added new methods for NdbTransaction::getNdbIndexOperation() and...

added new methods for NdbTransaction::getNdbIndexOperation() and NdbTransaction::getNdbIndexScanOperation() as recommended
made others depricated
updated examples to use recommended
parent ad2550ca
...@@ -291,6 +291,10 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) ...@@ -291,6 +291,10 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData)
{ {
NdbOperation* myNdbOperation; // For operations NdbOperation* myNdbOperation; // For operations
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
async_callback_t * cb; async_callback_t * cb;
int retries = 0; int retries = 0;
...@@ -347,8 +351,7 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) ...@@ -347,8 +351,7 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData)
} }
asynchExitHandler(myNdb); asynchExitHandler(myNdb);
} }
// Error check. If error, then maybe table GARAGE is not in database myNdbOperation = transaction[current].conn->getNdbOperation(myTable);
myNdbOperation = transaction[current].conn->getNdbOperation("GARAGE");
if (myNdbOperation == NULL) if (myNdbOperation == NULL)
{ {
if (asynchErrorHandler(transaction[current].conn, myNdb)) if (asynchErrorHandler(transaction[current].conn, myNdb))
......
...@@ -86,12 +86,15 @@ int main() ...@@ -86,12 +86,15 @@ int main()
/****************************************************** /******************************************************
* Insert (we do two insert transactions in parallel) * * Insert (we do two insert transactions in parallel) *
******************************************************/ ******************************************************/
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
myNdbTransaction[i] = myNdb->startTransaction(); myNdbTransaction[i] = myNdb->startTransaction();
if (myNdbTransaction[i] == NULL) APIERROR(myNdb->getNdbError()); if (myNdbTransaction[i] == NULL) APIERROR(myNdb->getNdbError());
myNdbOperation = myNdbTransaction[i]->getNdbOperation("MYTABLENAME"); myNdbOperation = myNdbTransaction[i]->getNdbOperation(myTable);
// Error check. If error, then maybe table MYTABLENAME is not in database
if (myNdbOperation == NULL) APIERROR(myNdbTransaction[i]->getNdbError()); if (myNdbOperation == NULL) APIERROR(myNdbTransaction[i]->getNdbError());
myNdbOperation->insertTuple(); myNdbOperation->insertTuple();
......
...@@ -88,13 +88,15 @@ void printTransactionError(NdbTransaction *ndbTransaction) { ...@@ -88,13 +88,15 @@ void printTransactionError(NdbTransaction *ndbTransaction) {
// Example insert // Example insert
// @param myNdb Ndb object representing NDB Cluster // @param myNdb Ndb object representing NDB Cluster
// @param myTransaction NdbTransaction used for transaction // @param myTransaction NdbTransaction used for transaction
// @param myTable Table to insert into
// @param error NdbError object returned in case of errors // @param error NdbError object returned in case of errors
// @return -1 in case of failures, 0 otherwise // @return -1 in case of failures, 0 otherwise
// //
int insert(int transactionId, NdbTransaction* myTransaction) { int insert(int transactionId, NdbTransaction* myTransaction,
const NdbDictionary::Table *myTable) {
NdbOperation *myOperation; // For other operations NdbOperation *myOperation; // For other operations
myOperation = myTransaction->getNdbOperation("MYTABLENAME"); myOperation = myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) return -1; if (myOperation == NULL) return -1;
if (myOperation->insertTuple() || if (myOperation->insertTuple() ||
...@@ -113,7 +115,8 @@ int insert(int transactionId, NdbTransaction* myTransaction) { ...@@ -113,7 +115,8 @@ int insert(int transactionId, NdbTransaction* myTransaction) {
// if there are temporary errors (e.g. the NDB Cluster is overloaded). // if there are temporary errors (e.g. the NDB Cluster is overloaded).
// @return -1 failure, 1 success // @return -1 failure, 1 success
// //
int executeInsertTransaction(int transactionId, Ndb* myNdb) { int executeInsertTransaction(int transactionId, Ndb* myNdb,
const NdbDictionary::Table *myTable) {
int result = 0; // No result yet int result = 0; // No result yet
int noOfRetriesLeft = 10; int noOfRetriesLeft = 10;
NdbTransaction *myTransaction; // For other transactions NdbTransaction *myTransaction; // For other transactions
...@@ -129,8 +132,8 @@ int executeInsertTransaction(int transactionId, Ndb* myNdb) { ...@@ -129,8 +132,8 @@ int executeInsertTransaction(int transactionId, Ndb* myNdb) {
APIERROR(myNdb->getNdbError()); APIERROR(myNdb->getNdbError());
ndberror = myNdb->getNdbError(); ndberror = myNdb->getNdbError();
result = -1; // Failure result = -1; // Failure
} else if (insert(transactionId, myTransaction) || } else if (insert(transactionId, myTransaction, myTable) ||
insert(10000+transactionId, myTransaction) || insert(10000+transactionId, myTransaction, myTable) ||
myTransaction->execute(NdbTransaction::Commit)) { myTransaction->execute(NdbTransaction::Commit)) {
TRANSERROR(myTransaction); TRANSERROR(myTransaction);
ndberror = myTransaction->getNdbError(); ndberror = myTransaction->getNdbError();
...@@ -211,11 +214,18 @@ int main() ...@@ -211,11 +214,18 @@ int main()
exit(-1); exit(-1);
} }
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
{
APIERROR(myDict->getNdbError());
return -1;
}
/************************************ /************************************
* Execute some insert transactions * * Execute some insert transactions *
************************************/ ************************************/
for (int i = 10000; i < 20000; i++) { for (int i = 10000; i < 20000; i++) {
executeInsertTransaction(i, myNdb); executeInsertTransaction(i, myNdb, myTable);
} }
delete myNdb; delete myNdb;
......
...@@ -141,6 +141,12 @@ int populate(Ndb * myNdb) ...@@ -141,6 +141,12 @@ int populate(Ndb * myNdb)
int i; int i;
Car cars[15]; Car cars[15];
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
/** /**
* Five blue mercedes * Five blue mercedes
*/ */
...@@ -177,8 +183,7 @@ int populate(Ndb * myNdb) ...@@ -177,8 +183,7 @@ int populate(Ndb * myNdb)
for (i = 0; i < 15; i++) for (i = 0; i < 15; i++)
{ {
NdbOperation* myNdbOperation = myTrans->getNdbOperation("GARAGE"); NdbOperation* myNdbOperation = myTrans->getNdbOperation(myTable);
// Error check. If error, then maybe table MYTABLENAME is not in database
if (myNdbOperation == NULL) if (myNdbOperation == NULL)
APIERROR(myTrans->getNdbError()); APIERROR(myTrans->getNdbError());
myNdbOperation->insertTuple(); myNdbOperation->insertTuple();
...@@ -210,6 +215,12 @@ int scan_delete(Ndb* myNdb, ...@@ -210,6 +215,12 @@ int scan_delete(Ndb* myNdb,
NdbTransaction *myTrans; NdbTransaction *myTrans;
NdbScanOperation *myScanOp; NdbScanOperation *myScanOp;
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
/** /**
* Loop as long as : * Loop as long as :
* retryMax not reached * retryMax not reached
...@@ -246,7 +257,7 @@ int scan_delete(Ndb* myNdb, ...@@ -246,7 +257,7 @@ int scan_delete(Ndb* myNdb,
/** /**
* Get a scan operation. * Get a scan operation.
*/ */
myScanOp = myTrans->getNdbScanOperation("GARAGE"); myScanOp = myTrans->getNdbScanOperation(myTable);
if (myScanOp == NULL) if (myScanOp == NULL)
{ {
std::cout << myTrans->getNdbError().message << std::endl; std::cout << myTrans->getNdbError().message << std::endl;
...@@ -382,6 +393,12 @@ int scan_update(Ndb* myNdb, ...@@ -382,6 +393,12 @@ int scan_update(Ndb* myNdb,
NdbTransaction *myTrans; NdbTransaction *myTrans;
NdbScanOperation *myScanOp; NdbScanOperation *myScanOp;
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
/** /**
* Loop as long as : * Loop as long as :
* retryMax not reached * retryMax not reached
...@@ -419,7 +436,7 @@ int scan_update(Ndb* myNdb, ...@@ -419,7 +436,7 @@ int scan_update(Ndb* myNdb,
/** /**
* Get a scan operation. * Get a scan operation.
*/ */
myScanOp = myTrans->getNdbScanOperation("GARAGE"); myScanOp = myTrans->getNdbScanOperation(myTable);
if (myScanOp == NULL) if (myScanOp == NULL)
{ {
std::cout << myTrans->getNdbError().message << std::endl; std::cout << myTrans->getNdbError().message << std::endl;
...@@ -567,6 +584,12 @@ int scan_print(Ndb * myNdb) ...@@ -567,6 +584,12 @@ int scan_print(Ndb * myNdb)
*/ */
NdbRecAttr * myRecAttr[3]; NdbRecAttr * myRecAttr[3];
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
/** /**
* Loop as long as : * Loop as long as :
* retryMax not reached * retryMax not reached
...@@ -604,7 +627,7 @@ int scan_print(Ndb * myNdb) ...@@ -604,7 +627,7 @@ int scan_print(Ndb * myNdb)
* Define a scan operation. * Define a scan operation.
* NDBAPI. * NDBAPI.
*/ */
myScanOp = myTrans->getNdbScanOperation("GARAGE"); myScanOp = myTrans->getNdbScanOperation(myTable);
if (myScanOp == NULL) if (myScanOp == NULL)
{ {
std::cout << myTrans->getNdbError().message << std::endl; std::cout << myTrans->getNdbError().message << std::endl;
......
...@@ -151,18 +151,24 @@ static void create_table(MYSQL &mysql) ...@@ -151,18 +151,24 @@ static void create_table(MYSQL &mysql)
**************************************************************************/ **************************************************************************/
static void do_insert(Ndb &myNdb) static void do_insert(Ndb &myNdb)
{ {
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
NdbTransaction *myTransaction= myNdb.startTransaction(); NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple(); myOperation->insertTuple();
myOperation->equal("ATTR1", i); myOperation->equal("ATTR1", i);
myOperation->setValue("ATTR2", i); myOperation->setValue("ATTR2", i);
myOperation= myTransaction->getNdbOperation("MYTABLENAME"); myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple(); myOperation->insertTuple();
...@@ -181,11 +187,17 @@ static void do_insert(Ndb &myNdb) ...@@ -181,11 +187,17 @@ static void do_insert(Ndb &myNdb)
*****************************************************************/ *****************************************************************/
static void do_update(Ndb &myNdb) static void do_update(Ndb &myNdb)
{ {
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 10; i+=2) { for (int i = 0; i < 10; i+=2) {
NdbTransaction *myTransaction= myNdb.startTransaction(); NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->updateTuple(); myOperation->updateTuple();
...@@ -204,10 +216,16 @@ static void do_update(Ndb &myNdb) ...@@ -204,10 +216,16 @@ static void do_update(Ndb &myNdb)
*************************************************/ *************************************************/
static void do_delete(Ndb &myNdb) static void do_delete(Ndb &myNdb)
{ {
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
NdbTransaction *myTransaction= myNdb.startTransaction(); NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->deleteTuple(); myOperation->deleteTuple();
...@@ -224,13 +242,19 @@ static void do_delete(Ndb &myNdb) ...@@ -224,13 +242,19 @@ static void do_delete(Ndb &myNdb)
*****************************/ *****************************/
static void do_read(Ndb &myNdb) static void do_read(Ndb &myNdb)
{ {
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
std::cout << "ATTR1 ATTR2" << std::endl; std::cout << "ATTR1 ATTR2" << std::endl;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
NdbTransaction *myTransaction= myNdb.startTransaction(); NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->readTuple(NdbOperation::LM_Read); myOperation->readTuple(NdbOperation::LM_Read);
......
...@@ -106,6 +106,14 @@ int main() ...@@ -106,6 +106,14 @@ int main()
exit(-1); exit(-1);
} }
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
const NdbDictionary::Index *myIndex= myDict->getIndex("MYINDEXNAME","MYTABLENAME");
if (myIndex == NULL)
APIERROR(myDict->getNdbError());
/************************************************************************** /**************************************************************************
* Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) * * Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) *
**************************************************************************/ **************************************************************************/
...@@ -113,14 +121,14 @@ int main() ...@@ -113,14 +121,14 @@ int main()
NdbTransaction *myTransaction= myNdb->startTransaction(); NdbTransaction *myTransaction= myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple(); myOperation->insertTuple();
myOperation->equal("ATTR1", i); myOperation->equal("ATTR1", i);
myOperation->setValue("ATTR2", i); myOperation->setValue("ATTR2", i);
myOperation = myTransaction->getNdbOperation("MYTABLENAME"); myOperation = myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple(); myOperation->insertTuple();
...@@ -143,7 +151,7 @@ int main() ...@@ -143,7 +151,7 @@ int main()
if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
NdbIndexOperation *myIndexOperation= NdbIndexOperation *myIndexOperation=
myTransaction->getNdbIndexOperation("MYINDEXNAME","MYTABLENAME"); myTransaction->getNdbIndexOperation(myIndex);
if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError());
myIndexOperation->readTuple(NdbOperation::LM_Read); myIndexOperation->readTuple(NdbOperation::LM_Read);
...@@ -166,7 +174,7 @@ int main() ...@@ -166,7 +174,7 @@ int main()
if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
NdbIndexOperation *myIndexOperation= NdbIndexOperation *myIndexOperation=
myTransaction->getNdbIndexOperation("MYINDEXNAME", "MYTABLENAME"); myTransaction->getNdbIndexOperation(myIndex);
if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError());
myIndexOperation->updateTuple(); myIndexOperation->updateTuple();
...@@ -187,7 +195,7 @@ int main() ...@@ -187,7 +195,7 @@ int main()
if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
NdbIndexOperation *myIndexOperation= NdbIndexOperation *myIndexOperation=
myTransaction->getNdbIndexOperation("MYINDEXNAME", "MYTABLENAME"); myTransaction->getNdbIndexOperation(myIndex);
if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError());
myIndexOperation->deleteTuple(); myIndexOperation->deleteTuple();
...@@ -209,7 +217,7 @@ int main() ...@@ -209,7 +217,7 @@ int main()
NdbTransaction *myTransaction= myNdb->startTransaction(); NdbTransaction *myTransaction= myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->readTuple(NdbOperation::LM_Read); myOperation->readTuple(NdbOperation::LM_Read);
......
...@@ -115,33 +115,39 @@ ...@@ -115,33 +115,39 @@
This first example uses an NdbOperation: This first example uses an NdbOperation:
@code @code
// 1. Create // 1. Retrieve table object
MyOperation= MyTransaction->getNdbOperation("MYTABLENAME"); myTable= myDict->getTable("MYTABLENAME");
// 2. Create
myOperation= myTransaction->getNdbOperation(myTable);
// 2. Define type of operation and lock mode // 3. Define type of operation and lock mode
MyOperation->readTuple(NdbOperation::LM_Read); myOperation->readTuple(NdbOperation::LM_Read);
// 3. Specify Search Conditions // 4. Specify Search Conditions
MyOperation->equal("ATTR1", i); myOperation->equal("ATTR1", i);
// 4. Attribute Actions // 5. Attribute Actions
MyRecAttr= MyOperation->getValue("ATTR2", NULL); myRecAttr= myOperation->getValue("ATTR2", NULL);
@endcode @endcode
For additional examples of this sort, see @ref ndbapi_simple.cpp. For additional examples of this sort, see @ref ndbapi_simple.cpp.
The second example uses an NdbIndexOperation: The second example uses an NdbIndexOperation:
@code @code
// 1. Create // 1. Retrieve index object
MyOperation= MyTransaction->getNdbIndexOperation("MYINDEX","MYTABLENAME"); myIndex= myDict->getIndex("MYINDEX", "MYTABLENAME");
// 2. Create
myOperation= myTransaction->getNdbIndexOperation(myIndex);
// 2. Define type of operation and lock mode // 3. Define type of operation and lock mode
MyOperation->readTuple(NdbOperation::LM_Read); myOperation->readTuple(NdbOperation::LM_Read);
// 3. Specify Search Conditions // 4. Specify Search Conditions
MyOperation->equal("ATTR1", i); myOperation->equal("ATTR1", i);
// 4. Attribute Actions // 5. Attribute Actions
MyRecAttr = MyOperation->getValue("ATTR2", NULL); myRecAttr = myOperation->getValue("ATTR2", NULL);
@endcode @endcode
Another example of this second type can be found in Another example of this second type can be found in
@ref ndbapi_simple_index.cpp. @ref ndbapi_simple_index.cpp.
...@@ -230,38 +236,44 @@ ...@@ -230,38 +236,44 @@
This first example performs a table scan, using an NdbScanOperation: This first example performs a table scan, using an NdbScanOperation:
@code @code
// 1. Create // 1. Retrieve table object
MyOperation= MyTransaction->getNdbScanOperation("MYTABLENAME"); myTable= myDict->getTable("MYTABLENAME");
// 2. Define type of operation and lock mode // 2. Create
MyOperation->readTuples(NdbOperation::LM_Read); myOperation= myTransaction->getNdbScanOperation(myTable);
// 3. Define type of operation and lock mode
myOperation->readTuples(NdbOperation::LM_Read);
// 3. Specify Search Conditions // 4. Specify Search Conditions
NdbScanFilter sf(MyOperation); NdbScanFilter sf(myOperation);
sf.begin(NdbScanFilter::OR); sf.begin(NdbScanFilter::OR);
sf.eq(0, i); // Return rows with column 0 equal to i or sf.eq(0, i); // Return rows with column 0 equal to i or
sf.eq(1, i+1); // column 1 equal to (i+1) sf.eq(1, i+1); // column 1 equal to (i+1)
sf.end(); sf.end();
// 4. Attribute Actions // 5. Attribute Actions
MyRecAttr= MyOperation->getValue("ATTR2", NULL); myRecAttr= myOperation->getValue("ATTR2", NULL);
@endcode @endcode
Our second example uses an NdbIndexScanOperation to perform an index scan: Our second example uses an NdbIndexScanOperation to perform an index scan:
@code @code
// 1. Create // 1. Retrieve index object
MyOperation= MyTransaction->getNdbIndexScanOperation("MYORDEREDINDEX", "MYTABLENAME"); myIndex= myDict->getIndex("MYORDEREDINDEX", "MYTABLENAME");
// 2. Create
myOperation= myTransaction->getNdbIndexScanOperation(myIndex);
// 2. Define type of operation and lock mode // 3. Define type of operation and lock mode
MyOperation->readTuples(NdbOperation::LM_Read); myOperation->readTuples(NdbOperation::LM_Read);
// 3. Specify Search Conditions // 4. Specify Search Conditions
// All rows with ATTR1 between i and (i+1) // All rows with ATTR1 between i and (i+1)
MyOperation->setBound("ATTR1", NdbIndexScanOperation::BoundGE, i); myOperation->setBound("ATTR1", NdbIndexScanOperation::BoundGE, i);
MyOperation->setBound("ATTR1", NdbIndexScanOperation::BoundLE, i+1); myOperation->setBound("ATTR1", NdbIndexScanOperation::BoundLE, i+1);
// 4. Attribute Actions // 5. Attribute Actions
MyRecAttr = MyOperation->getValue("ATTR2", NULL); myRecAttr = MyOperation->getValue("ATTR2", NULL);
@endcode @endcode
Some additional discussion of each step required to perform a scan follows: Some additional discussion of each step required to perform a scan follows:
......
...@@ -1228,6 +1228,7 @@ public: ...@@ -1228,6 +1228,7 @@ public:
*/ */
int dropTable(const char * name); int dropTable(const char * name);
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/** /**
* Alter defined table given defined Table instance * Alter defined table given defined Table instance
* @param table Table to alter * @param table Table to alter
...@@ -1237,7 +1238,6 @@ public: ...@@ -1237,7 +1238,6 @@ public:
*/ */
int alterTable(const Table &table); int alterTable(const Table &table);
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/** /**
* Invalidate cached table object * Invalidate cached table object
* @param name Name of table to invalidate * @param name Name of table to invalidate
......
...@@ -181,6 +181,7 @@ public: ...@@ -181,6 +181,7 @@ public:
#endif #endif
}; };
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
/** /**
* Get an NdbOperation for a table. * Get an NdbOperation for a table.
* Note that the operation has to be defined before it is executed. * Note that the operation has to be defined before it is executed.
...@@ -192,6 +193,7 @@ public: ...@@ -192,6 +193,7 @@ public:
* @return Pointer to an NdbOperation object if successful, otherwise NULL. * @return Pointer to an NdbOperation object if successful, otherwise NULL.
*/ */
NdbOperation* getNdbOperation(const char* aTableName); NdbOperation* getNdbOperation(const char* aTableName);
#endif
/** /**
* Get an NdbOperation for a table. * Get an NdbOperation for a table.
...@@ -206,6 +208,7 @@ public: ...@@ -206,6 +208,7 @@ public:
*/ */
NdbOperation* getNdbOperation(const NdbDictionary::Table * aTable); NdbOperation* getNdbOperation(const NdbDictionary::Table * aTable);
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
/** /**
* Get an operation from NdbScanOperation idlelist and * Get an operation from NdbScanOperation idlelist and
* get the NdbTransaction object which * get the NdbTransaction object which
...@@ -215,6 +218,7 @@ public: ...@@ -215,6 +218,7 @@ public:
* @return pointer to an NdbOperation object if successful, otherwise NULL * @return pointer to an NdbOperation object if successful, otherwise NULL
*/ */
NdbScanOperation* getNdbScanOperation(const char* aTableName); NdbScanOperation* getNdbScanOperation(const char* aTableName);
#endif
/** /**
* Get an operation from NdbScanOperation idlelist and * Get an operation from NdbScanOperation idlelist and
...@@ -227,6 +231,7 @@ public: ...@@ -227,6 +231,7 @@ public:
*/ */
NdbScanOperation* getNdbScanOperation(const NdbDictionary::Table * aTable); NdbScanOperation* getNdbScanOperation(const NdbDictionary::Table * aTable);
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
/** /**
* Get an operation from NdbIndexScanOperation idlelist and * Get an operation from NdbIndexScanOperation idlelist and
* get the NdbTransaction object which * get the NdbTransaction object which
...@@ -238,6 +243,9 @@ public: ...@@ -238,6 +243,9 @@ public:
*/ */
NdbIndexScanOperation* getNdbIndexScanOperation(const char* anIndexName, NdbIndexScanOperation* getNdbIndexScanOperation(const char* anIndexName,
const char* aTableName); const char* aTableName);
NdbIndexScanOperation* getNdbIndexScanOperation
(const NdbDictionary::Index *anIndex, const NdbDictionary::Table *aTable);
#endif
/** /**
* Get an operation from NdbIndexScanOperation idlelist and * Get an operation from NdbIndexScanOperation idlelist and
...@@ -246,14 +254,12 @@ public: ...@@ -246,14 +254,12 @@ public:
* *
* @param anIndex * @param anIndex
An index object (fetched by NdbDictionary::Dictionary::getIndex). An index object (fetched by NdbDictionary::Dictionary::getIndex).
* @param aTable
A table object (fetched by NdbDictionary::Dictionary::getTable).
* @return pointer to an NdbOperation object if successful, otherwise NULL * @return pointer to an NdbOperation object if successful, otherwise NULL
*/ */
NdbIndexScanOperation* getNdbIndexScanOperation NdbIndexScanOperation* getNdbIndexScanOperation
(const NdbDictionary::Index * anIndex, (const NdbDictionary::Index *anIndex);
const NdbDictionary::Table * aTable);
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
/** /**
* Get an operation from NdbIndexOperation idlelist and * Get an operation from NdbIndexOperation idlelist and
* get the NdbTransaction object that * get the NdbTransaction object that
...@@ -266,21 +272,21 @@ public: ...@@ -266,21 +272,21 @@ public:
*/ */
NdbIndexOperation* getNdbIndexOperation(const char* anIndexName, NdbIndexOperation* getNdbIndexOperation(const char* anIndexName,
const char* aTableName); const char* aTableName);
NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex,
const NdbDictionary::Table *aTable);
#endif
/** /**
* Get an operation from NdbIndexOperation idlelist and * Get an operation from NdbIndexOperation idlelist and
* get the NdbTransaction object that * get the NdbTransaction object that
* was fetched by startTransaction pointing to this operation. * was fetched by startTransaction pointing to this operation.
* *
* @param anIndex * @param anIndex
* An index object (fetched by NdbDictionary::Dictionary::getIndex). * An index object (fetched by NdbDictionary::Dictionary::getIndex).
* @param aTable
* A table object (fetched by NdbDictionary::Dictionary::getTable).
* @return Pointer to an NdbIndexOperation object if * @return Pointer to an NdbIndexOperation object if
* successful, otherwise NULL * successful, otherwise NULL
*/ */
NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index * anIndex, NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex);
const NdbDictionary::Table * aTable);
/** /**
* @name Execute Transaction * @name Execute Transaction
......
...@@ -529,6 +529,12 @@ NdbIndexImpl::getTable() const ...@@ -529,6 +529,12 @@ NdbIndexImpl::getTable() const
return m_tableName.c_str(); return m_tableName.c_str();
} }
const NdbTableImpl *
NdbIndexImpl::getBaseTable() const
{
return m_table;
}
const NdbTableImpl * const NdbTableImpl *
NdbIndexImpl::getIndexTable() const NdbIndexImpl::getIndexTable() const
{ {
......
...@@ -169,6 +169,7 @@ public: ...@@ -169,6 +169,7 @@ public:
void setTable(const char * table); void setTable(const char * table);
const char * getTable() const; const char * getTable() const;
const NdbTableImpl * getIndexTable() const; const NdbTableImpl * getIndexTable() const;
const NdbTableImpl * getBaseTable() const;
Uint32 m_indexId; Uint32 m_indexId;
BaseString m_internalName; BaseString m_internalName;
......
...@@ -1093,10 +1093,16 @@ NdbTransaction::getNdbIndexScanOperation(const char* anIndexName, ...@@ -1093,10 +1093,16 @@ NdbTransaction::getNdbIndexScanOperation(const char* anIndexName,
NdbIndexImpl* index = NdbIndexImpl* index =
theNdb->theDictionary->getIndex(anIndexName, aTableName); theNdb->theDictionary->getIndex(anIndexName, aTableName);
if (index == 0) if (index == 0)
{
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return 0; return 0;
}
NdbTableImpl* table = theNdb->theDictionary->getTable(aTableName); NdbTableImpl* table = theNdb->theDictionary->getTable(aTableName);
if (table == 0) if (table == 0)
{
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return 0; return 0;
}
return getNdbIndexScanOperation(index, table); return getNdbIndexScanOperation(index, table);
} }
...@@ -1115,7 +1121,7 @@ NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index, ...@@ -1115,7 +1121,7 @@ NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index,
} }
return tOp; return tOp;
} else { } else {
setOperationErrorCodeAbort(theNdb->theError.code); setOperationErrorCodeAbort(4271);
return NULL; return NULL;
}//if }//if
} }
...@@ -1124,6 +1130,24 @@ NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index, ...@@ -1124,6 +1130,24 @@ NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index,
return NULL; return NULL;
}//NdbTransaction::getNdbIndexScanOperation() }//NdbTransaction::getNdbIndexScanOperation()
NdbIndexScanOperation*
NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index)
{
if (index)
{
const NdbDictionary::Table *table=
theNdb->theDictionary->getTable(index->getTable());
if (table)
return getNdbIndexScanOperation(index, table);
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return NULL;
}
setOperationErrorCodeAbort(4271);
return NULL;
}
NdbIndexScanOperation* NdbIndexScanOperation*
NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index, NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index,
const NdbDictionary::Table * table) const NdbDictionary::Table * table)
...@@ -1131,8 +1155,8 @@ NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index, ...@@ -1131,8 +1155,8 @@ NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index,
if (index && table) if (index && table)
return getNdbIndexScanOperation(& NdbIndexImpl::getImpl(*index), return getNdbIndexScanOperation(& NdbIndexImpl::getImpl(*index),
& NdbTableImpl::getImpl(*table)); & NdbTableImpl::getImpl(*table));
else setOperationErrorCodeAbort(4271);
return NULL; return NULL;
}//NdbTransaction::getNdbIndexScanOperation() }//NdbTransaction::getNdbIndexScanOperation()
/***************************************************************************** /*****************************************************************************
...@@ -1222,6 +1246,12 @@ NdbTransaction::getNdbIndexOperation(const char* anIndexName, ...@@ -1222,6 +1246,12 @@ NdbTransaction::getNdbIndexOperation(const char* anIndexName,
NdbTableImpl * table = theNdb->theDictionary->getTable(aTableName); NdbTableImpl * table = theNdb->theDictionary->getTable(aTableName);
NdbIndexImpl * index; NdbIndexImpl * index;
if (table == 0)
{
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return NULL;
}
if (table->m_frm.get_data()) if (table->m_frm.get_data())
{ {
// This unique index is defined from SQL level // This unique index is defined from SQL level
...@@ -1244,8 +1274,7 @@ NdbTransaction::getNdbIndexOperation(const char* anIndexName, ...@@ -1244,8 +1274,7 @@ NdbTransaction::getNdbIndexOperation(const char* anIndexName,
return NULL; return NULL;
} }
// table == 0 setOperationErrorCodeAbort(4243);
setOperationErrorCodeAbort(theNdb->theError.code);
return NULL; return NULL;
} }
...@@ -1307,6 +1336,24 @@ NdbTransaction::getNdbIndexOperation(const NdbIndexImpl * anIndex, ...@@ -1307,6 +1336,24 @@ NdbTransaction::getNdbIndexOperation(const NdbIndexImpl * anIndex,
return NULL; return NULL;
}//NdbTransaction::getNdbIndexOperation() }//NdbTransaction::getNdbIndexOperation()
NdbIndexOperation*
NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index)
{
if (index)
{
const NdbDictionary::Table *table=
theNdb->theDictionary->getTable(index->getTable());
if (table)
return getNdbIndexOperation(index, table);
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return NULL;
}
setOperationErrorCodeAbort(4271);
return NULL;
}
NdbIndexOperation* NdbIndexOperation*
NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index, NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index,
const NdbDictionary::Table * table) const NdbDictionary::Table * table)
...@@ -1314,8 +1361,9 @@ NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index, ...@@ -1314,8 +1361,9 @@ NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index,
if (index && table) if (index && table)
return getNdbIndexOperation(& NdbIndexImpl::getImpl(*index), return getNdbIndexOperation(& NdbIndexImpl::getImpl(*index),
& NdbTableImpl::getImpl(*table)); & NdbTableImpl::getImpl(*table));
else
return NULL; setOperationErrorCodeAbort(4271);
return NULL;
}//NdbTransaction::getNdbIndexOperation() }//NdbTransaction::getNdbIndexOperation()
......
...@@ -517,7 +517,8 @@ ErrorBundle ErrorCodes[] = { ...@@ -517,7 +517,8 @@ ErrorBundle ErrorCodes[] = {
{ 4268, IE, "Error in blob head update forced rollback of transaction" }, { 4268, IE, "Error in blob head update forced rollback of transaction" },
{ 4269, IE, "No connection to ndb management server" }, { 4269, IE, "No connection to ndb management server" },
{ 4270, IE, "Unknown blob error" }, { 4270, IE, "Unknown blob error" },
{ 4335, AE, "Only one autoincrement column allowed per table. Having a table without primary key uses an autoincremented hidden key, i.e. a table without a primary key can not have an autoincremented column" } { 4335, AE, "Only one autoincrement column allowed per table. Having a table without primary key uses an autoincremented hidden key, i.e. a table without a primary key can not have an autoincremented column" },
{ 4271, AE, "Invalid index object, not retrieved via getIndex()" }
}; };
static static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment