From 25aa87e6bbfa027b659df53f62050f42d94ab6ed Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Feb 2007 09:52:18 +0100 Subject: [PATCH] A few minor cleanups for recent AbortOption behaviour change. storage/ndb/include/ndbapi/NdbOperation.hpp: Add some comments describing the new AbortOption handling. storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp: Fix example to work with new AbortOption handling. storage/ndb/src/ndbapi/NdbOperationDefine.cpp: Add forgotten method implementations. --- storage/ndb/include/ndbapi/NdbOperation.hpp | 21 ++++++++++++++----- .../ndbapi_simple_index.cpp | 17 +++++++++++++-- storage/ndb/src/ndbapi/NdbOperationDefine.cpp | 20 ++++++++++++++++-- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/storage/ndb/include/ndbapi/NdbOperation.hpp b/storage/ndb/include/ndbapi/NdbOperation.hpp index 90b90c7e481..380926c6a41 100644 --- a/storage/ndb/include/ndbapi/NdbOperation.hpp +++ b/storage/ndb/include/ndbapi/NdbOperation.hpp @@ -98,7 +98,20 @@ public: }; /** - * How should transaction be handled if operation fails + * How should transaction be handled if operation fails. + * + * If AO_IgnoreError, a failure in one operation will not abort the + * transaction, and NdbTransaction::execute() will return 0 (success). Use + * NdbOperation::getNdbError() to check for errors from individual + * operations. + * + * If AbortOnError, a failure in one operation will abort the transaction + * and cause NdbTransaction::execute() to return -1. + * + * Abort option can be set on execute(), or in the individual operation. + * Setting AO_IgnoreError or AbortOnError in execute() overrides the settings + * on individual operations. Setting DefaultAbortOption in execute() (the + * default) causes individual operation settings to be used. * * For READ, default is AO_IgnoreError * DML, default is AbortOnError @@ -1019,10 +1032,8 @@ protected: NdbBlob* theBlobList; /* - * Abort option per operation, used by blobs. Default -1. If set, - * overrides abort option on connection level. If set to IgnoreError, - * does not cause execute() to return failure. This is different from - * IgnoreError on connection level. + * Abort option per operation, used by blobs. + * See also comments on enum AbortOption. */ Int8 m_abortOption; diff --git a/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp b/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp index dae99642a24..440face79ae 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp @@ -19,6 +19,17 @@ // Correct output from this program is: // // ATTR1 ATTR2 +// 0 0 +// 1 1 +// 2 2 +// 3 3 +// 4 4 +// 5 5 +// 6 6 +// 7 7 +// 8 8 +// 9 9 +// ATTR1 ATTR2 // 0 10 // 1 1 // 2 12 @@ -166,7 +177,8 @@ int main(int argc, char** argv) NdbRecAttr *myRecAttr= myIndexOperation->getValue("ATTR1", NULL); if (myRecAttr == NULL) APIERROR(myTransaction->getNdbError()); - if(myTransaction->execute( NdbTransaction::Commit ) != -1) + if(myTransaction->execute( NdbTransaction::Commit, + NdbOperation::AbortOnError ) != -1) printf(" %2d %2d\n", myRecAttr->u_32_value(), i); myNdb->closeTransaction(myTransaction); @@ -232,7 +244,8 @@ int main(int argc, char** argv) NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL); if (myRecAttr == NULL) APIERROR(myTransaction->getNdbError()); - if(myTransaction->execute( NdbTransaction::Commit ) == -1) + if(myTransaction->execute( NdbTransaction::Commit, + NdbOperation::AbortOnError ) == -1) if (i == 3) { std::cout << "Detected that deleted tuple doesn't exist!\n"; } else { diff --git a/storage/ndb/src/ndbapi/NdbOperationDefine.cpp b/storage/ndb/src/ndbapi/NdbOperationDefine.cpp index 8958b6ec596..b5019cf7386 100644 --- a/storage/ndb/src/ndbapi/NdbOperationDefine.cpp +++ b/storage/ndb/src/ndbapi/NdbOperationDefine.cpp @@ -715,6 +715,22 @@ insertATTRINFO_error1: }//NdbOperation::insertATTRINFOloop() +NdbOperation::AbortOption +NdbOperation::getAbortOption() const +{ + return (AbortOption)m_abortOption; +} - - +int +NdbOperation::setAbortOption(AbortOption ao) +{ + switch(ao) + { + case AO_IgnoreError: + case AbortOnError: + m_abortOption= ao; + return 0; + default: + return -1; + } +}