Bug #69509 mysql-js ignores values for auto_increment columns on insert; node.js
Submitted: 18 Jun 2013 23:48 Modified: 1 Jan 2014 22:23
Reporter: Jesper wisborg Krogh Email Updates:
Status: Closed Impact on me:
Category:MySQL Cluster: Node.js client Severity:S2 (Serious)
Version:7.3.2 OS:Linux (Oracle Linux 6)
Assigned to: Bernd Ocklin CPU Architecture:Any

[18 Jun 2013 23:48] Jesper wisborg Krogh
If you have a table with an auto-increment column insert a row using the node.js and explicitly set the value of the auto-increment column, mysql-js overwrites the explicit value with the next auto-increment value.

How to repeat:
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `val` varchar(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1;

Insert a row:

   { id: 2, val: 'b' }

That will be inserted as (1, 'b'). You can keep inserting the same row and you will not get any duplicate key error as the id value just keeps incrementing. After inserting the row three times, the data in t1 is:

mysql> SELECT * FROM t1 ORDER BY id;
| id | val |
|  1 | b   |
|  2 | b   |
|  3 | b   |
3 rows in set (0.00 sec)

Suggested fix:
The behaviour for e.g. using the SQL nodes or ClusterJ is to honour explicitly set values for auto-increment columns. mysql-js should do that as well.
[1 Jan 2014 22:23] Craig Russell
Fixed in mysql-js revision 672
Will be shipped in 7.3.4

Bug 16980227 Autoincrement values ignored on insert

  add field autoIncFieldName to table handler
  use autoIncFieldName for setAutoincrement method

  check needAutoInc flag in operation to set autoincrement functionality

  for insert operation, set needAutoInc if value for autoincrement column 
    is not set in domain object