Skip to content

Commit 5794060

Browse files
committed
Fix #70628: Clearing bindings on an SQLite3 statement doesn't work
Obiously, it isn't sufficient to call sqlite3_clear_bindings() alone, but also the bound_params of the php_sqlite3_stmt have to be cleared.
1 parent b4873e5 commit 5794060

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,12 @@ PHP_METHOD(sqlite3stmt, clear)
13761376
RETURN_FALSE;
13771377
}
13781378

1379+
if (stmt_obj->bound_params) {
1380+
zend_hash_destroy(stmt_obj->bound_params);
1381+
FREE_HASHTABLE(stmt_obj->bound_params);
1382+
stmt_obj->bound_params = NULL;
1383+
}
1384+
13791385
RETURN_TRUE;
13801386
}
13811387
/* }}} */

ext/sqlite3/tests/bug70628.phpt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
Bug #70628 (Clearing bindings on an SQLite3 statement doesn't work)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('sqlite3')) die('skip'); ?>
6+
--FILE--
7+
<?php
8+
$db = new SQLite3(':memory:');
9+
10+
$db->exec("CREATE TABLE Dogs (Id INTEGER PRIMARY KEY, Breed TEXT, Name TEXT, Age INTEGER)");
11+
12+
$sth = $db->prepare("INSERT INTO Dogs (Breed, Name, Age) VALUES (:breed,:name,:age)");
13+
14+
$sth->bindValue(':breed', 'canis', SQLITE3_TEXT);
15+
$sth->bindValue(':name', 'jack', SQLITE3_TEXT);
16+
$sth->bindValue(':age', 7, SQLITE3_INTEGER);
17+
$sth->execute();
18+
19+
$sth->clear();
20+
$sth->reset();
21+
22+
$sth->bindValue(':breed', 'russel', SQLITE3_TEXT);
23+
$sth->bindValue(':age', 3, SQLITE3_INTEGER);
24+
$sth->execute();
25+
26+
$res = $db->query('SELECT * FROM Dogs');
27+
while (($row = $res->fetchArray(SQLITE3_ASSOC))) {
28+
var_dump($row);
29+
}
30+
$res->finalize();
31+
32+
$sth->close();
33+
$db->close();
34+
?>
35+
--EXPECT--
36+
array(4) {
37+
["Id"]=>
38+
int(1)
39+
["Breed"]=>
40+
string(5) "canis"
41+
["Name"]=>
42+
string(4) "jack"
43+
["Age"]=>
44+
int(7)
45+
}
46+
array(4) {
47+
["Id"]=>
48+
int(2)
49+
["Breed"]=>
50+
string(6) "russel"
51+
["Name"]=>
52+
NULL
53+
["Age"]=>
54+
int(3)
55+
}

0 commit comments

Comments
 (0)