Multiple statement handles, placeholders, and autoincrement

Multiple statement handles, placeholders, and autoincrement

am 29.06.2002 01:50:07 von David Adam

--------------A678E3DC47F20BEACF1E3A29
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi, I'm using perl 5.6.1, Mysql 3.23.49, and Redhat Linux 7.2,
converting a flat-field database of pathological design into a
relational version. I need to insert into several tables, over and
over, and would thus like to use multiple statement handles ($stha,
$sthb, etc.) so that I can create each statement with placeholders and
avoid some overhead.
One of the tasks involves inserting an autoincrement Sample ID field
into one table, and then getting the assigned Sample ID back immediately
so I can use it in a subsequent insert into another table. I couldn't
get LAST_INSERT_ID to work for me (probably because I was asking for
the answer on a different statement handle than the one used to insert),
so I tried a query asking for the sample ID I had just inserted, using a
secondary key.
Sometimes it seems to work, but my program hangs with an uninitialized
value for my retrieved Sample ID sooner or later (usually pretty soon).
So I have a QUESTION:
Can a short query #2 on connection B (the retrieval) get ahead of a
longer query #2 on connection A (the autoincrement insertion), so that I
can't get the autoincremented value back reliably? If so, is there a
tidy way around the problem, or do I have to resort to using one
statement handle, and then recreating each query each time I need it?
What I appear to need is just the opposite of INSERT DELAYED -- some
sort of SELECT DELAYED that waits for the previous insert to complete
before executing.
Any insights will be much appreciated!

--
David Adam
Quaternary Geologist
Lake County, California



--------------A678E3DC47F20BEACF1E3A29--