sdyates has asked for the wisdom of the Perl Monks concerning the following question:
Well, I made this great little application that writes to and updates a table in MySQL, but now I have more than one user making updates, and while I feel that the chance of a corruption is slim, I want to be able to lock the table for all other users(threads), write the information to the DB, then unlock the tables.
I am using DBD::mysql. Below is an sample of the code I used to write to the DB:
my $sth = $dbh->prepare("$SQLCommand") or err_trap("Cannot prepare the + load_category_names query"); $sth->execute or err_trap("Cannot execute the SQL query to SQL COMMAND +");
Simple stuff! Yet if I copy these lines above and use LOCK TABLES table read, I cannot write as I am locking all data.
I understand I have a two part issue here:
1) proper perl syntax to write to the database three times
a. lock tables
b. execute my sql command
c. unlock talbes
2) Determining the proper syntax of the lock and unlock to get me where I need to be.
For Perl, do I just copy the two lines of code, replace $SQLCommand with appropriate lock statement. Use the same two lines of code to write my SQLCommand. Then, use the same two lines of code replacing $SQLCommand again with UNLOCK TABLES?
Also if any one has some sample SQL lines on locking procedures *I know this is not a MySQ site, but what the heck, it is related. Thanks folks.
Edited: Sun Oct 14 07:11:57 2001, footpad - Added/Corrected <P> tags and removed repeated paragraphs.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LOCK TABLES using Perl in MySQL
by greywolf (Priest) on Oct 13, 2001 at 01:29 UTC | |
|
Re: LOCK TABLES using Perl in MySQL
by merlyn (Sage) on Oct 13, 2001 at 01:38 UTC | |
by mischief (Hermit) on Oct 13, 2001 at 17:27 UTC | |
by merlyn (Sage) on Oct 13, 2001 at 19:42 UTC | |
|
Re: LOCK TABLES using Perl in MySQL
by George_Sherston (Vicar) on Oct 13, 2001 at 01:37 UTC | |
by sdyates (Scribe) on Jan 03, 2002 at 02:33 UTC | |
|
Re: LOCK TABLES using Perl in MySQL
by George_Sherston (Vicar) on Oct 13, 2001 at 01:53 UTC |