List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 12 2001 9:47pm
Subject:Re: last_insert_id() issue w/ DBI
View as plain text  
At 4:34 PM -0500 6/12/01, Erik Rantapaa wrote:
>This really might be a DBI problem, but I find it's pretty weird.
>
>I am attempting to perform atomic updates by using UPDATE statements
>like:
>
>	UPDATE counter SET v = last_insert_id(v+1) WHERE k = 'xxx';
>
>where counter has the schema: create table counter (k varchar(16) 
>primary key, v int);
>
>This works flawlessly through DBI when accessing a local database.
>However, when accessing a remote database it sometimes fails. I can get
>it to fail more often when I have multiple processes banging away at
>the database with this same statement.
>
>The exact failure is:
>
>	$sth = $dbh->prepare("UPDATE ... WHERE k = ?") succeeds
>	$sth->execute("xxx") succeeds
>	$sth->{mysql_insertid} is undefined

Try using:

$dbh->do ("UPDATE ... WHERE k = ?", undef, "xxx")
and then access $dbh->{mysql_insertid} to see if you get a different
result.  I suspect perhaps not, but it's something to try.

>
>I've written a C program to test this query, and I can't get it to fail,
>even with multiple concurrent queries running.
>
>Has anyone seen this problem before?
>
>Erik Rantapaa
>rantapaa@stripped


-- 
Paul DuBois, paul@stripped
Thread
last_insert_id() issue w/ DBIErik Rantapaa12 Jun
  • Re: last_insert_id() issue w/ DBIPaul DuBois12 Jun
    • Re: last_insert_id() issue w/ DBIErik Rantapaa13 Jun