MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drop_tab.cpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include <ndb_global.h>
19 #include <ndb_opts.h>
20 
21 #include <NdbOut.hpp>
22 #include <NdbApi.hpp>
23 #include <NDBT.hpp>
24 
25 static const char* _dbname = "TEST_DB";
26 
27 const char *load_default_groups[]= { "mysql_cluster",0 };
28 
29 static struct my_option my_long_options[] =
30 {
31  NDB_STD_OPTS("ndb_desc"),
32  { "database", 'd', "Name of database table is in",
33  (uchar**) &_dbname, (uchar**) &_dbname, 0,
34  GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
35  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
36 };
37 
38 static void short_usage_sub(void)
39 {
40  ndb_short_usage_sub(NULL);
41 }
42 
43 static void usage()
44 {
45  ndb_usage(short_usage_sub, load_default_groups, my_long_options);
46 }
47 
48 int main(int argc, char** argv){
49  NDB_INIT(argv[0]);
50  ndb_opt_set_usage_funcs(short_usage_sub, usage);
51  load_defaults("my",load_default_groups,&argc,&argv);
52  int ho_error;
53  if ((ho_error=handle_options(&argc, &argv, my_long_options,
54  ndb_std_get_one_option)))
55  return NDBT_ProgramExit(NDBT_WRONGARGS);
56  if (argc < 1) {
57  usage();
58  return NDBT_ProgramExit(NDBT_WRONGARGS);
59  }
60 
61  Ndb_cluster_connection con(opt_ndb_connectstring, opt_ndb_nodeid);
62  con.set_name("ndb_drop_table");
63  if(con.connect(12, 5, 1) != 0)
64  {
65  ndbout << "Unable to connect to management server." << endl;
66  return NDBT_ProgramExit(NDBT_FAILED);
67  }
68  if (con.wait_until_ready(30,3) < 0)
69  {
70  ndbout << "Cluster nodes not ready in 30 seconds." << endl;
71  return NDBT_ProgramExit(NDBT_FAILED);
72  }
73 
74  Ndb MyNdb(&con, _dbname );
75  if(MyNdb.init() != 0){
76  ERR(MyNdb.getNdbError());
77  return NDBT_ProgramExit(NDBT_FAILED);
78  }
79 
80  int res = 0;
81  for(int i = 0; i<argc; i++){
82  ndbout << "Dropping table " << argv[i] << "...";
83  int tmp;
84  if((tmp = MyNdb.getDictionary()->dropTable(argv[i])) != 0){
85  ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
86  res = tmp;
87  } else {
88  ndbout << "OK" << endl;
89  }
90  }
91 
92  if(res != 0){
93  return NDBT_ProgramExit(NDBT_FAILED);
94  }
95 
96  return NDBT_ProgramExit(NDBT_OK);
97 }