Fix #73530: Unsetting result set may reset other result set

Calling sqlite3_reset() when a result set object is freed can cause
undesired and maybe even hard to track interference with other result
sets. Furthermore, there is no need to call sqlite3_reset(), because
that is implicitly called on SQLite3Stmt::execute(), and users are
encouraged to explicitly call either SQLite3Result::finalize() or
SQLite3Stmt::reset() anyway.
This commit is contained in:
Christoph M. Becker 2016-11-16 11:49:04 +01:00
parent ecba563f2f
commit eb570294a2
3 changed files with 35 additions and 4 deletions

3
NEWS
View File

@ -11,6 +11,9 @@ PHP NEWS
. Fixed bug #72776 (Invalid parameter in memcpy function trough
openssl_pbkdf2). (Jakub Zelenka)
- SQLite3:
. Fixed bug #73530 (Unsetting result set may reset other result set). (cmb)
10 Nov 2016, PHP 5.6.28
- Core:

View File

@ -2184,10 +2184,6 @@ static void php_sqlite3_result_object_free_storage(void *object TSRMLS_DC) /* {{
}
if (intern->stmt_obj_zval) {
if (intern->stmt_obj->initialised) {
sqlite3_reset(intern->stmt_obj->stmt);
}
if (intern->is_prepared_statement == 0) {
zval_dtor(intern->stmt_obj_zval);
FREE_ZVAL(intern->stmt_obj_zval);

View File

@ -0,0 +1,32 @@
--TEST--
Bug #73530 (Unsetting result set may reset other result set)
--SKIPIF--
<?php
if (!extension_loaded('sqlite3')) die('skip sqlite3 extension not available');
?>
--FILE--
<?php
$db = new SQLite3(':memory:');
$db->exec("CREATE TABLE foo (num int)");
$db->exec("INSERT INTO foo VALUES (0)");
$db->exec("INSERT INTO foo VALUES (1)");
$stmt = $db->prepare("SELECT * FROM foo WHERE NUM = ?");
$stmt->bindValue(1, 0, SQLITE3_INTEGER);
$res1 = $stmt->execute();
$res1->finalize();
$stmt->clear();
$stmt->reset();
$stmt->bindValue(1, 1, SQLITE3_INTEGER);
$res2 = $stmt->execute();
while ($row = $res2->fetchArray(SQLITE3_ASSOC)) {
var_dump($row);
unset($res1);
}
?>
===DONE===
--EXPECT--
array(1) {
["num"]=>
int(1)
}
===DONE===