19 #include <ndb_global.h>
30 main(
int argc,
const char** argv){
33 const char* _dbname =
"TEST_DB";
35 int _ordered = 0, _pk = 1;
40 {
"database",
'd', arg_string, &_dbname,
"dbname",
41 "Name of database table is in"},
42 {
"ordered",
'o', arg_flag, &_ordered,
"Create ordered index",
"" },
43 {
"pk",
'p', arg_flag, &_pk,
"Create index on primary key",
"" },
44 {
"idxname",
'i', arg_string, &_iname,
"idxname",
"Override default name for index" },
45 {
"tabname",
't', arg_string, &_tname,
"tabname",
"Specify single tabname and list of col names as args" },
46 {
"usage",
'?', arg_flag, &_help,
"Print help",
"" }
49 int num_args =
sizeof(args) /
sizeof(args[0]);
53 "This program will create one unique hash index named ind_<tabname> "
54 " for each table. The index will contain all columns in the table";
56 if(getarg(args, num_args, argc, argv, &optind) || _help ||
57 argv[optind] == NULL){
58 arg_printusage(args, num_args, argv[0], desc);
59 return NDBT_ProgramExit(NDBT_WRONGARGS);
65 return NDBT_ProgramExit(NDBT_FAILED);
68 Ndb MyNdb(&con, _dbname);
69 if(MyNdb.init() != 0){
70 ERR(MyNdb.getNdbError());
71 return NDBT_ProgramExit(NDBT_FAILED);
74 while(MyNdb.waitUntilReady() != 0)
75 ndbout <<
"Waiting for ndb to become ready..." << endl;
79 for(
int i = optind;
i<argc;
i++){
80 const char* tabName= (_tname)? _tname : argv[
i];
83 g_err <<
"Unknown table: " << tabName << endl;
85 return NDBT_ProgramExit(NDBT_FAILED);
99 sprintf(buf,
"IND_%s_%s_%c",
100 argv[
i], (_pk ?
"PK" :
"FULL"), (_ordered ?
'O' :
'U'));
112 ndbout <<
"creating index " << ind.
getName() <<
" on table " << tabName
121 ndbout <<
")" << endl;
126 ndbout <<
"creating index " << ind.
getName() <<
" on table " << tabName
128 for(
int argNum=i; argNum < argc; argNum++)
130 const char* colName= argv[argNum];
133 g_err <<
"Column " << colName <<
" does not exist in table " << tabName
135 return NDBT_ProgramExit(NDBT_FAILED);
137 ndbout << colName <<
", ";
140 ndbout <<
")" << endl;
146 ndbout <<
"OK" << endl;
149 return NDBT_ProgramExit(NDBT_OK);
152 return NDBT_ProgramExit(NDBT_OK);