diff --git a/ndb/examples/ndbapi_async_example/ndbapi_async.cpp b/ndb/examples/ndbapi_async_example/ndbapi_async.cpp index 68b0aa18c63..16731411c76 100644 --- a/ndb/examples/ndbapi_async_example/ndbapi_async.cpp +++ b/ndb/examples/ndbapi_async_example/ndbapi_async.cpp @@ -291,6 +291,10 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) { 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; int retries = 0; @@ -347,8 +351,7 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) } asynchExitHandler(myNdb); } - // Error check. If error, then maybe table GARAGE is not in database - myNdbOperation = transaction[current].conn->getNdbOperation("GARAGE"); + myNdbOperation = transaction[current].conn->getNdbOperation(myTable); if (myNdbOperation == NULL) { if (asynchErrorHandler(transaction[current].conn, myNdb)) diff --git a/ndb/examples/ndbapi_async_example1/ndbapi_async1.cpp b/ndb/examples/ndbapi_async_example1/ndbapi_async1.cpp index fb806a5bbb5..e8bc19e267b 100644 --- a/ndb/examples/ndbapi_async_example1/ndbapi_async1.cpp +++ b/ndb/examples/ndbapi_async_example1/ndbapi_async1.cpp @@ -86,12 +86,15 @@ int main() /****************************************************** * 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++) { myNdbTransaction[i] = myNdb->startTransaction(); if (myNdbTransaction[i] == NULL) APIERROR(myNdb->getNdbError()); - myNdbOperation = myNdbTransaction[i]->getNdbOperation("MYTABLENAME"); - // Error check. If error, then maybe table MYTABLENAME is not in database + myNdbOperation = myNdbTransaction[i]->getNdbOperation(myTable); if (myNdbOperation == NULL) APIERROR(myNdbTransaction[i]->getNdbError()); myNdbOperation->insertTuple(); diff --git a/ndb/examples/ndbapi_retries_example/ndbapi_retries.cpp b/ndb/examples/ndbapi_retries_example/ndbapi_retries.cpp index d14e0cf4553..8c29fe31446 100644 --- a/ndb/examples/ndbapi_retries_example/ndbapi_retries.cpp +++ b/ndb/examples/ndbapi_retries_example/ndbapi_retries.cpp @@ -88,13 +88,15 @@ void printTransactionError(NdbTransaction *ndbTransaction) { // Example insert // @param myNdb Ndb object representing NDB Cluster // @param myTransaction NdbTransaction used for transaction +// @param myTable Table to insert into // @param error NdbError object returned in case of errors // @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 - myOperation = myTransaction->getNdbOperation("MYTABLENAME"); + myOperation = myTransaction->getNdbOperation(myTable); if (myOperation == NULL) return -1; if (myOperation->insertTuple() || @@ -113,7 +115,8 @@ int insert(int transactionId, NdbTransaction* myTransaction) { // if there are temporary errors (e.g. the NDB Cluster is overloaded). // @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 noOfRetriesLeft = 10; NdbTransaction *myTransaction; // For other transactions @@ -129,8 +132,8 @@ int executeInsertTransaction(int transactionId, Ndb* myNdb) { APIERROR(myNdb->getNdbError()); ndberror = myNdb->getNdbError(); result = -1; // Failure - } else if (insert(transactionId, myTransaction) || - insert(10000+transactionId, myTransaction) || + } else if (insert(transactionId, myTransaction, myTable) || + insert(10000+transactionId, myTransaction, myTable) || myTransaction->execute(NdbTransaction::Commit)) { TRANSERROR(myTransaction); ndberror = myTransaction->getNdbError(); @@ -211,11 +214,18 @@ int main() 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 * ************************************/ for (int i = 10000; i < 20000; i++) { - executeInsertTransaction(i, myNdb); + executeInsertTransaction(i, myNdb, myTable); } delete myNdb; diff --git a/ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp b/ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp index 183dd69f648..bb19eaaf1d6 100644 --- a/ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp +++ b/ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp @@ -141,6 +141,12 @@ int populate(Ndb * myNdb) int i; 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 */ @@ -177,8 +183,7 @@ int populate(Ndb * myNdb) for (i = 0; i < 15; i++) { - NdbOperation* myNdbOperation = myTrans->getNdbOperation("GARAGE"); - // Error check. If error, then maybe table MYTABLENAME is not in database + NdbOperation* myNdbOperation = myTrans->getNdbOperation(myTable); if (myNdbOperation == NULL) APIERROR(myTrans->getNdbError()); myNdbOperation->insertTuple(); @@ -210,6 +215,12 @@ int scan_delete(Ndb* myNdb, NdbTransaction *myTrans; 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 : * retryMax not reached @@ -246,7 +257,7 @@ int scan_delete(Ndb* myNdb, /** * Get a scan operation. */ - myScanOp = myTrans->getNdbScanOperation("GARAGE"); + myScanOp = myTrans->getNdbScanOperation(myTable); if (myScanOp == NULL) { std::cout << myTrans->getNdbError().message << std::endl; @@ -382,6 +393,12 @@ int scan_update(Ndb* myNdb, NdbTransaction *myTrans; 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 : * retryMax not reached @@ -419,7 +436,7 @@ int scan_update(Ndb* myNdb, /** * Get a scan operation. */ - myScanOp = myTrans->getNdbScanOperation("GARAGE"); + myScanOp = myTrans->getNdbScanOperation(myTable); if (myScanOp == NULL) { std::cout << myTrans->getNdbError().message << std::endl; @@ -567,6 +584,12 @@ int scan_print(Ndb * myNdb) */ 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 : * retryMax not reached @@ -604,7 +627,7 @@ int scan_print(Ndb * myNdb) * Define a scan operation. * NDBAPI. */ - myScanOp = myTrans->getNdbScanOperation("GARAGE"); + myScanOp = myTrans->getNdbScanOperation(myTable); if (myScanOp == NULL) { std::cout << myTrans->getNdbError().message << std::endl; diff --git a/ndb/examples/ndbapi_simple_example/ndbapi_simple.cpp b/ndb/examples/ndbapi_simple_example/ndbapi_simple.cpp index 82b7abc16eb..152d4fa44af 100644 --- a/ndb/examples/ndbapi_simple_example/ndbapi_simple.cpp +++ b/ndb/examples/ndbapi_simple_example/ndbapi_simple.cpp @@ -151,18 +151,24 @@ static void create_table(MYSQL &mysql) **************************************************************************/ 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++) { NdbTransaction *myTransaction= myNdb.startTransaction(); if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); - NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); + NdbOperation *myOperation= myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->insertTuple(); myOperation->equal("ATTR1", i); myOperation->setValue("ATTR2", i); - myOperation= myTransaction->getNdbOperation("MYTABLENAME"); + myOperation= myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->insertTuple(); @@ -181,11 +187,17 @@ static void do_insert(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) { NdbTransaction *myTransaction= myNdb.startTransaction(); if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); - NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); + NdbOperation *myOperation= myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->updateTuple(); @@ -204,10 +216,16 @@ static void do_update(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(); if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); - NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); + NdbOperation *myOperation= myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->deleteTuple(); @@ -224,13 +242,19 @@ static void do_delete(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; for (int i = 0; i < 10; i++) { NdbTransaction *myTransaction= myNdb.startTransaction(); if (myTransaction == NULL) APIERROR(myNdb.getNdbError()); - NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); + NdbOperation *myOperation= myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->readTuple(NdbOperation::LM_Read); diff --git a/ndb/examples/ndbapi_simple_index_example/ndbapi_simple_index.cpp b/ndb/examples/ndbapi_simple_index_example/ndbapi_simple_index.cpp index 7d70dc723f8..5afaf6078d1 100644 --- a/ndb/examples/ndbapi_simple_index_example/ndbapi_simple_index.cpp +++ b/ndb/examples/ndbapi_simple_index_example/ndbapi_simple_index.cpp @@ -106,6 +106,14 @@ int main() 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) * **************************************************************************/ @@ -113,14 +121,14 @@ int main() NdbTransaction *myTransaction= myNdb->startTransaction(); if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); - NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); + NdbOperation *myOperation= myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->insertTuple(); myOperation->equal("ATTR1", i); myOperation->setValue("ATTR2", i); - myOperation = myTransaction->getNdbOperation("MYTABLENAME"); + myOperation = myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->insertTuple(); @@ -143,7 +151,7 @@ int main() if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); NdbIndexOperation *myIndexOperation= - myTransaction->getNdbIndexOperation("MYINDEXNAME","MYTABLENAME"); + myTransaction->getNdbIndexOperation(myIndex); if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError()); myIndexOperation->readTuple(NdbOperation::LM_Read); @@ -166,7 +174,7 @@ int main() if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); NdbIndexOperation *myIndexOperation= - myTransaction->getNdbIndexOperation("MYINDEXNAME", "MYTABLENAME"); + myTransaction->getNdbIndexOperation(myIndex); if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError()); myIndexOperation->updateTuple(); @@ -187,7 +195,7 @@ int main() if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); NdbIndexOperation *myIndexOperation= - myTransaction->getNdbIndexOperation("MYINDEXNAME", "MYTABLENAME"); + myTransaction->getNdbIndexOperation(myIndex); if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError()); myIndexOperation->deleteTuple(); @@ -209,7 +217,7 @@ int main() NdbTransaction *myTransaction= myNdb->startTransaction(); if (myTransaction == NULL) APIERROR(myNdb->getNdbError()); - NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); + NdbOperation *myOperation= myTransaction->getNdbOperation(myTable); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->readTuple(NdbOperation::LM_Read); diff --git a/ndb/include/ndbapi/Ndb.hpp b/ndb/include/ndbapi/Ndb.hpp index 049abf92d26..07d2407bca9 100644 --- a/ndb/include/ndbapi/Ndb.hpp +++ b/ndb/include/ndbapi/Ndb.hpp @@ -115,33 +115,39 @@ This first example uses an NdbOperation: @code - // 1. Create - MyOperation= MyTransaction->getNdbOperation("MYTABLENAME"); - - // 2. Define type of operation and lock mode - MyOperation->readTuple(NdbOperation::LM_Read); + // 1. Retrieve table object + myTable= myDict->getTable("MYTABLENAME"); - // 3. Specify Search Conditions - MyOperation->equal("ATTR1", i); + // 2. Create + myOperation= myTransaction->getNdbOperation(myTable); - // 4. Attribute Actions - MyRecAttr= MyOperation->getValue("ATTR2", NULL); + // 3. Define type of operation and lock mode + myOperation->readTuple(NdbOperation::LM_Read); + + // 4. Specify Search Conditions + myOperation->equal("ATTR1", i); + + // 5. Attribute Actions + myRecAttr= myOperation->getValue("ATTR2", NULL); @endcode For additional examples of this sort, see @ref ndbapi_simple.cpp. The second example uses an NdbIndexOperation: @code - // 1. Create - MyOperation= MyTransaction->getNdbIndexOperation("MYINDEX","MYTABLENAME"); + // 1. Retrieve index object + myIndex= myDict->getIndex("MYINDEX", "MYTABLENAME"); - // 2. Define type of operation and lock mode - MyOperation->readTuple(NdbOperation::LM_Read); + // 2. Create + myOperation= myTransaction->getNdbIndexOperation(myIndex); - // 3. Specify Search Conditions - MyOperation->equal("ATTR1", i); + // 3. Define type of operation and lock mode + myOperation->readTuple(NdbOperation::LM_Read); - // 4. Attribute Actions - MyRecAttr = MyOperation->getValue("ATTR2", NULL); + // 4. Specify Search Conditions + myOperation->equal("ATTR1", i); + + // 5. Attribute Actions + myRecAttr = myOperation->getValue("ATTR2", NULL); @endcode Another example of this second type can be found in @ref ndbapi_simple_index.cpp. @@ -230,38 +236,44 @@ This first example performs a table scan, using an NdbScanOperation: @code - // 1. Create - MyOperation= MyTransaction->getNdbScanOperation("MYTABLENAME"); + // 1. Retrieve table object + myTable= myDict->getTable("MYTABLENAME"); - // 2. Define type of operation and lock mode - MyOperation->readTuples(NdbOperation::LM_Read); + // 2. Create + myOperation= myTransaction->getNdbScanOperation(myTable); + + // 3. Define type of operation and lock mode + myOperation->readTuples(NdbOperation::LM_Read); - // 3. Specify Search Conditions - NdbScanFilter sf(MyOperation); + // 4. Specify Search Conditions + NdbScanFilter sf(myOperation); sf.begin(NdbScanFilter::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.end(); - // 4. Attribute Actions - MyRecAttr= MyOperation->getValue("ATTR2", NULL); + // 5. Attribute Actions + myRecAttr= myOperation->getValue("ATTR2", NULL); @endcode Our second example uses an NdbIndexScanOperation to perform an index scan: @code - // 1. Create - MyOperation= MyTransaction->getNdbIndexScanOperation("MYORDEREDINDEX", "MYTABLENAME"); + // 1. Retrieve index object + myIndex= myDict->getIndex("MYORDEREDINDEX", "MYTABLENAME"); - // 2. Define type of operation and lock mode - MyOperation->readTuples(NdbOperation::LM_Read); + // 2. Create + myOperation= myTransaction->getNdbIndexScanOperation(myIndex); - // 3. Specify Search Conditions + // 3. Define type of operation and lock mode + myOperation->readTuples(NdbOperation::LM_Read); + + // 4. Specify Search Conditions // All rows with ATTR1 between i and (i+1) - MyOperation->setBound("ATTR1", NdbIndexScanOperation::BoundGE, i); - MyOperation->setBound("ATTR1", NdbIndexScanOperation::BoundLE, i+1); + myOperation->setBound("ATTR1", NdbIndexScanOperation::BoundGE, i); + myOperation->setBound("ATTR1", NdbIndexScanOperation::BoundLE, i+1); - // 4. Attribute Actions - MyRecAttr = MyOperation->getValue("ATTR2", NULL); + // 5. Attribute Actions + myRecAttr = MyOperation->getValue("ATTR2", NULL); @endcode Some additional discussion of each step required to perform a scan follows: diff --git a/ndb/include/ndbapi/NdbDictionary.hpp b/ndb/include/ndbapi/NdbDictionary.hpp index 707dbd63f06..b4e670dfb89 100644 --- a/ndb/include/ndbapi/NdbDictionary.hpp +++ b/ndb/include/ndbapi/NdbDictionary.hpp @@ -1228,6 +1228,7 @@ public: */ int dropTable(const char * name); +#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** * Alter defined table given defined Table instance * @param table Table to alter @@ -1237,7 +1238,6 @@ public: */ int alterTable(const Table &table); -#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** * Invalidate cached table object * @param name Name of table to invalidate diff --git a/ndb/include/ndbapi/NdbTransaction.hpp b/ndb/include/ndbapi/NdbTransaction.hpp index 42c8271efee..148f4911ed9 100644 --- a/ndb/include/ndbapi/NdbTransaction.hpp +++ b/ndb/include/ndbapi/NdbTransaction.hpp @@ -181,6 +181,7 @@ public: #endif }; +#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an NdbOperation for a table. * Note that the operation has to be defined before it is executed. @@ -192,6 +193,7 @@ public: * @return Pointer to an NdbOperation object if successful, otherwise NULL. */ NdbOperation* getNdbOperation(const char* aTableName); +#endif /** * Get an NdbOperation for a table. @@ -206,6 +208,7 @@ public: */ NdbOperation* getNdbOperation(const NdbDictionary::Table * aTable); +#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an operation from NdbScanOperation idlelist and * get the NdbTransaction object which @@ -215,6 +218,7 @@ public: * @return pointer to an NdbOperation object if successful, otherwise NULL */ NdbScanOperation* getNdbScanOperation(const char* aTableName); +#endif /** * Get an operation from NdbScanOperation idlelist and @@ -227,6 +231,7 @@ public: */ NdbScanOperation* getNdbScanOperation(const NdbDictionary::Table * aTable); +#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an operation from NdbIndexScanOperation idlelist and * get the NdbTransaction object which @@ -238,6 +243,9 @@ public: */ NdbIndexScanOperation* getNdbIndexScanOperation(const char* anIndexName, const char* aTableName); + NdbIndexScanOperation* getNdbIndexScanOperation + (const NdbDictionary::Index *anIndex, const NdbDictionary::Table *aTable); +#endif /** * Get an operation from NdbIndexScanOperation idlelist and @@ -246,14 +254,12 @@ public: * * @param anIndex 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 */ NdbIndexScanOperation* getNdbIndexScanOperation - (const NdbDictionary::Index * anIndex, - const NdbDictionary::Table * aTable); + (const NdbDictionary::Index *anIndex); +#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an operation from NdbIndexOperation idlelist and * get the NdbTransaction object that @@ -266,21 +272,21 @@ public: */ NdbIndexOperation* getNdbIndexOperation(const char* anIndexName, const char* aTableName); + NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex, + const NdbDictionary::Table *aTable); +#endif /** * Get an operation from NdbIndexOperation idlelist and * get the NdbTransaction object that * was fetched by startTransaction pointing to this operation. * - * @param anIndex + * @param anIndex * 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 * successful, otherwise NULL */ - NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index * anIndex, - const NdbDictionary::Table * aTable); + NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex); /** * @name Execute Transaction diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 07a186d8850..596ac7f990d 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -529,6 +529,12 @@ NdbIndexImpl::getTable() const return m_tableName.c_str(); } +const NdbTableImpl * +NdbIndexImpl::getBaseTable() const +{ + return m_table; +} + const NdbTableImpl * NdbIndexImpl::getIndexTable() const { diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.hpp b/ndb/src/ndbapi/NdbDictionaryImpl.hpp index 2738c7e65b1..f4ba509162f 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.hpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.hpp @@ -169,6 +169,7 @@ public: void setTable(const char * table); const char * getTable() const; const NdbTableImpl * getIndexTable() const; + const NdbTableImpl * getBaseTable() const; Uint32 m_indexId; BaseString m_internalName; diff --git a/ndb/src/ndbapi/NdbTransaction.cpp b/ndb/src/ndbapi/NdbTransaction.cpp index f6664657f73..ab6c0ca3e38 100644 --- a/ndb/src/ndbapi/NdbTransaction.cpp +++ b/ndb/src/ndbapi/NdbTransaction.cpp @@ -1093,10 +1093,16 @@ NdbTransaction::getNdbIndexScanOperation(const char* anIndexName, NdbIndexImpl* index = theNdb->theDictionary->getIndex(anIndexName, aTableName); if (index == 0) + { + setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code); return 0; + } NdbTableImpl* table = theNdb->theDictionary->getTable(aTableName); if (table == 0) + { + setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code); return 0; + } return getNdbIndexScanOperation(index, table); } @@ -1115,7 +1121,7 @@ NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index, } return tOp; } else { - setOperationErrorCodeAbort(theNdb->theError.code); + setOperationErrorCodeAbort(4271); return NULL; }//if } @@ -1124,6 +1130,24 @@ NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index, return NULL; }//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* NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index, const NdbDictionary::Table * table) @@ -1131,8 +1155,8 @@ NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index, if (index && table) return getNdbIndexScanOperation(& NdbIndexImpl::getImpl(*index), & NdbTableImpl::getImpl(*table)); - else - return NULL; + setOperationErrorCodeAbort(4271); + return NULL; }//NdbTransaction::getNdbIndexScanOperation() /***************************************************************************** @@ -1222,6 +1246,12 @@ NdbTransaction::getNdbIndexOperation(const char* anIndexName, NdbTableImpl * table = theNdb->theDictionary->getTable(aTableName); NdbIndexImpl * index; + if (table == 0) + { + setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code); + return NULL; + } + if (table->m_frm.get_data()) { // This unique index is defined from SQL level @@ -1244,8 +1274,7 @@ NdbTransaction::getNdbIndexOperation(const char* anIndexName, return NULL; } - // table == 0 - setOperationErrorCodeAbort(theNdb->theError.code); + setOperationErrorCodeAbort(4243); return NULL; } @@ -1307,6 +1336,24 @@ NdbTransaction::getNdbIndexOperation(const NdbIndexImpl * anIndex, return NULL; }//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* NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index, const NdbDictionary::Table * table) @@ -1314,8 +1361,9 @@ NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index, if (index && table) return getNdbIndexOperation(& NdbIndexImpl::getImpl(*index), & NdbTableImpl::getImpl(*table)); - else - return NULL; + + setOperationErrorCodeAbort(4271); + return NULL; }//NdbTransaction::getNdbIndexOperation() diff --git a/ndb/src/ndbapi/ndberror.c b/ndb/src/ndbapi/ndberror.c index 1e87e8481d0..08f2c8dcc7a 100644 --- a/ndb/src/ndbapi/ndberror.c +++ b/ndb/src/ndbapi/ndberror.c @@ -517,7 +517,8 @@ ErrorBundle ErrorCodes[] = { { 4268, IE, "Error in blob head update forced rollback of transaction" }, { 4269, IE, "No connection to ndb management server" }, { 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