Gleb Paharenko:
> Could you provide a repeatable test case for you problem?
I don't know how repeatable this is. As I said I have one computer where it
seems to work sometimes, as if there's a race condition. Right now it seems
repeatable on the computer I'm using at the moment:
mysql> select version();
+-----------+
| version() |
+-----------+
| 4.1.14 |
+-----------+
1 row in set (0.00 sec)
mysql> create table parent (
-> ID int unsigned not null auto_increment,
-> value varchar(50),
-> primary key (ID)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> create table child (
-> ID int unsigned not null auto_increment,
-> parent_ID int unsigned not null,
-> value varchar(50),
-> primary key (ID)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> insert into parent (value) values ('a');
Query OK, 1 row affected (0.00 sec)
mysql> insert into child (parent_ID, value) values
-> (last_insert_ID(), 'b1'), (last_insert_ID(), 'b2'),
-> (last_insert_ID(), 'b3');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> insert into parent (value) values ('c');
Query OK, 1 row affected (0.00 sec)
mysql> insert into child (parent_ID, value) values
-> (last_insert_ID(), 'd1'), (last_insert_ID(), 'd2'),
-> (last_insert_ID(), 'd3');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from child;
+----+-----------+-------+
| ID | parent_ID | value |
+----+-----------+-------+
| 1 | 1 | b1 |
| 2 | 1 | b2 |
| 3 | 2 | b3 |
| 4 | 2 | d1 |
| 5 | 4 | d2 |
| 6 | 5 | d3 |
+----+-----------+-------+
6 rows in set (0.00 sec)
Note how child rows 1 and 4 have the IDs of their respective parent row in the
parent_ID field, but child rows 3, 5 and 6 have the ID of the preceding child
row instead. (For row 2 we can't tell the difference.)
Here's the SQL code for easy copying:
use test;
create table parent (
ID int unsigned not null auto_increment,
value varchar(50),
primary key (ID)
);
create table child (
ID int unsigned not null auto_increment,
parent_ID int unsigned not null,
value varchar(50),
primary key (ID)
);
insert into parent (value) values ('a');
insert into child (parent_ID, value) values
(last_insert_ID(), 'b1'), (last_insert_ID(), 'b2'),
(last_insert_ID(), 'b3');
insert into parent (value) values ('c');
insert into child (parent_ID, value) values
(last_insert_ID(), 'd1'), (last_insert_ID(), 'd2'),
(last_insert_ID(), 'd3');
select * from child;
Björn Persson
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]