summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott MacVicar <scottmac@php.net>2009-01-20 09:57:34 +0000
committerScott MacVicar <scottmac@php.net>2009-01-20 09:57:34 +0000
commit5b79c375009b4aac5ae69c49746f5006092497c9 (patch)
tree1c6592437048f53371c038635235207c7538546e
parentb0c1d09cda82d9d57eaebda5a2ab061f8f283ccd (diff)
downloadphp-git-5b79c375009b4aac5ae69c49746f5006092497c9.tar.gz
MFH Fix bug #47159 - Any SQLite3 statement prepared should be added to the freelist
-rw-r--r--ext/sqlite3/sqlite3.c24
-rw-r--r--ext/sqlite3/tests/bug47159.phpt22
2 files changed, 39 insertions, 7 deletions
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index cede5c82df..4a194059a8 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -370,6 +370,8 @@ PHP_METHOD(sqlite3, prepare)
zval *object = getThis();
char *sql;
int sql_len, errcode;
+ php_sqlite3_free_list *free_item;
+
db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(object TSRMLS_CC);
SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3)
@@ -388,14 +390,21 @@ PHP_METHOD(sqlite3, prepare)
stmt_obj->db_obj_zval = getThis();
Z_ADDREF_P(object);
-
+
errcode = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &(stmt_obj->stmt), NULL);
if (errcode != SQLITE_OK) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to prepare statement: %d, %s", errcode, sqlite3_errmsg(db_obj->db));
zval_dtor(return_value);
RETURN_FALSE;
}
+
stmt_obj->initialised = 1;
+
+ free_item = emalloc(sizeof(php_sqlite3_free_list));
+ free_item->stmt_obj = stmt_obj;
+ free_item->stmt_obj_zval = return_value;
+
+ zend_llist_add_element(&(db_obj->free_list), &free_item);
}
/* }}} */
@@ -1067,7 +1076,6 @@ PHP_METHOD(sqlite3stmt, execute)
zval *object = getThis();
int return_code = 0;
struct php_sqlite3_bound_param *param;
- php_sqlite3_free_list *free_item;
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
@@ -1142,11 +1150,6 @@ PHP_METHOD(sqlite3stmt, execute)
}
return_code = sqlite3_step(stmt_obj->stmt);
- free_item = emalloc(sizeof(php_sqlite3_free_list));
- free_item->stmt_obj = stmt_obj;
- free_item->stmt_obj_zval = getThis();
-
- zend_llist_add_element(&(stmt_obj->db_obj->free_list), &free_item);
switch (return_code) {
case SQLITE_ROW: /* Valid Row */
@@ -1189,6 +1192,7 @@ PHP_METHOD(sqlite3stmt, __construct)
char *sql;
int sql_len, errcode;
zend_error_handling error_handling;
+ php_sqlite3_free_list *free_item;
stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
@@ -1220,6 +1224,12 @@ PHP_METHOD(sqlite3stmt, __construct)
RETURN_FALSE;
}
stmt_obj->initialised = 1;
+
+ free_item = emalloc(sizeof(php_sqlite3_free_list));
+ free_item->stmt_obj = stmt_obj;
+ free_item->stmt_obj_zval = getThis();
+
+ zend_llist_add_element(&(db_obj->free_list), &free_item);
}
/* }}} */
diff --git a/ext/sqlite3/tests/bug47159.phpt b/ext/sqlite3/tests/bug47159.phpt
new file mode 100644
index 0000000000..f8ffa289f5
--- /dev/null
+++ b/ext/sqlite3/tests/bug47159.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #45798 (sqlite3 doesn't track unexecuted statements)
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__) . '/new_db.inc');
+
+$stmt = $db->prepare("SELECT 1");
+
+var_dump($stmt->close());
+
+var_dump($db->close());
+
+print "done";
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+done