19 #include <ndb_global.h>
24 #include "UtilTransactions.hpp"
28 int main(
int argc,
const char** argv){
31 const char* _tabname = NULL;
32 const char* _dbname =
"TEST_DB";
33 const char* _connectstr = NULL;
34 int _copy_data =
true;
38 {
"database",
'd', arg_string, &_dbname,
"dbname",
39 "Name of database table is in"},
40 {
"connstr",
'c', arg_string, &_connectstr,
"connect string",
41 "How to connect to NDB"},
42 {
"copy-data",
'\0', arg_negative_flag, &_copy_data,
"Don't copy data to new table",
43 "How to connect to NDB"},
44 {
"usage",
'?', arg_flag, &_help,
"Print help",
"" }
46 int num_args =
sizeof(args) /
sizeof(args[0]);
50 "This program will copy one table in Ndb\n";
52 if(getarg(args, num_args, argc, argv, &optind) ||
53 argv[optind] == NULL || argv[optind + 1] == NULL || _help){
54 arg_printusage(args, num_args, argv[0], desc);
55 return NDBT_ProgramExit(NDBT_WRONGARGS);
57 _tabname = argv[optind];
62 return NDBT_ProgramExit(NDBT_FAILED);
64 Ndb MyNdb(&con,_dbname);
65 if(MyNdb.init() != 0){
66 ERR(MyNdb.getNdbError());
67 return NDBT_ProgramExit(NDBT_FAILED);
70 while(MyNdb.waitUntilReady() != 0)
71 ndbout <<
"Waiting for ndb to become ready..." << endl;
76 ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
77 return NDBT_ProgramExit(NDBT_FAILED);
83 if (MyNdb.getDictionary()->listIndexes(list, *ptab) != 0)
85 ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
86 return NDBT_ProgramExit(NDBT_FAILED);
88 for (
unsigned i = 0;
i<list.
count;
i++)
104 indexes.push_back(copy);
108 for (
int i = optind + 1;
i<argc;
i++)
110 const char *_to_tabname = argv[
i];
111 ndbout <<
"Copying table " << _tabname <<
" to " << _to_tabname <<
"...";
113 tab2.setName(_to_tabname);
114 if (MyNdb.getDictionary()->beginSchemaTrans() != 0)
116 ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
117 return NDBT_ProgramExit(NDBT_FAILED);
119 if (MyNdb.getDictionary()->createTable(
tab2) != 0){
120 ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
121 return NDBT_ProgramExit(NDBT_FAILED);
124 for (
unsigned j = 0; j<indexes.size(); j++)
128 int res = MyNdb.getDictionary()->createIndex(*idx);
131 ndbout <<
"Failed to create index: " << idx->
getName() <<
" : "
132 << MyNdb.getDictionary()->getNdbError() << endl;
133 return NDBT_ProgramExit(NDBT_FAILED);
137 if (MyNdb.getDictionary()->endSchemaTrans() != 0)
139 ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
140 return NDBT_ProgramExit(NDBT_FAILED);
143 ndbout <<
"OK" << endl;
145 ndbout <<
"Copying data..."<<endl;
147 NDBT_Table::discoverTableFromDb(&MyNdb,
151 if(util.copyTableData(&MyNdb,
152 _to_tabname) != NDBT_OK){
153 return NDBT_ProgramExit(NDBT_FAILED);
155 ndbout <<
"OK" << endl;
159 for (
unsigned j = 0; j<indexes.size(); j++)
164 return NDBT_ProgramExit(NDBT_OK);