Bug #36067 NdbRecAttr->int32_value() returns unsigned value for TINYINT,SMALLINT,MEDIUMINT
Submitted: 14 Apr 2008 18:19 Modified: 14 Apr 2008 20:58
Reporter: David Shrewsbury Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Frazer Clement CPU Architecture:Any

[14 Apr 2008 18:19] David Shrewsbury
Description:
Tested on 5.1.23 ndb-6.3.10 and ndb-6.3.13

If retrieving a negative number from a table column defined as TINYINT, SMALLINT or MEDIUMINT using int32_value(), the value returned as if it is unsigned. If the column is INT or BIGINT, it works as expected.

Workaround is to use INT instead.

How to repeat:
Run the attached NDB API program after creating this table:

  CREATE TABLE test.t (
     a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
     b TINYINT,
     c SMALLINT,
     d MEDIUMINT,
     e INT,
     f BIGINT
  ) ENGINE=NDB;
  INSERT INTO test.t (b,c,d,e,f) VALUES (-1,-1,-1,-1,-1);

mysql> select * from t;
+---+------+------+------+------+------+
| a | b    | c    | d    | e    | f    |
+---+------+------+------+------+------+
| 1 |   -1 |   -1 |   -1 |   -1 |   -1 | 
+---+------+------+------+------+------+

Output is:
==========

Column Name: b:
  type: Tinyint
  value: 255

Column Name: c:
  type: Smallint
  value: 65535

Column Name: d:
  type: Mediumint
  value: 16777215

Column Name: e:
  type: Int
  value: -1

Column Name: f:
  type: Bigint
  value: -1
[14 Apr 2008 18:20] David Shrewsbury
C++ code

Attachment: bug.cc (text/x-c++src), 4.23 KiB.

[14 Apr 2008 20:53] Jonas Oreland
shouldnt one use NbdRecAttr::short_value() for those datatypes ?
[14 Apr 2008 20:58] Tomas Ulin
So you have to make sure you use the correct conversion function.  The below 3 should be the correct ones for these types.  If you want to have a general function for retriving thew data without knowing the type, you will have to create your own "switch" statement.

  Int32 medium_value() const;
  short short_value() const;
  Int8  int8_value() const;           

BR,

Tomas