Bug #23612 NdbOperation::incValue() sets value to 0
Submitted: 25 Oct 2006 4:55 Modified: 15 Feb 2007 20:46
Reporter: John David Duncan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:5.0.27, 5.0.20 OS:MacOS (Mac OS X 10.4)
Assigned to: Hartmut Holzgraefe CPU Architecture:Any

[25 Oct 2006 4:55] John David Duncan
Description:
I am trying to use interpretedUpdateTuple and incValue().

I expect the program in the test case here to increment the value of a column, but instead it sets the column to 0.

 This is not in the documentation. 

How to repeat:
CREATE DATABASE ndb_test ;
use ndb_test ;

CREATE TABLE table8_counter  (
  i int not null primary key,
  c int unsigned not null
) type = ndb;

insert into table8_counter values (1,22) ;

----------- compile this -------
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include "NdbApi.hpp"

int main() {
  Ndb *db;
  const NdbDictionary::Dictionary *dict;
  const NdbDictionary::Table *tab;
  NdbTransaction *tx;
  NdbOperation *op;
  const char *connect_string = "";
  const char *my_database = "ndb_test";
  const char *my_table = "table8_counter";
  
  ndb_init();

  Ndb_cluster_connection conn(connect_string);
  conn.connect(4,5,1);
  conn.wait_until_ready(20, 0);
  
  db = new Ndb( & conn);
  db->init();
  db->setDatabaseName(my_database);
  dict = db->getDictionary();
  tab = dict->getTable(my_table);
  
  tx = db->startTransaction();
  if(!tx) puts(db->getNdbError().message);
  
  op = tx->getNdbOperation(my_table);
  if(!op) puts(db->getNdbError().message);
  
  printf("table: %s \n", op->getTableName());

  if ( op->interpretedUpdateTuple() ||
       op->equal((Uint32) 0,1) ||
       op->incValue("c", (Uint32) 1)
     ) {
        puts("Something failed\n");
        puts(op->getNdbError().message);
  }
  
  if(tx->execute( NdbTransaction::Commit )) {
    puts("Execute failed.\n");
    puts(tx->getNdbError().message);
  }
  
  tx->close();
  
  delete db;
  return 0;
}

------------
Run the program.

Do SELECT * from table8_counter ;

c should be 23, but it is 0.
[1 Nov 2006 11:48] Valeriy Kravchuk
Thank you for a problem report. Please, try to repeat with a newer version, 5.0.27, and inform about the results.
[2 Nov 2006 6:46] John David Duncan
I repeated with 5.0.27, and I see the same results.
[8 Nov 2006 23:59] Johan Andersson
Works fine for me on
5.0.27
5.1.x
[9 Nov 2006 3:45] John David Duncan
Johan, what OS did you use?

I just tested on Linux (Ubuntu 6, Athlon 64) with 5.0.27 and it works correctly there.

However this test still does not work for me on the Mac (OS X 10.4 PPC), where the value is set to zero.
[15 Feb 2007 20:46] John David Duncan
Retested with 5.1.15 -- This now works correctly both on Mac PPC and Linux intel.  I'm not really sure what the problem was.