Re: Checking for entry in table?
Rudy Lippan <[email protected]>
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 29 Mar 2005, Garry Williams wrote:
> My suggestion is to just insert the row you care about without checking
> to see if it is there. If it is already in the table, the insert will
> fail on duplicate key (assuming that you have some column(s) defined as
> unique or primary key). The failure will produce $sth->err() == 1062,
> if the insert is a duplicate. Otherwise, you have your record inserted.
Of course some DBs will abort a transaction in the event of a failed insert
because of the way the SQL spec is written.
> record. You cannot guarantee winning the race.
$dbh->do(q{LOCK TABLE foo})
...
or
$dbh->{AutoCommit} = 0; # use transactions
$dbh->do(q{SET TRANSACTION ISOLATION LEVEL SERALIZABLE}); # paranoid
...
-r
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/[email protected]