here are my tables
test(tno,tname),
test2(t2no,tno,...);
test3(t3no,t2no,y,...);
I want into insert the data into these three tables one by one in one transaction, so that the id generated in test1 will be referred in test2 and so on. but my problem is multiple users may access the same page at once. at that time id of one fellow is being referring in another’s record. my db has autocommit=1. For this I used, locks by locking these tables first. then I tried doing the above, so that a user will wait until its previous one’s details gets stored. though it accepts the data and keeps it in queue.
It is working, but I don’t have auto_increment enabled in any on of those tables (I can’t modify them, as I don’t have privilege to change the DB).
I tried in this way
lock table test write,test2 write,test3 write;
mysql> insert into test(tno) select max(tno) from test;
ERROR 1100 (HY000): Table 'test' was not locked with LOCK TABLES.
If I statically give the value for that id it is working fine. Everything else is working fine.
If this is the only way that rows are being inserted to the tables, you could try first select the new ID
max(tno), then lock the table forREADand then insert the new row. after that unlock theREAD.