Re: Insertorupdate and autoincrement [message #1793 is a reply to message #1792] |
Thu, 06 November 2008 09:09 |
AJM
Messages: 2373 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
The behaviour you describe is as expected. Columns with the auto_increment attribute act as follows:
(a) During an INSERT if an auto_increment column has a value which is greater than zero then that value will be used, and a new one will not be generated. It is normal practice not to supply any value, not even zero, for an auto_increment column.
(b) The insertOrUpdate() function will construct a WHERE string using the current primary key and perform a lookup to find out if the record exists or not. If the primary key is auto_increment then for an INSERT there is no value, so the result of the lookup is unpredictable.
In short, do not use the insertOrUpdate() function to insert records which rely on auto_increment to supply their values. In this case you should examine the value yourself and call either insertRecord() or updateRecord() manually.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|