43 memset(buf, 0,
sizeof(buf));
44 strncpy(buf, p, pn-p);
50 if (sscanf(buf,
"%d", &sval) == 0)
57 if (sscanf(buf,
"%u", &uval) == 0)
65 memset(buf2, 0,
sizeof(buf));
91 int insertLine(
Ndb* pNdb,
100 while (retryAttempt < retryMax){
103 if (pTrans == NULL) {
105 NdbSleep_MilliSleep(50);
124 check = setValuesFromLine(pOp,
139 check = pTrans->
execute( Commit );
147 ndbout <<
"ERROR: NdbError reports success when transcaction failed" << endl;
153 NdbSleep_MilliSleep(50);
186 int insertFile(
Ndb* pNdb,
188 const char* fileName){
190 const int MAX_LINE_LEN = 8000;
191 char line[MAX_LINE_LEN];
194 FILE* instr = fopen(fileName,
"r");
196 ndbout <<
"Coul'd not open " << fileName << endl;
200 while(fgets(line, MAX_LINE_LEN, instr)){
203 if (line[strlen(line)-1] ==
'\n') {
204 line[strlen(line)-1] =
'\0';
207 int check = insertLine(pNdb, pTab, line);
209 ndbout <<
"Wrong format in input data file, line: " << lineNo << endl;
225 int main(
int argc,
const char** argv){
228 const char* _tabname = NULL;
232 {
"usage",
'?', arg_flag, &_help,
"Print help",
"" }
234 int num_args =
sizeof(args) /
sizeof(args[0]);
238 "This program will bulk copy data from a file to a table in Ndb.\n";
240 if(getarg(args, num_args, argc, argv, &optind) ||
241 argv[optind] == NULL || _help) {
242 arg_printusage(args, num_args, argv[0], desc);
243 return NDBT_ProgramExit(NDBT_WRONGARGS);
245 _tabname = argv[optind];
246 ndbout <<
"Tablename: " << _tabname << endl;
249 Ndb MyNdb(
"TEST_DB" );
251 if(MyNdb.init() != 0){
252 ERR(MyNdb.getNdbError());
253 return NDBT_ProgramExit(NDBT_FAILED);
257 while(MyNdb.waitUntilReady() != 0)
258 ndbout <<
"Waiting for ndb to become ready..." << endl;
263 ndbout <<
" Table " << _tabname <<
" does not exist!" << endl;
264 return NDBT_ProgramExit(NDBT_WRONGARGS);
269 if (insertFile(&MyNdb, pTab, buf) != 0){
270 return NDBT_ProgramExit(NDBT_FAILED);
273 return NDBT_ProgramExit(NDBT_OK);