В MySQL, в insertIntoA
вы должны иметь возможность:
SELECT LAST_INSERT_ID()
... на том же соединении, которое вы использовали для вставки, при условии, что вы ищете значение столбца identity
.
РЕДАКТИРОВАТЬ : Если вы делаете это, и оно не работает (согласно вашему комментарию), я бы посмотрел на средние слои, чтобы увидеть, что происходит. С MySQL все в порядке:
mysql> create table A (id int(11) not null auto_increment, descr varchar(64), primary key (id));
Query OK, 0 rows affected (0.13 sec)
mysql> create table B (fk int(11) not null, descr varchar(64));
Query OK, 0 rows affected (0.06 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into A (descr) values ('Testing 1 2 3');
Query OK, 1 row affected (0.00 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.03 sec)
mysql> insert into B (fk, descr) values (1, 'Test complete');
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.03 sec)
mysql> select * from A;
+----+---------------+
| id | descr |
+----+---------------+
| 1 | Testing 1 2 3 |
+----+---------------+
1 row in set (0.02 sec)
mysql> select * from B;
+----+---------------+
| fk | descr |
+----+---------------+
| 1 | Test complete |
+----+---------------+
1 row in set (0.00 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into A (descr) values ('Second test');
Query OK, 1 row affected (0.01 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
mysql> insert into B (fk, descr) values (2, 'Second test complete');
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.08 sec)
mysql> select * from A;
+----+---------------+
| id | descr |
+----+---------------+
| 1 | Testing 1 2 3 |
| 2 | Second test |
+----+---------------+
2 rows in set (0.02 sec)
mysql> select * from B;
+----+----------------------+
| fk | descr |
+----+----------------------+
| 1 | Test complete |
| 2 | Second test complete |
+----+----------------------+
2 rows in set (0.00 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into A (descr) values ('We''ll roll this one back.');
Query OK, 1 row affected (0.00 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 3 |
+------------------+
1 row in set (0.00 sec)
mysql> insert into B (fk, descr) values (3, 'Won''t see this one.');
Query OK, 1 row affected (0.00 sec)
mysql> select * from B;
+----+----------------------+
| fk | descr |
+----+----------------------+
| 1 | Test complete |
| 2 | Second test complete |
| 3 | Won't see this one. |
+----+----------------------+
3 rows in set (0.00 sec)
mysql> rollback;
Query OK, 0 rows affected (0.03 sec)
mysql> select * from A;
+----+---------------+
| id | descr |
+----+---------------+
| 1 | Testing 1 2 3 |
| 2 | Second test |
+----+---------------+
2 rows in set (0.00 sec)
mysql> select * from B;
+----+----------------------+
| fk | descr |
+----+----------------------+
| 1 | Test complete |
| 2 | Second test complete |
+----+----------------------+
2 rows in set (0.00 sec)