php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29476 sqlite_fetch_column_types locks the database forever
Submitted: 2004-08-01 00:50 UTC Modified: 2006-04-18 14:30 UTC
Votes:22
Avg. Score:4.5 ± 0.7
Reproduced:18 of 18 (100.0%)
Same Version:7 (38.9%)
Same OS:11 (61.1%)
From: hugo_pl at users dot sourceforge dot net Assigned: iliaa (profile)
Status: Closed Package: SQLite related
PHP Version: 5.1.3RC3 OS: *
Private report: No CVE-ID: None
 [2004-08-01 00:50 UTC] hugo_pl at users dot sourceforge dot net
Description:
------------
When I call the function:
sqlite_fetch_column_types(...);

or the method:

fetchColumnTypes(...);

of the SQLiteDatabase Object, the entire database is locked forever... and I cant modify the database until Apache is restarted.

I tested this with Apache2 SAPI module, and SQLite version 2.8.14 on win32 and 2.8.13 and 2.8.14 on Linux.

In all plataforms, the database is unlocked only when I restart Apache, if I never call sqlite_fetch_column_types or the method fetchColumnTypes, all runs Ok.

P.S.: English is not my natural language.

Reproduce code:
---------------
<?php
// Open a database file...
$db = sqlite_open('test.db');
sqlite_busy_timeout($db, 1000);

//! Uncomment this line to see the bug!!
//sqlite_fetch_column_types($db, 'papers');

sqlite_query($db, 'select * from papers limit 10');

// Any Update query and kabbom... =/
sqlite_query($db, 'update papers set papel="Hi" where id=1');
sqlite_close($db);

?>

Expected result:
----------------
No warnings about a locked database when I send the update query

Actual result:
--------------
Warning:  sqlite_query() [function.sqlite-query]: database is locked...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-25 06:56 UTC] hugo_pl at users dot sourceforge dot net
Hi 
 
I think that this is a PHP bug, I made a better exemple to 
show this bug: 
 
<pre> 
<?php 
 
try { 
	$db = new SQLiteDatabase('./test.db'); 
	$db->busyTimeout(1000); 
	 
	// table exists? 
	$exists = $db->singleQuery('SELECT count(*) FROM 
sqlite_master WHERE tbl_name=\'bugtest\''); 
	if (!$exists) 
		$db->query('CREATE TABLE bugtest (a, b, c, 
d);'); 
	 
	// Without this line all runs Ok. 
	$db->fetchColumnTypes('bugtest'); 
 
	$db->query('INSERT INTO bugtest VALUES (1, 2, 3, 
4)'); 
	 
	 
	echo 'Res: <br>'; 
	print_r( $db->arrayQuery('SELECT * FROM bugtest', 
SQLITE_ASSOC) ); 
} 
catch (Exception $e) 
{ 
	echo 'Exception: ', $e->getMessage(); 
} 
 
 
?> 
 
The first time you run this script all appear to be Ok... 
the insert query is executed, etc... but the second time 
is displayed a message:  
 
Warning:  SQLiteDatabase::query() [function.query]: 
database is locked in /home/hugo/public_html/phpbug.php on 
line 16 
 
Nothing is wrong with the script, if this message appear 
something is wrong with PHP.... on windows the same bug 
occur, then it is not a problem from SQLite or Apache 
compiled by me under linux.
 [2005-03-06 22:09 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-11-18 16:07 UTC] jwellis at carlalbert dot edu
This is still a problem in PHP 5.1.0RC5-dev.

here is my reproduction code:

----------------------------
$database_path = "sqlite_db1";
$db = new SQLiteDatabase($database_path);
//  sqlite_db1 has a table called t1 with the colums id (int) and stuff (text)  //

$db->query("INSERT INTO t1 (stuff) VALUES ('something');", SQLITE_NUM, $db_error);
print $db->changes() ." rows affected<br>\n";

//-----//  This is the part that breaks it  //-----//
$table_cols = $db->fetchColumnTypes("t1", SQLITE_ASSOC); 
foreach($table_cols as $col => $type) {
	print"\t$col: $type<br>\n";
}
//-------------------------------------------------//

$db->query("INSERT INTO t1 (stuff) VALUES ('something');", SQLITE_NUM, $db_error);
print $db->changes() ." rows affected<br>\n";
 [2006-04-09 00:10 UTC] nforbes@php.net
Same error with 5.1.2 (release). However, on 5.1.3-dev, 
the script simply hangs. Tested using the above, posted by 
jwellis.
 [2006-04-11 11:52 UTC] sniper@php.net
Assigned to sqlite guru Ilia.
 [2006-04-18 14:30 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC