mardi 7 avril 2015

Setting sqlite's busy_timeout when set via PDO in PHP, not having any effect

A long running SQLITE transaction, which sleeps between begin-transaction and commit for 40 seconds to keep the database locked.



// longTrans.php
$db->beginTransaction() ;
$db->perform("insert into emails (email) values ('dsf') ");
sleep(40) ;
$epdo->commit();


Now if pragma busy_timeout=1000000 via the sqlite command line tool, followed by a insert query insert into emails (email) values ('nik.'); Then this query waits for longTrans.php to finish. This afaik is expected behaviour.


HOWEVER when the busy_timeout is set via the PHP-PDO driver, it doesn't seem to have an effect.


Code to set busy timeout via php :



$prag =$db->query('PRAGMA busy_timeout=1000000') ;
$prag = $db->->query('PRAGMA busy_timeout')->fetchAll() ;
var_dump($prag); //shows busy timeout as 1000000


Another php script which tries to insert while the longTrans.php script is active.



$query = "INSERT OR ABORT INTO note( eid ,pid , enabled) VALUES (:emailid , :p_id, '1' ) "
$st = $this->db->prepare($query) ;
$this->db->beginTransaction() ;
$st->execute($bind) ;


This instantly throws "database is locked", followed by a FATAL "'There is already an active transaction'". Basically it doesn't seem to respect the busy timeout


Both the php scripts are opening the same db file, but in different processes.


System: debian (squeeze/ vagrant) sqlite 3.8.8.3 PHP 5.3.3-7+squeeze19


Have I hit a bug ? Or Using/understanding busy_timeout incorrectly ? Any possible fixes ?


Thanks


Aucun commentaire:

Enregistrer un commentaire