I've read the DBI documentation on CPAN and ordered "Programming the Perl DBI" but haven't received it yet. My Perl skills are mediocre so I'm looking for some suggestions
I'm making a database app with MySQL and there are many tables with foreign key references. I'm using InnoDB tables that support transactions.
Say I have some tables called "People", "Address", and "LivesAt". "People" to "Address" is a many to many relationship and "LivesAt" has the foreign keys of "People" and "Address".
So what I'm planning on doing is to add a person to "People" and call "$rv = $dbh->last_insert_id;" to get the persons primary key to use as the foreign key in "LivesAt".
But say I add a person to the database then someone else milliseconds later adds another person to the database, and then I execute "$rv = $dbh->last_insert_id;", would that give me not my insert_id but the other persons insert_id? If this would give me an improper insert_id then I'll use transactions.
This may be far fetched, but I've looked all over and haven't seen any answers.
Is there any other way to update multiple tables that have related foreign/primary keys and keep the foreign keys consistent besides doing an update, then getting the "last_insert_id" and using that as the foreign key for related tables?In the "Perl Cookbook 2nd Edition" it says you can do "inserts, updates, deletes, queries here" on page 573 in the eval statement.
Does this mean you can do SELECT statements while in the middle of a transaction? I'd like to do this to get the foreign key values for my new INSERTS.
Summary of Questions:
1. Say I add a person to the database then someone else milliseconds later adds another person to the database, and then I execute "$rv = $dbh->last_insert_id;", would that give me not my insert_id but the other persons insert_id from their insert?
2. Is there any other way to update multiple tables that have related foreign/primary keys and keep the foreign keys consistent besides doing an update, then getting the "last_insert_id" and using that as the foreign key for related tables?
3. Can I do SELECT statements while in the middle of a transaction?