1
1
/*
2
- Copyright (c) 2005, 2016 , Oracle and/or its affiliates. All rights reserved.
2
+ Copyright (c) 2005, 2017 , Oracle and/or its affiliates. All rights reserved.
3
3
4
4
This program is free software; you can redistribute it and/or modify
5
5
it under the terms of the GNU General Public License as published by
@@ -75,6 +75,7 @@ static int g_verbose = 0;
75
75
76
76
static int g_nodes, g_connections, g_system, g_section;
77
77
static const char * g_query = 0 ;
78
+ static int g_query_all = 0 ;
78
79
79
80
static int g_nodeid = 0 ;
80
81
static const char * g_type = 0 ;
@@ -136,6 +137,9 @@ static struct my_option my_long_options[] =
136
137
{ " config_from_node" , NDB_OPT_NOSHORT, " Use current config from node with given nodeid" ,
137
138
(uchar**) &g_config_from_node, (uchar**) &g_config_from_node,
138
139
0 , GET_INT, REQUIRED_ARG, INT_MIN, INT_MIN, 0 , 0 , 0 , 0 },
140
+ { " query_all" , ' a' , " Query all the options" ,
141
+ (uchar**)&g_query_all, (uchar**)&g_query_all,
142
+ 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
139
143
{ 0 , 0 , 0 , 0 , 0 , 0 , GET_NO_ARG, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 }
140
144
};
141
145
@@ -173,21 +177,29 @@ struct HostMatch : public Match
173
177
struct Apply
174
178
{
175
179
Apply () {}
176
- Apply (int val) { m_key = val;}
180
+ Apply (const char *s):m_name(s) {}
181
+ BaseString m_name;
182
+ virtual int apply (const Iter&) = 0;
183
+ virtual ~Apply () {}
184
+ };
185
+
186
+
187
+ struct ParamApply : public Apply
188
+ {
189
+ ParamApply (int val,const char *s) :Apply(s), m_key(val) {}
177
190
int m_key;
178
191
virtual int apply (const Iter&);
179
- virtual ~Apply () {}
180
192
};
181
193
182
194
struct NodeTypeApply : public Apply
183
195
{
184
- NodeTypeApply () {}
196
+ NodeTypeApply (const char *s) :Apply(s ) {}
185
197
virtual int apply (const Iter&);
186
198
};
187
199
188
200
struct ConnectionTypeApply : public Apply
189
201
{
190
- ConnectionTypeApply () {}
202
+ ConnectionTypeApply (const char *s) :Apply(s ) {}
191
203
virtual int apply (const Iter&);
192
204
};
193
205
@@ -205,6 +217,7 @@ main(int argc, char** argv){
205
217
ndb_opt_set_usage_funcs (short_usage_sub, usage);
206
218
ndb_load_defaults (NULL ,load_default_groups,&argc,&argv);
207
219
int ho_error;
220
+ bool print_headers = false ;
208
221
if ((ho_error=handle_options (&argc, &argv, my_long_options,
209
222
ndb_std_get_one_option)))
210
223
exit (255 );
@@ -274,6 +287,17 @@ main(int argc, char** argv){
274
287
if (strcmp (g_field_delimiter, " \\ n" ) == 0 )
275
288
g_field_delimiter = " \n " ;
276
289
290
+ if (g_query_all)
291
+ {
292
+ if (g_query)
293
+ {
294
+ fprintf (stderr,
295
+ " Error: Only one of the options: --query_all, --query is allowed.\n " );
296
+ exit (0 );
297
+ }
298
+ print_headers = true ;
299
+ }
300
+
277
301
if (parse_query (select_list, argc, argv))
278
302
{
279
303
exit (0 );
@@ -284,6 +308,17 @@ main(int argc, char** argv){
284
308
exit (0 );
285
309
}
286
310
311
+ if (print_headers)
312
+ {
313
+ printf (" %s" , select_list[0 ]->m_name .c_str ());
314
+ for (unsigned i = 1 ; i < select_list.size (); i++)
315
+ {
316
+ printf (" %s" , g_field_delimiter);
317
+ printf (" %s" , select_list[i]->m_name .c_str ());
318
+ }
319
+ printf (" %s" , g_row_delimiter);
320
+ }
321
+
287
322
Iter iter (* conf, g_section);
288
323
bool prev= false ;
289
324
iter.first ();
@@ -301,6 +336,91 @@ main(int argc, char** argv){
301
336
return 0 ;
302
337
}
303
338
339
+ static
340
+ int
341
+ helper (Vector<Apply*>& select, const char * str)
342
+ {
343
+ bool all = false ;
344
+ bool retflag = false ;
345
+
346
+ if (g_query_all)
347
+ {
348
+ all = true ;
349
+ }
350
+
351
+ if (g_section == CFG_SECTION_NODE)
352
+ {
353
+ if (all)
354
+ {
355
+ select.push_back (new ParamApply (CFG_NODE_ID, " nodeid" ));
356
+ select.push_back (new ParamApply (CFG_NODE_HOST, " host" ));
357
+ select.push_back (new NodeTypeApply (" type" ));
358
+ }
359
+ else if (native_strcasecmp (str, " nodeid" ) == 0 )
360
+ {
361
+ select.push_back (new ParamApply (CFG_NODE_ID, " nodeid" ));
362
+ retflag = true ;
363
+ }
364
+ else if (native_strncasecmp (str, " host" , 4 ) == 0 )
365
+ {
366
+ select.push_back (new ParamApply (CFG_NODE_HOST, " host" ));
367
+ retflag = true ;
368
+ }
369
+ else if (native_strcasecmp (str, " type" ) == 0 )
370
+ {
371
+ select.push_back (new NodeTypeApply (" type" ));
372
+ retflag = true ;
373
+ }
374
+ }
375
+ else if (g_section == CFG_SECTION_CONNECTION)
376
+ {
377
+ if (all || native_strcasecmp (str, " type" ) == 0 )
378
+ {
379
+ select.push_back (new ConnectionTypeApply (" type" ));
380
+ retflag = true ;
381
+ }
382
+ }
383
+ if (all || !retflag)
384
+ {
385
+ bool found = false ;
386
+ for (int p = 0 ; p < ConfigInfo::m_NoOfParams; p++)
387
+ {
388
+ if (0 )ndbout_c (" %s %s" ,
389
+ ConfigInfo::m_ParamInfo[p]._section ,
390
+ ConfigInfo::m_ParamInfo[p]._fname );
391
+ if ((g_section == CFG_SECTION_CONNECTION &&
392
+ (strcmp (ConfigInfo::m_ParamInfo[p]._section , " TCP" ) == 0 ||
393
+ strcmp (ConfigInfo::m_ParamInfo[p]._section , " SCI" ) == 0 ||
394
+ strcmp (ConfigInfo::m_ParamInfo[p]._section , " SHM" ) == 0 ))
395
+ ||
396
+ (g_section == CFG_SECTION_NODE &&
397
+ (strcmp (ConfigInfo::m_ParamInfo[p]._section , " DB" ) == 0 ||
398
+ strcmp (ConfigInfo::m_ParamInfo[p]._section , " API" ) == 0 ||
399
+ strcmp (ConfigInfo::m_ParamInfo[p]._section , " MGM" ) == 0 ))
400
+ ||
401
+ (g_section == CFG_SECTION_SYSTEM))
402
+ {
403
+ if (all || native_strcasecmp (ConfigInfo::m_ParamInfo[p]._fname , str) == 0 )
404
+ {
405
+ select.push_back (new ParamApply (ConfigInfo::m_ParamInfo[p]._paramId ,
406
+ ConfigInfo::m_ParamInfo[p]._fname ));
407
+ if (!all)
408
+ {
409
+ found = true ;
410
+ break ;
411
+ }
412
+ }
413
+ }
414
+ }
415
+ if (!all && !found)
416
+ {
417
+ fprintf (stderr, " Unknown query option: %s\n " , str);
418
+ return 1 ;
419
+ }
420
+ }
421
+ return 0 ;
422
+ }
423
+
304
424
static
305
425
int
306
426
parse_query (Vector<Apply*>& select, int &argc, char **& argv)
@@ -313,67 +433,16 @@ parse_query(Vector<Apply*>& select, int &argc, char**& argv)
313
433
for (unsigned i = 0 ; i<list.size (); i++)
314
434
{
315
435
const char * str= list[i].c_str ();
316
- if (g_section == CFG_SECTION_NODE )
436
+ if ( helper (select, str) )
317
437
{
318
- if (native_strcasecmp (str, " nodeid" ) == 0 )
319
- {
320
- select.push_back (new Apply (CFG_NODE_ID));
321
- continue ;
322
- }
323
- else if (native_strncasecmp (str, " host" , 4 ) == 0 )
324
- {
325
- select.push_back (new Apply (CFG_NODE_HOST));
326
- continue ;
327
- }
328
- else if (native_strcasecmp (str, " type" ) == 0 )
329
- {
330
- select.push_back (new NodeTypeApply ());
331
- continue ;
332
- }
333
- }
334
- else if (g_section == CFG_SECTION_CONNECTION)
335
- {
336
- if (native_strcasecmp (str, " type" ) == 0 )
337
- {
338
- select.push_back (new ConnectionTypeApply ());
339
- continue ;
340
- }
341
- }
342
- {
343
- bool found = false ;
344
- for (int p = 0 ; p<ConfigInfo::m_NoOfParams; p++)
345
- {
346
- if (0 )ndbout_c (" %s %s" ,
347
- ConfigInfo::m_ParamInfo[p]._section ,
348
- ConfigInfo::m_ParamInfo[p]._fname );
349
- if ((g_section == CFG_SECTION_CONNECTION &&
350
- (strcmp (ConfigInfo::m_ParamInfo[p]._section , " TCP" ) == 0 ||
351
- strcmp (ConfigInfo::m_ParamInfo[p]._section , " SCI" ) == 0 ||
352
- strcmp (ConfigInfo::m_ParamInfo[p]._section , " SHM" ) == 0 ))
353
- ||
354
- (g_section == CFG_SECTION_NODE &&
355
- (strcmp (ConfigInfo::m_ParamInfo[p]._section , " DB" ) == 0 ||
356
- strcmp (ConfigInfo::m_ParamInfo[p]._section , " API" ) == 0 ||
357
- strcmp (ConfigInfo::m_ParamInfo[p]._section , " MGM" ) == 0 ))
358
- ||
359
- (g_section == CFG_SECTION_SYSTEM))
360
- {
361
- if (native_strcasecmp (ConfigInfo::m_ParamInfo[p]._fname , str) == 0 )
362
- {
363
- select.push_back (new Apply (ConfigInfo::m_ParamInfo[p]._paramId ));
364
- found = true ;
365
- break ;
366
- }
367
- }
368
- }
369
- if (!found)
370
- {
371
- fprintf (stderr, " Unknown query option: %s\n " , str);
372
- return 1 ;
373
- }
438
+ return 1 ;
374
439
}
375
440
}
376
441
}
442
+ if (g_query_all)
443
+ {
444
+ return helper (select, NULL );
445
+ }
377
446
return 0 ;
378
447
}
379
448
@@ -517,7 +586,7 @@ HostMatch::eval(const Iter& iter)
517
586
}
518
587
519
588
int
520
- Apply ::apply (const Iter& iter)
589
+ ParamApply ::apply (const Iter& iter)
521
590
{
522
591
Uint32 val32;
523
592
Uint64 val64;
0 commit comments