SQLite transaction doesn't work as expected

Posted by troll on Stack Overflow See other posts from Stack Overflow or by troll
Published on 2009-02-19T07:37:42Z Indexed on 2010/04/13 0:02 UTC
Read the original article Hit count: 283

Filed under:
|
|
|

I prepared 2 files, "1.php" and "2.php".

"1.php" is like this.

<?php
$dbh = new PDO('sqlite:test1');
$dbh->beginTransaction();

print "aaa<br>";
sleep(55);
$dbh->commit();

print "bbb";
?>

and "2.php" is like this.

<?php
$dbh = new PDO('sqlite:test1');
$dbh->beginTransaction();

print "ccc<br>";
$dbh->commit();
print "ddd";
?>

and I excute "1.php". It starts a transaction and waits 55 seconds.

So when I immediately excute "2.php", my expectation is this:

  1. "1.php" is getting transaction and
  2. "1" holds a database lock
  3. "2" can not begin a transaction
  4. "2" can not get database lock so
  5. "2" have to wait 55 seconds

BUT, but the test went another way. When I excute "2",then

  1. "2" immediately returned it's result
  2. "2" did not wait

so I have to think that "1" could not get transaction, or could not get database lock.

Can anyone help?

© Stack Overflow or respective owner

Related posts about sqlite

Related posts about transaction