25 #include <ndb_global.h>
34 static int _unqualified = 0;
35 static int _parsable = 0;
36 static int show_temp_status = 0;
38 const char *load_default_groups[]= {
"mysql_cluster",0 };
41 fatal(
char const*
fmt, ...)
46 BaseString::vsnprintf(buf,
sizeof(buf), fmt, ap);
52 NDBT_ProgramExit(NDBT_FAILED);
57 fatal_dict(
char const* fmt, ...)
62 BaseString::vsnprintf(buf,
sizeof(buf), fmt, ap);
68 NDBT_ProgramExit(NDBT_FAILED);
73 list(
const char * tabname,
79 fatal_dict(
"listObjects");
82 fatal_dict(
"listIndexes");
86 if (ndb->usingFullyQualifiedNames())
89 ndbout_c(
"%-5s %-20s %-8s %-7s %-4s %-12s %-8s %s",
"id",
"type",
"state",
"logging",
"temp",
"database",
"schema",
"name");
91 ndbout_c(
"%-5s %-20s %-8s %-7s %-12s %-8s %s",
"id",
"type",
"state",
"logging",
"database",
"schema",
"name");
96 ndbout_c(
"%-5s %-20s %-8s %-7s %-4s %s",
"id",
"type",
"state",
"logging",
"temp",
"name");
98 ndbout_c(
"%-5s %-20s %-8s %-7s %s",
"id",
"type",
"state",
"logging",
"name");
101 for (
unsigned i = 0;
i < list.
count;
i++) {
104 bool isTable =
false;
107 strcpy(type,
"SystemTable");
111 strcpy(type,
"UserTable");
115 strcpy(type,
"UniqueHashIndex");
119 strcpy(type,
"OrderedIndex");
123 strcpy(type,
"HashIndexTrigger");
126 strcpy(type,
"IndexTrigger");
129 strcpy(type,
"SubscriptionTrigger");
132 strcpy(type,
"ReadOnlyConstraint");
134 case NdbDictionary::Object::ReorgTrigger:
135 strcpy(type,
"ReorgTrigger");
138 strcpy(type,
"Tablespace");
141 strcpy(type,
"LogfileGroup");
144 strcpy(type,
"Datafile");
147 strcpy(type,
"Undofile");
150 strcpy(type,
"TableEvent");
153 sprintf(type,
"%d", (
int)elt.
type);
159 strcpy(state,
"Offline");
162 strcpy(state,
"Building");
165 strcpy(state,
"Dropping");
168 strcpy(state,
"Online");
171 strcpy(state,
"Backup");
174 strcpy(state,
"Broken");
177 sprintf(state,
"%d", (
int)elt.
state);
189 strcpy(store,
"Yes");
192 sprintf(store,
"%d", (
int)elt.
store);
197 if (show_temp_status)
203 case NDB_TEMP_TAB_PERMANENT:
206 case NDB_TEMP_TAB_TEMPORARY:
210 sprintf(temp,
"%d", (
int)elt.
temp);
215 if (ndb->usingFullyQualifiedNames())
219 if (show_temp_status)
226 if (show_temp_status)
236 if (show_temp_status)
237 ndbout_c(
"%d\t'%s'\t'%s'\t'%s'\t'%s'\t'%s'", elt.
id, type, state, store, temp, elt.
name);
239 ndbout_c(
"%d\t'%s'\t'%s'\t'%s'\t'%s'", elt.
id, type, state, store, elt.
name);
243 if (show_temp_status)
244 ndbout_c(
"%-5d %-20s %-8s %-7s %-4s %s", elt.
id, type, state, store, temp, elt.
name);
246 ndbout_c(
"%-5d %-20s %-8s %-7s %s", elt.
id, type, state, store, elt.
name);
254 static const char* _dbname =
"TEST_DB";
258 static struct my_option my_long_options[] =
260 NDB_STD_OPTS(
"ndb_show_tables"),
261 {
"database",
'd',
"Name of database table is in",
262 (uchar**) &_dbname, (uchar**) &_dbname, 0,
263 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
264 {
"loops",
'l',
"loops",
265 (uchar**) &_loops, (uchar**) &_loops, 0,
266 GET_INT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0 },
267 {
"type",
't',
"type",
268 (uchar**) &_type, (uchar**) &_type, 0,
269 GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
270 {
"unqualified",
'u',
"Use unqualified table names",
271 (uchar**) &_unqualified, (uchar**) &_unqualified, 0,
272 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
273 {
"parsable",
'p',
"Return output suitable for mysql LOAD DATA INFILE",
274 (uchar**) &_parsable, (uchar**) &_parsable, 0,
275 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
276 {
"show-temp-status", NDB_OPT_NOSHORT,
"Show table temporary flag",
277 (uchar**) &show_temp_status, (uchar**) &show_temp_status, 0,
278 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
279 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
282 static void short_usage_sub(
void)
284 ndb_short_usage_sub(NULL);
289 ndb_usage(short_usage_sub, load_default_groups, my_long_options);
292 int main(
int argc,
char** argv){
294 const char* _tabname;
295 ndb_opt_set_usage_funcs(short_usage_sub, usage);
296 load_defaults(
"my",load_default_groups,&argc,&argv);
299 opt_debug=
"d:t:O,/tmp/ndb_show_tables.trace";
301 if ((ho_error=handle_options(&argc, &argv, my_long_options,
302 ndb_std_get_one_option)))
303 return NDBT_ProgramExit(NDBT_WRONGARGS);
308 if (ndb_cluster_connection == NULL)
309 fatal(
"Unable to create cluster connection");
311 ndb_cluster_connection->
set_name(
"ndb_show_tables");
312 if (ndb_cluster_connection->
connect(12,5,1))
313 fatal(
"Unable to connect to management server.");
315 fatal(
"Cluster nodes not ready in 30 seconds.");
317 ndb =
new Ndb(ndb_cluster_connection, _dbname);
318 if (ndb->
init() != 0)
321 for (
int i = 0; _loops == 0 ||
i < _loops;
i++) {
325 delete ndb_cluster_connection;
326 return NDBT_ProgramExit(NDBT_OK);