Bug #29762 The ndbapi-examples don't work as expected due to api changes in MySQL 5.1.16
Submitted: 12 Jul 2007 15:37 Modified: 23 Jul 2007 13:18
Reporter: Rubén Laguna Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.1.19 OS:Any
Assigned to: Tomas Ulin CPU Architecture:Any
Tags: deleteTuple, ndb, ndbapi, ndbapi_examples, nodatafound

[12 Jul 2007 15:37] Rubén Laguna
Description:
mysql-5.1/storage/ndb/ndbapi-examples/ndbapi_simple/ndbapi_simple.cpp relies on 
NdbTransaction::execute() returning -1 when data is not found. But beginning with MySQL 5.1.16 execute() will return  -1 only and only if the transaction was aborted. So ndbapi_simple should check for NdbError::NoDataFound explicitly. 

This behavior is documented in http://dev.mysql.com/doc/ndbapi/en/class-ndbtransaction-execute.html

How to repeat:
compile 5.1.19-ndb-6.3.1-telco
download ndbapi_examples from the bitkeeper repository
compile and link ndbapi_simple using 5.1.19-ndb-6.3.1-telco headers and libraries.
Execute the ndbapi_simple. 

Suggested fix:
Add a check for NdbError:NoDataFound to ndbapi_simple.cpp. see diff output below. 

# diff -c ~/mysql-5.1/storage/ndb/ndbapi-examples/ndbapi_simple/ndbapi_simple.cpp ndbapi_simple.cpp
*** /home/ecerulm/mysql-5.1/storage/ndb/ndbapi-examples/ndbapi_simple/ndbapi_simple.cpp 2007-07-12 17:25:42.000000000 +0200
--- ndbapi_simple.cpp   2007-07-12 17:08:39.000000000 +0200
***************
*** 286,293 ****
        } else {
        APIERROR(myTransaction->getNdbError());
        }
!
!     if (i != 3) {
        printf(" %2d    %2d\n", i, myRecAttr->u_32_value());
      }
      myNdb.closeTransaction(myTransaction);
--- 286,295 ----
        } else {
        APIERROR(myTransaction->getNdbError());
        }
!   //  std::cout << "myTransaction->getNdbError().classification = " << myTransaction->getNdbError().classification << "\n";!     if (myTransaction->getNdbError().classification == NdbError::NoDataFound && i== 3) {
!       std::cout << "Detected that deleted tuple doesn't exist!" << std::endl;
!     } else {
        printf(" %2d    %2d\n", i, myRecAttr->u_32_value());
      }
      myNdb.closeTransaction(myTransaction);
[13 Jul 2007 13:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/30873

ChangeSet@1.2560, 2007-07-13 15:30:36+02:00, tomas@whalegate.ndb.mysql.com +1 -0
  Bug #29762 The ndbapi-examples don't work as expected due to api changes in MySQL 5.1.16]
[19 Jul 2007 15:48] Bugs System
Pushed into 5.1.21-beta
[23 Jul 2007 13:18] Jon Stephens
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

Updated example with code from patch. mysqldoc rev 7183.