At 11:20 +0200 11/22/02, Mircea LUTIC wrote:
Hello!
Question: Can I rely on the following behaviour?
mysql> create table test(id integer not null auto_increment primary key, t
char(15));
mysql> insert into test(t) values (last_insert_id());
mysql> insert into test(t) values (last_insert_id()+1);
mysql> select * from test;
+----+------+
| id | t |
+----+------+
| 1 | 0 |
| 2 | 2 |
+----+------+
That is - when used in an insert statement the last_insert_id() returns the
value BEFORE the insert?
No. You have to generate an AUTO_INCREMENT value before using it.
If you were to refer to it before generating it, what's to guarantee
that you would ever generate it?
This is useful when storing hierarchical data in a table by using char() to
store "ancestorid.parentid.objectid."
Suggestion: Document this behaviour.
?
Can't document the behavior you suggest, because LAST_INSERT_ID()
behaves the way it's explained in the manual, not the way you suggest
above.
sql, query
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php