39 enum ApiType {api_attr, api_record};
43 #define PRINT_ERROR(code,msg) \
44 std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \
45 << ", code: " << code \
46 << ", msg: " << msg << "." << std::endl
47 #define MYSQLERROR(mysql) { \
48 PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \
50 #define APIERROR(error) { \
51 PRINT_ERROR(error.code,error.message); \
54 int main(
int argc,
char** argv)
58 std::cout <<
"Arguments are <socket mysqld> <connect_string cluster> <attr|record>.\n";
66 char * mysqld_sock = argv[1];
67 const char *connectstring = argv[2];
68 ApiType accessType=api_attr;
74 if (cluster_connection.connect(4 ,
78 std::cout <<
"Cluster management server was not ready within 30 secs.\n";
83 if (cluster_connection.wait_until_ready(30,0) < 0)
85 std::cout <<
"Cluster was not ready within 30 secs.\n";
91 if ( !mysql_init(&mysql) ) {
92 std::cout <<
"mysql_init failed\n";
95 if ( !mysql_real_connect(&mysql,
"localhost",
"root",
"",
"",
99 if (0==strncmp(
"attr", argv[3], 4))
103 else if (0==strncmp(
"record", argv[3], 6))
105 accessType=api_record;
109 std::cout <<
"Bad access type argument : "<< argv[3] <<
"\n";
114 run_application(mysql, cluster_connection, accessType);
122 static void init_ndbrecord_info(
Ndb &);
124 static void do_insert(
Ndb &, ApiType);
125 static void do_update(
Ndb &, ApiType);
126 static void do_delete(
Ndb &, ApiType);
127 static void do_read(
Ndb &, ApiType);
128 static void do_mixed_read(
Ndb &);
129 static void do_mixed_update(
Ndb &);
130 static void do_scan(
Ndb &, ApiType);
131 static void do_mixed_scan(
Ndb &);
132 static void do_indexScan(
Ndb &, ApiType);
133 static void do_mixed_indexScan(
Ndb&);
134 static void do_read_and_delete(
Ndb &);
135 static void do_scan_update(
Ndb&, ApiType);
136 static void do_scan_delete(
Ndb&, ApiType);
137 static void do_scan_lock_reread(
Ndb&, ApiType);
138 static void do_all_extras_read(
Ndb &myNdb);
139 static void do_secondary_indexScan(
Ndb &myNdb, ApiType accessType);
140 static void do_secondary_indexScanEqual(
Ndb &myNdb, ApiType accessType);
141 static void do_interpreted_update(
Ndb &myNdb, ApiType accessType);
142 static void do_interpreted_scan(
Ndb &myNdb, ApiType accessType);
143 static void do_read_using_default(
Ndb &myNdb);
166 static void run_application(
MYSQL &mysql,
173 mysql_query(&mysql,
"CREATE DATABASE ndb_examples");
174 if (mysql_query(&mysql,
"USE ndb_examples") != 0) MYSQLERROR(mysql);
181 Ndb myNdb( &cluster_connection,
"ndb_examples" );
182 if (myNdb.init()) APIERROR(myNdb.getNdbError());
184 init_ndbrecord_info(myNdb);
188 do_insert(myNdb, accessType);
189 do_update(myNdb, accessType);
190 do_delete(myNdb, accessType);
191 do_read(myNdb, accessType);
192 do_mixed_read(myNdb);
193 do_mixed_update(myNdb);
194 do_read(myNdb, accessType);
195 do_scan(myNdb, accessType);
196 do_mixed_scan(myNdb);
197 do_indexScan(myNdb, accessType);
198 do_mixed_indexScan(myNdb);
199 do_read_and_delete(myNdb);
200 do_scan_update(myNdb, accessType);
201 do_scan_delete(myNdb, accessType);
202 do_scan_lock_reread(myNdb, accessType);
203 do_all_extras_read(myNdb);
204 do_secondary_indexScan(myNdb, accessType);
205 do_secondary_indexScanEqual(myNdb, accessType);
206 do_scan(myNdb, accessType);
207 do_interpreted_update(myNdb, accessType);
208 do_interpreted_scan(myNdb, accessType);
209 do_read_using_default(myNdb);
210 do_scan(myNdb, accessType);
218 if (mysql_query(&mysql,
219 "DROP TABLE IF EXISTS"
220 " api_recattr_vs_record"))
223 if (mysql_query(&mysql,
225 " api_recattr_vs_record"
226 " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY,"
227 " ATTR2 INT UNSIGNED NOT NULL,"
228 " ATTR3 INT UNSIGNED NOT NULL)"
233 if (mysql_query(&mysql,
236 " ON api_recattr_vs_record"
247 static const NdbRecord *pkeyColumnRecord;
250 static const NdbRecord *psecondaryIndexRecord;
252 static int attr1ColNum;
253 static int attr2ColNum;
254 static int attr3ColNum;
259 static void init_ndbrecord_info(
Ndb &myNdb)
276 if (pattr1Col == NULL) APIERROR(myDict->
getNdbError());
278 if (pattr2Col == NULL) APIERROR(myDict->
getNdbError());
280 if (pattr3Col == NULL) APIERROR(myDict->
getNdbError());
282 attr1ColNum = pattr1Col->getColumnNo();
283 attr2ColNum = pattr2Col->getColumnNo();
284 attr3ColNum = pattr3Col->getColumnNo();
287 recordSpec[0].column = pattr1Col;
288 recordSpec[0].offset = offsetof(
RowData, attr1);
289 recordSpec[0].nullbit_byte_offset = 0;
290 recordSpec[0].nullbit_bit_in_byte = 0;
293 recordSpec[1].column = pattr2Col;
294 recordSpec[1].offset = offsetof(
RowData, attr2);
295 recordSpec[1].nullbit_byte_offset = 0;
296 recordSpec[1].nullbit_bit_in_byte = 0;
299 recordSpec[2].column = pattr3Col;
300 recordSpec[2].offset = offsetof(
RowData, attr3);
301 recordSpec[2].nullbit_byte_offset = 0;
302 recordSpec[2].nullbit_bit_in_byte = 0;
306 myDict->createRecord(myTable, recordSpec, 1,
sizeof(recordSpec[0]));
308 if (pkeyColumnRecord == NULL) APIERROR(myDict->
getNdbError());
312 myDict->createRecord(myTable, recordSpec, 3,
sizeof(recordSpec[0]));
314 if (pallColsRecord == NULL) APIERROR(myDict->
getNdbError());
319 if (myPIndex == NULL)
323 myDict->createRecord(myPIndex, recordSpec, 1,
sizeof(recordSpec[0]));
325 if (pkeyIndexRecord == NULL) APIERROR(myDict->
getNdbError());
333 recordSpec[0].column= pattr3Col;
334 recordSpec[0].offset= offsetof(
IndexRow, attr3);
335 recordSpec[0].nullbit_byte_offset=0;
336 recordSpec[0].nullbit_bit_in_byte=0;
338 recordSpec[1].column= pattr2Col;
339 recordSpec[1].offset= offsetof(
IndexRow, attr2);
340 recordSpec[1].nullbit_byte_offset=0;
341 recordSpec[1].nullbit_bit_in_byte=1;
344 psecondaryIndexRecord =
345 myDict->createRecord(mySIndex,
348 sizeof(recordSpec[0]));
351 if (psecondaryIndexRecord == NULL)
360 static void do_insert(
Ndb &myNdb, ApiType accessType)
365 std::cout <<
"Running do_insert\n";
370 for (
int i = 0;
i < 5;
i++) {
372 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
379 if (myOperation == NULL) APIERROR(myTransaction->
getNdbError());
382 myOperation->
equal(
"ATTR1",
i);
388 if (myOperation == NULL) APIERROR(myTransaction->
getNdbError());
390 myOperation->
equal(
"ATTR1",
i+5);
399 row.attr1= row.attr2= row.attr3=
i;
402 myTransaction->insertTuple(pallColsRecord, (
char *) &row);
403 if (pop1 == NULL) APIERROR(myTransaction->
getNdbError());
405 row.attr1= row.attr2= row.attr3=
i+5;
408 myTransaction->insertTuple(pallColsRecord, (
char *) &row);
409 if (pop2 == NULL) APIERROR(myTransaction->
getNdbError());
415 std::cout <<
"Bad branch : " << accessType <<
"\n";
426 std::cout <<
"-------\n";
432 static void do_update(
Ndb &myNdb, ApiType accessType)
437 std::cout <<
"Running do_update\n";
439 for (
int i = 0;
i < 10;
i+=2) {
441 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
448 if (myOperation == NULL) APIERROR(myTransaction->
getNdbError());
451 myOperation->
equal(
"ATTR1",
i );
467 unsigned char attrMask=(1<<attr2ColNum) | (1<<attr3ColNum);
470 myTransaction->updateTuple(pkeyColumnRecord, (
char*) &row,
471 pallColsRecord, (
char*) &row,
474 if (pop==NULL) APIERROR(myTransaction->
getNdbError());
479 std::cout <<
"Bad branch : " << accessType <<
"\n";
490 std::cout <<
"-------\n";
496 static void do_delete(
Ndb &myNdb, ApiType accessType)
501 std::cout <<
"Running do_delete\n";
507 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
513 NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
514 if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
517 myOperation->
equal(
"ATTR1", 3 );
530 if (pop==NULL) APIERROR(myTransaction->getNdbError());
535 std::cout <<
"Bad branch : " << accessType <<
"\n";
542 APIERROR(myTransaction->getNdbError());
546 std::cout <<
"-------\n";
553 static void do_mixed_update(
Ndb &myNdb)
559 std::cout <<
"Running do_mixed_update (NdbRecord only)\n";
561 for (
int i = 0;
i < 10;
i+=2) {
563 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
570 unsigned char attrMask= (1<<attr2ColNum);
575 Uint32 dataSource=
i + 40;
577 setvalspecs[0].column = pattr3Col;
578 setvalspecs[0].value = &dataSource;
581 opts.optionsPresent= NdbOperation::OperationOptions::OO_SETVALUE;
582 opts.extraSetValues= &setvalspecs[0];
583 opts.numExtraSetValues= 1;
588 myTransaction->updateTuple(pkeyColumnRecord, (
char*) &row,
589 pallColsRecord, (
char*) &row,
593 if (pop==NULL) APIERROR(myTransaction->
getNdbError());
601 std::cout <<
"-------\n";
608 static void do_read(
Ndb &myNdb, ApiType accessType)
613 std::cout <<
"Running do_read\n";
618 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
620 for (
int i = 0;
i < 10;
i++) {
622 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
633 if (myOperation == NULL) APIERROR(myTransaction->
getNdbError());
636 myOperation->
equal(
"ATTR1",
i);
638 myRecAttr= myOperation->
getValue(
"ATTR2", NULL);
639 if (myRecAttr == NULL) APIERROR(myTransaction->
getNdbError());
641 myRecAttr2=myOperation->
getValue(
"ATTR3", NULL);
642 if (myRecAttr2 == NULL) APIERROR(myTransaction->
getNdbError());
650 myTransaction->readTuple(pkeyColumnRecord,
654 if (pop==NULL) APIERROR(myTransaction->
getNdbError());
660 std::cout <<
"Bad branch : " << accessType <<
"\n";
670 std::cout <<
"Detected that deleted tuple doesn't exist!" << std::endl;
679 printf(
" %2d %2d %2d\n",
682 myRecAttr2->u_32_value());
689 printf(
" %2d %2d %2d\n",
698 std::cout <<
"Bad branch : " << accessType <<
"\n";
706 std::cout <<
"-------\n";
712 static void do_mixed_read(
Ndb &myNdb)
714 std::cout <<
"Running do_mixed_read (NdbRecord only)\n";
716 std::cout <<
"ATTR1 ATTR2 ATTR3 COMMIT_COUNT" << std::endl;
718 for (
int i = 0;
i < 10;
i++) {
720 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
730 extraCols[0].column=pattr3Col;
731 extraCols[0].appStorage=NULL;
732 extraCols[0].recAttr=NULL;
734 extraCols[1].column=NdbDictionary::Column::COMMIT_COUNT;
735 extraCols[1].appStorage=NULL;
736 extraCols[1].recAttr=NULL;
739 opts.optionsPresent = NdbOperation::OperationOptions::OO_GETVALUE;
741 opts.extraGetValues= &extraCols[0];
742 opts.numExtraGetValues= 2;
745 unsigned char attrMask= (1<<attr2ColNum);
751 myTransaction->readTuple(pkeyColumnRecord,
758 if (pop==NULL) APIERROR(myTransaction->
getNdbError());
760 myRecAttr3= extraCols[0].recAttr;
761 myRecAttrCC= extraCols[1].recAttr;
763 if (myRecAttr3 == NULL) APIERROR(myTransaction->
getNdbError());
764 if (myRecAttrCC == NULL) APIERROR(myTransaction->
getNdbError());
772 std::cout <<
"Detected that deleted tuple doesn't exist!" << std::endl;
778 printf(
" %2d %2d %2d %d\n",
781 myRecAttr3->u_32_value(),
789 std::cout <<
"-------\n";
795 static void do_scan(
Ndb &myNdb, ApiType accessType)
800 std::cout <<
"Running do_scan\n";
805 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
808 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
821 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
825 recAttrAttr1=psop->getValue(
"ATTR1");
826 recAttrAttr2=psop->getValue(
"ATTR2");
827 recAttrAttr3=psop->getValue(
"ATTR3");
837 psop=myTransaction->
scanTable(pallColsRecord,
840 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
846 std::cout <<
"Bad branch : " << accessType <<
"\n";
858 while (psop->nextResult(
true) == 0)
860 printf(
" %2d %2d %2d\n",
879 while ((rc = psop->nextResult((
const char**) &prowData,
883 printf(
" %2d %2d %2d\n",
889 if (rc != 1) APIERROR(myTransaction->
getNdbError());
897 std::cout <<
"Bad branch : " << accessType <<
"\n";
907 std::cout <<
"-------\n";
913 static void do_mixed_scan(
Ndb &myNdb)
915 std::cout <<
"Running do_mixed_scan(NdbRecord only)\n";
917 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
920 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
926 unsigned char attrMask=((1<<attr1ColNum) | (1<<attr2ColNum));
930 extraGets[0].column = pattr3Col;
931 extraGets[0].appStorage= 0;
932 extraGets[0].recAttr= 0;
935 options.optionsPresent= NdbScanOperation::ScanOptions::SO_GETVALUE;
936 options.extraGetValues= &extraGets[0];
937 options.numExtraGetValues= 1;
939 psop=myTransaction->
scanTable(pallColsRecord,
944 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
947 recAttrAttr3 = extraGets[0].recAttr;
949 if (recAttrAttr3 == NULL) APIERROR(myTransaction->
getNdbError());
958 while ((rc = psop->nextResult((
const char**) &prowData,
962 printf(
" %2d %2d %2d\n",
965 recAttrAttr3->u_32_value());
968 if (rc != 1) APIERROR(myTransaction->
getNdbError());
977 std::cout <<
"-------\n";
985 static void do_indexScan(
Ndb &myNdb, ApiType accessType)
990 std::cout <<
"Running do_indexScan\n";
992 if (myPIndex == NULL)
995 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
998 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
1013 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1019 NdbScanOperation::SF_OrderBy |
1020 NdbScanOperation::SF_MultiRange |
1021 NdbScanOperation::SF_ReadRangeNo;
1041 if (psop->end_of_bound(0))
1042 APIERROR(psop->getNdbError());
1055 if (psop->end_of_bound(1))
1056 APIERROR(psop->getNdbError());
1059 recAttrAttr1=psop->getValue(
"ATTR1");
1060 recAttrAttr2=psop->getValue(
"ATTR2");
1061 recAttrAttr3=psop->getValue(
"ATTR3");
1071 NdbScanOperation::SF_OrderBy |
1072 NdbScanOperation::SF_MultiRange |
1073 NdbScanOperation::SF_ReadRangeNo;
1076 options.optionsPresent=NdbScanOperation::ScanOptions::SO_SCANFLAGS;
1077 options.scan_flags=scanFlags;
1079 psop=myTransaction->
scanIndex(pkeyIndexRecord,
1087 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1097 bound.low_key=(
char*)&low;
1098 bound.low_key_count=1;
1099 bound.low_inclusive=
true;
1100 bound.high_key=(
char*)&high;
1101 bound.high_key_count=1;
1102 bound.high_inclusive=
false;
1105 if (psop->setBound(pkeyIndexRecord, bound))
1115 bound.low_key=(
char*)&low;
1116 bound.low_key_count=1;
1117 bound.low_inclusive=
false;
1118 bound.high_key=(
char*)&high;
1119 bound.high_key_count=1;
1120 bound.high_inclusive=
true;
1123 if (psop->setBound(pkeyIndexRecord, bound))
1130 std::cout <<
"Bad branch : " << accessType <<
"\n";
1145 while (psop->nextResult(
true) == 0)
1147 printf(
" %2d %2d %2d Range no : %2d\n",
1151 psop->get_range_no());
1164 while ((rc = psop->nextResult((
const char**) &prowData,
1169 printf(
" %2d %2d %2d Range no : %2d\n",
1173 psop->get_range_no());
1176 if (rc != 1) APIERROR(myTransaction->
getNdbError());
1184 std::cout <<
"Bad branch : " << accessType <<
"\n";
1194 std::cout <<
"-------\n";
1202 static void do_mixed_indexScan(
Ndb &myNdb)
1207 std::cout <<
"Running do_mixed_indexScan\n";
1209 if (myPIndex == NULL)
1212 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
1215 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
1221 NdbScanOperation::SF_OrderBy |
1222 NdbScanOperation::SF_MultiRange |
1223 NdbScanOperation::SF_ReadRangeNo;
1226 unsigned char attrMask=((1<<attr1ColNum) | (1<<attr2ColNum));
1229 extraGets[0].column= pattr3Col;
1230 extraGets[0].appStorage= NULL;
1231 extraGets[0].recAttr= NULL;
1234 options.optionsPresent=
1235 NdbScanOperation::ScanOptions::SO_SCANFLAGS |
1236 NdbScanOperation::ScanOptions::SO_GETVALUE;
1237 options.scan_flags= scanFlags;
1238 options.extraGetValues= &extraGets[0];
1239 options.numExtraGetValues= 1;
1241 psop=myTransaction->
scanIndex(pkeyIndexRecord,
1249 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1252 recAttrAttr3= extraGets[0].recAttr;
1262 bound.low_key=(
char*)&low;
1263 bound.low_key_count=1;
1264 bound.low_inclusive=
true;
1265 bound.high_key=(
char*)&high;
1266 bound.high_key_count=1;
1267 bound.high_inclusive=
false;
1270 if (psop->setBound(pkeyIndexRecord, bound))
1280 bound.low_key=(
char*)&low;
1281 bound.low_key_count=1;
1282 bound.low_inclusive=
false;
1283 bound.high_key=(
char*)&high;
1284 bound.high_key_count=1;
1285 bound.high_inclusive=
true;
1288 if (psop->setBound(pkeyIndexRecord, bound))
1299 while ((rc = psop->nextResult((
const char**) &prowData,
1303 printf(
" %2d %2d %2d Range no : %2d\n",
1306 recAttrAttr3->u_32_value(),
1307 psop->get_range_no());
1310 if (rc != 1) APIERROR(myTransaction->
getNdbError());
1319 std::cout <<
"-------\n";
1326 static void do_read_and_delete(
Ndb &myNdb)
1332 std::cout <<
"Running do_read_and_delete (NdbRecord only)\n";
1335 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
1347 extraGets[0].column = pattr3Col;
1348 extraGets[0].appStorage = NULL;
1349 extraGets[0].recAttr = NULL;
1350 extraGets[1].column = NdbDictionary::Column::COMMIT_COUNT;
1351 extraGets[1].appStorage = NULL;
1352 extraGets[1].recAttr = NULL;
1354 options.optionsPresent= NdbOperation::OperationOptions::OO_GETVALUE;
1355 options.extraGetValues= &extraGets[0];
1356 options.numExtraGetValues= 2;
1358 unsigned char attrMask = (1<<attr2ColNum);
1361 myTransaction->deleteTuple(pkeyColumnRecord,
1369 if (pop==NULL) APIERROR(myTransaction->
getNdbError());
1374 std::cout <<
"ATTR1 ATTR2 ATTR3 COMMITS" << std::endl;
1375 printf(
" %2d %2d %2d %2d\n",
1383 std::cout <<
"-------\n";
1387 static const int GOT_ROW= 0;
1388 static const int NO_MORE_ROWS= 1;
1389 static const int NEED_TO_FETCH_ROWS= 2;
1394 static void do_scan_update(
Ndb &myNdb, ApiType accessType)
1399 if (myTable == NULL)
1402 std::cout <<
"Running do_scan_update\n";
1405 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
1418 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1425 NdbScanOperation::SF_KeyInfo) != 0)
1428 recAttrAttr1=psop->getValue(
"ATTR1");
1429 recAttrAttr2=psop->getValue(
"ATTR2");
1430 recAttrAttr3=psop->getValue(
"ATTR3");
1437 options.optionsPresent= NdbScanOperation::ScanOptions::SO_SCANFLAGS;
1438 options.scan_flags= NdbScanOperation::SF_KeyInfo;
1440 psop=myTransaction->
scanTable(pallColsRecord,
1446 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1452 std::cout <<
"Bad branch : " << accessType <<
"\n";
1466 int result= NEED_TO_FETCH_ROWS;
1467 Uint32 processed= 0;
1469 while (result == NEED_TO_FETCH_ROWS)
1472 while ((result = psop->nextResult(fetch)) == GOT_ROW)
1480 op->
setValue(
"ATTR2", (10*col2Value));
1505 int result= NEED_TO_FETCH_ROWS;
1508 while (result == NEED_TO_FETCH_ROWS)
1511 while ((result = psop->nextResult((
const char**) &prowData,
1512 fetch,
false)) == GOT_ROW)
1523 const NdbOperation *op = psop->updateCurrentTuple(myTransaction,
1556 std::cout <<
"Bad branch : " << accessType <<
"\n";
1566 std::cout <<
"-------\n";
1572 static void do_scan_delete(
Ndb &myNdb, ApiType accessType)
1577 if (myTable == NULL)
1580 std::cout <<
"Running do_scan_delete\n";
1583 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
1598 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1602 NdbScanOperation::SF_KeyInfo) != 0)
1605 recAttrAttr1=psop->getValue(
"ATTR1");
1614 options.optionsPresent=NdbScanOperation::ScanOptions::SO_SCANFLAGS;
1616 options.scan_flags=NdbScanOperation::SF_KeyInfo;
1618 psop=myTransaction->
scanTable(pkeyColumnRecord,
1624 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1630 std::cout <<
"Bad branch : " << accessType <<
"\n";
1642 int result= NEED_TO_FETCH_ROWS;
1645 while (result == NEED_TO_FETCH_ROWS)
1648 while ((result = psop->nextResult(fetch)) == GOT_ROW)
1659 if (psop->deleteCurrentTuple())
1688 int result= NEED_TO_FETCH_ROWS;
1691 while (result == NEED_TO_FETCH_ROWS)
1700 while ((result = psop->nextResult((
const char**) &prowData,
1719 extraGets[0].column = pattr3Col;
1720 extraGets[0].appStorage = NULL;
1721 extraGets[0].recAttr = NULL;
1722 extraGets[1].column = NdbDictionary::Column::COMMIT_COUNT;
1723 extraGets[1].appStorage = NULL;
1724 extraGets[1].recAttr = NULL;
1726 options.optionsPresent= NdbOperation::OperationOptions::OO_GETVALUE;
1727 options.extraGetValues= &extraGets[0];
1728 options.numExtraGetValues= 2;
1731 unsigned char attrMask = (1<<attr1ColNum) | (1<<attr2ColNum);
1733 theDeleteOp = psop->deleteCurrentTuple(myTransaction,
1740 if (theDeleteOp==NULL)
1744 attr3= extraGets[0].recAttr;
1745 commitCount= extraGets[1].recAttr;
1767 printf(
"Deleted data\n");
1768 printf(
"ATTR1 ATTR2 ATTR3 COMMITS\n");
1769 printf(
" %2d %2d %2d %2d\n",
1783 std::cout <<
"Bad branch : " << accessType <<
"\n";
1793 std::cout <<
"-------\n";
1801 static void do_scan_lock_reread(
Ndb &myNdb, ApiType accessType)
1806 if (myTable == NULL)
1809 std::cout <<
"Running do_scan_lock_reread\n";
1812 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
1823 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1827 NdbScanOperation::SF_KeyInfo) != 0)
1830 recAttrAttr1=psop->getValue(
"ATTR1");
1837 options.optionsPresent= NdbScanOperation::ScanOptions::SO_SCANFLAGS;
1839 options.scan_flags= NdbScanOperation::SF_KeyInfo;
1841 psop=myTransaction->
scanTable(pkeyColumnRecord,
1847 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
1853 std::cout <<
"Bad branch : " << accessType <<
"\n";
1865 int result= NEED_TO_FETCH_ROWS;
1867 NdbRecAttr *attr1, *attr2, *attr3, *commitCount;
1869 while (result == NEED_TO_FETCH_ROWS)
1872 while ((result = psop->nextResult(fetch)) == GOT_ROW)
1889 commitCount=op->
getValue(NdbDictionary::Column::COMMIT_COUNT);
1905 printf(
"Locked and re-read data:\n");
1906 printf(
"ATTR1 ATTR2 ATTR3 COMMITS\n");
1907 printf(
" %2d %2d %2d %2d\n",
1908 attr1->u_32_value(),
1923 int result= NEED_TO_FETCH_ROWS;
1928 while (result == NEED_TO_FETCH_ROWS)
1931 while ((result = psop->nextResult((
const char**) &prowData,
1949 extraGets[0].column = pattr3Col;
1950 extraGets[0].appStorage = NULL;
1951 extraGets[0].recAttr = NULL;
1952 extraGets[1].column = NdbDictionary::Column::COMMIT_COUNT;
1953 extraGets[1].appStorage = NULL;
1954 extraGets[1].recAttr = NULL;
1956 options.optionsPresent=NdbOperation::OperationOptions::OO_GETVALUE;
1957 options.extraGetValues=&extraGets[0];
1958 options.numExtraGetValues=2;
1961 unsigned char attrMask = (1<<attr1ColNum) | (1<<attr2ColNum);
1963 const NdbOperation *lockOp = psop->lockCurrentTuple(myTransaction,
1965 (
char *) &rereadData,
1972 attr3= extraGets[0].recAttr;
1973 commitCount= extraGets[1].recAttr;
1992 printf(
"Locked and re-read data:\n");
1993 printf(
"ATTR1 ATTR2 ATTR3 COMMITS\n");
1994 printf(
" %2d %2d %2d %2d\n",
2009 std::cout <<
"Bad branch : " << accessType <<
"\n";
2019 std::cout <<
"-------\n";
2025 static void do_all_extras_read(
Ndb &myNdb)
2027 std::cout <<
"Running do_all_extras_read(NdbRecord only)\n";
2028 std::cout <<
"ATTR1 ATTR2 ATTR3 COMMIT_COUNT" << std::endl;
2030 for (
int i = 0;
i < 10;
i++) {
2032 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
2035 NdbRecAttr *myRecAttr1, *myRecAttr2, *myRecAttr3, *myRecAttrCC;
2042 extraCols[0].column=pattr1Col;
2043 extraCols[0].appStorage=NULL;
2044 extraCols[0].recAttr=NULL;
2046 extraCols[1].column=pattr2Col;
2047 extraCols[1].appStorage=NULL;
2048 extraCols[1].recAttr=NULL;
2050 extraCols[2].column=pattr3Col;
2051 extraCols[2].appStorage=NULL;
2052 extraCols[2].recAttr=NULL;
2054 extraCols[3].column=NdbDictionary::Column::COMMIT_COUNT;
2055 extraCols[3].appStorage=NULL;
2056 extraCols[3].recAttr=NULL;
2059 opts.optionsPresent = NdbOperation::OperationOptions::OO_GETVALUE;
2061 opts.extraGetValues=&extraCols[0];
2062 opts.numExtraGetValues=4;
2064 unsigned char attrMask= 0;
2070 myTransaction->readTuple(pkeyColumnRecord,
2077 if (pop==NULL) APIERROR(myTransaction->
getNdbError());
2079 myRecAttr1=extraCols[0].recAttr;
2080 myRecAttr2=extraCols[1].recAttr;
2081 myRecAttr3=extraCols[2].recAttr;
2082 myRecAttrCC=extraCols[3].recAttr;
2084 if (myRecAttr1 == NULL) APIERROR(myTransaction->
getNdbError());
2085 if (myRecAttr2 == NULL) APIERROR(myTransaction->
getNdbError());
2086 if (myRecAttr3 == NULL) APIERROR(myTransaction->
getNdbError());
2087 if (myRecAttrCC == NULL) APIERROR(myTransaction->
getNdbError());
2095 printf(
"Detected that deleted tuple %d doesn't exist!\n",
i);
2098 printf(
" %2d %2d %2d %d\n",
2099 myRecAttr1->u_32_value(),
2109 std::cout <<
"-------\n";
2116 static void do_secondary_indexScan(
Ndb &myNdb, ApiType accessType)
2121 std::cout <<
"Running do_secondary_indexScan\n";
2122 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
2125 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
2133 NdbScanOperation::SF_OrderBy |
2134 NdbScanOperation::SF_Descending |
2135 NdbScanOperation::SF_MultiRange |
2136 NdbScanOperation::SF_ReadRangeNo;
2144 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
2160 APIERROR(psop->getNdbError());
2162 APIERROR(psop->getNdbError());
2164 recAttrAttr1=psop->getValue(
"ATTR1");
2165 recAttrAttr2=psop->getValue(
"ATTR2");
2166 recAttrAttr3=psop->getValue(
"ATTR3");
2174 options.optionsPresent=NdbScanOperation::ScanOptions::SO_SCANFLAGS;
2175 options.scan_flags=scanFlags;
2177 psop=myTransaction->
scanIndex(psecondaryIndexRecord,
2185 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
2195 bound.low_key=(
char*)&low;
2196 bound.low_key_count=1;
2197 bound.low_inclusive=
false;
2198 bound.high_key=(
char*)&high;
2199 bound.high_key_count=1;
2200 bound.high_inclusive=
false;
2203 if (psop->setBound(psecondaryIndexRecord, bound))
2210 std::cout <<
"Bad branch : " << accessType <<
"\n";
2226 while (psop->nextResult(
true) == 0)
2228 printf(
" %2d %2d %2d Range no : %2d\n",
2232 psop->get_range_no());
2245 while ((rc = psop->nextResult((
const char**) &prowData,
2250 printf(
" %2d %2d %2d Range no : %2d\n",
2254 psop->get_range_no());
2257 if (rc != 1) APIERROR(myTransaction->
getNdbError());
2265 std::cout <<
"Bad branch : " << accessType <<
"\n";
2275 std::cout <<
"-------\n";
2282 static void do_secondary_indexScanEqual(
Ndb &myNdb, ApiType accessType)
2287 std::cout <<
"Running do_secondary_indexScanEqual\n";
2288 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
2291 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
2298 Uint32 scanFlags = NdbScanOperation::SF_OrderBy;
2308 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
2319 recAttrAttr1=psop->getValue(
"ATTR1");
2320 recAttrAttr2=psop->getValue(
"ATTR2");
2321 recAttrAttr3=psop->getValue(
"ATTR3");
2329 options.optionsPresent= NdbScanOperation::ScanOptions::SO_SCANFLAGS;
2330 options.scan_flags=scanFlags;
2332 psop=myTransaction->
scanIndex(psecondaryIndexRecord,
2340 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
2344 bound.low_key= (
char*)&attr3Eq;
2345 bound.low_key_count= 1;
2346 bound.low_inclusive=
true;
2347 bound.high_key= (
char*)&attr3Eq;
2348 bound.high_key_count= 1;
2349 bound.high_inclusive=
true;
2352 if (psop->setBound(psecondaryIndexRecord, bound))
2359 std::cout <<
"Bad branch : " << accessType <<
"\n";
2377 while ((res= psop->nextResult(
true)) == GOT_ROW)
2379 printf(
" %2d %2d %2d\n",
2385 if (res != NO_MORE_ROWS)
2386 APIERROR(psop->getNdbError());
2398 while ((rc = psop->nextResult((
const char**) &prowData,
2403 printf(
" %2d %2d %2d\n",
2409 if (rc != NO_MORE_ROWS)
2418 std::cout <<
"Bad branch : " << accessType <<
"\n";
2428 std::cout <<
"-------\n";
2435 static void do_interpreted_update(
Ndb &myNdb, ApiType accessType)
2441 std::cout <<
"Running do_interpreted_update\n";
2443 if (myTable == NULL)
2445 if (myPIndex == NULL)
2448 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
2451 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
2463 const Uint32 R1=1, R2=2, R3=3, R4=4, R5=5, R6=6;
2472 if (pop == NULL) APIERROR(myTransaction->
getNdbError());
2478 if (pop->
equal(
"ATTR1", 4) != 0)
2482 recAttrAttr1=pop->
getValue(
"ATTR1");
2483 recAttrAttr2=pop->
getValue(
"ATTR2");
2484 recAttrAttr3=pop->
getValue(
"ATTR3");
2505 if (pop->
sub_reg(R3, R5, R3) != 0)
2509 if (pop->
add_reg(R1, R2, R2) != 0)
2521 if (pop->
subValue(
"ATTR3", (Uint32)30) != 0)
2524 Uint32 comparisonValue= 10;
2527 if (pop->branch_col_lt(pattr3Col->getColumnNo(),
2543 Uint32 comparisonValue2= 344;
2587 recAttrAttr11= pop->
getValue(
"ATTR1");
2588 recAttrAttr12= pop->
getValue(
"ATTR2");
2589 recAttrAttr13= pop->
getValue(
"ATTR3");
2605 if (pop->
sub_reg(R3, R4, R3) != 0)
2609 if (pop->
add_reg(R2, R1, R2) != 0)
2646 if (pop->
add_reg(R1, R2, R6) != 0)
2678 const NdbOperation *op0= myTransaction->readTuple(pkeyColumnRecord,
2686 const Uint32 numWords= 64;
2687 Uint32
space[numWords];
2701 if (code->load_const_u32(R5, 3) != 0)
2705 if (code->read_attr(R1, pattr1Col) != 0)
2707 if (code->read_attr(R2, pattr2Col) != 0)
2709 if (code->read_attr(R3, pattr3Col) != 0)
2713 if (code->sub_reg(R3, R3, R5) != 0)
2717 if (code->add_reg(R2, R1, R2) != 0)
2721 if (code->write_attr(pattr2Col, R2) != 0)
2725 if (code->write_attr(pattr3Col, R3) != 0)
2729 if (code->sub_val(pattr3Col->getColumnNo(), (Uint32)30) != 0)
2732 Uint32 comparisonValue= 10;
2735 if (code->branch_col_lt(&comparisonValue,
2737 pattr3Col->getColumnNo(),
2743 if (code->interpret_exit_nok(627) != 0)
2747 if (code->def_label(0) != 0)
2750 Uint32 comparisonValue2= 344;
2753 if (code->branch_col_eq(&comparisonValue2,
2755 pattr2Col->getColumnNo(),
2761 if (code->interpret_exit_nok(628) != 0)
2765 if (code->def_label(1) != 0)
2769 if (code->load_const_u32(R1, 10) != 0)
2773 if (code->load_const_u32(R3, 2) != 0)
2782 if (code->write_attr(pattr2Col, R2) != 0)
2786 if (code->interpret_exit_ok() != 0)
2794 if (code->load_const_u32(R4, 1) != 0)
2798 if (code->def_label(2) != 0)
2802 if (code->sub_reg(R3, R3, R4) != 0)
2806 if (code->add_reg(R2, R2, R1) != 0)
2810 if (code->branch_ge(R3, R4, 2) != 0)
2814 if (code->branch_label(3) != 0)
2818 if (code->interpret_exit_nok(629) != 0)
2822 if (code->def_label(3) != 0)
2838 if (code->add_reg(R6, R1, R2) != 0)
2871 NdbOperation::OperationOptions::OO_INTERPRETED;
2872 oo.interpretedCode= code;
2874 unsigned char mask= 0;
2876 pop= myTransaction->updateTuple(pkeyColumnRecord,
2880 (
const unsigned char *) &mask,
2896 myTransaction->readTuple(pkeyColumnRecord,
2907 std::cout <<
"Bad branch : " << accessType <<
"\n";
2923 printf(
" %2d %2d %2d Before\n"
2924 " %2d %2d %2d After\n",
2925 recAttrAttr1->u_32_value(),
2936 printf(
" %2d %2d %2d Before\n"
2937 " %2d %2d %2d After\n",
2948 std::cout <<
"Bad branch : " << accessType <<
"\n";
2958 std::cout <<
"-------\n";
2965 static void do_interpreted_scan(
Ndb &myNdb, ApiType accessType)
2970 std::cout <<
"Running do_interpreted_scan\n";
2972 if (myTable == NULL)
2975 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
2978 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
2986 const Uint32 numWords= 64;
2987 Uint32 space[numWords];
2998 Uint32 comparisonValue= 10;
3001 if (code->branch_col_gt(&comparisonValue,
3003 pattr3Col->getColumnNo(),
3008 if (code->interpret_exit_nok() != 0)
3012 if (code->def_label(0) != 0)
3016 if (code->interpret_exit_ok() != 0)
3029 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
3033 if (psop->setInterpretedCode(code) != 0)
3036 recAttrAttr1=psop->getValue(
"ATTR1");
3037 recAttrAttr2=psop->getValue(
"ATTR2");
3038 recAttrAttr3=psop->getValue(
"ATTR3");
3046 so.optionsPresent = NdbScanOperation::ScanOptions::SO_INTERPRETED;
3047 so.interpretedCode= code;
3049 psop=myTransaction->
scanTable(pallColsRecord,
3055 if (psop == NULL) APIERROR(myTransaction->
getNdbError());
3061 std::cout <<
"Bad branch : " << accessType <<
"\n";
3073 while (psop->nextResult(
true) == 0)
3075 printf(
" %2d %2d %2d\n",
3091 while ((rc = psop->nextResult((
const char**) &prowData,
3095 printf(
" %2d %2d %2d\n",
3101 if (rc != NO_MORE_ROWS) APIERROR(myTransaction->
getNdbError());
3109 std::cout <<
"Bad branch : " << accessType <<
"\n";
3119 std::cout <<
"-------\n";
3125 static void do_read_using_default(
Ndb &myNdb)
3131 if (myTable == NULL)
3134 std::cout <<
"Running do_read_using_default_record (NdbRecord only)\n";
3135 std::cout <<
"ATTR1 ATTR2 ATTR3" << std::endl;
3138 char* buffer= (
char*)malloc(NdbDictionary::getRecordRowLength(tableRec));
3142 printf(
"Allocation failed\n");
3146 for (
int i = 0;
i < 10;
i++) {
3148 if (myTransaction == NULL) APIERROR(myNdb.
getNdbError());
3150 char* attr1= NdbDictionary::getValuePtr(tableRec,
3153 *((
unsigned int*)attr1)=
i;
3156 myTransaction->readTuple(tableRec,
3160 if (pop==NULL) APIERROR(myTransaction->
getNdbError());
3169 std::cout <<
"Detected that tuple " <<
i <<
" doesn't exist!" << std::endl;
3175 printf(
" %2d %2d %2d\n",
3177 *((
unsigned int*) NdbDictionary::getValuePtr(tableRec,
3180 *((
unsigned int*) NdbDictionary::getValuePtr(tableRec,
3190 std::cout <<
"-------\n";