scottmac Tue Jan 20 09:57:26 2009 UTC Added files: /php-src/ext/sqlite3/tests bug47159.phpt
Modified files: /php-src/ext/sqlite3 sqlite3.c Log: Fix bug #47159 - Any SQLite3 statement prepared should be added to the freelist http://cvs.php.net/viewvc.cgi/php-src/ext/sqlite3/sqlite3.c?r1=1.30&r2=1.31&diff_format=u Index: php-src/ext/sqlite3/sqlite3.c diff -u php-src/ext/sqlite3/sqlite3.c:1.30 php-src/ext/sqlite3/sqlite3.c:1.31 --- php-src/ext/sqlite3/sqlite3.c:1.30 Tue Jan 20 00:24:05 2009 +++ php-src/ext/sqlite3/sqlite3.c Tue Jan 20 09:57:25 2009 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sqlite3.c,v 1.30 2009/01/20 00:24:05 scottmac Exp $ */ +/* $Id: sqlite3.c,v 1.31 2009/01/20 09:57:25 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -384,6 +384,8 @@ 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) @@ -402,7 +404,7 @@ stmt_obj->db_obj_zval = getThis(); Z_ADDREF_P(object); - + /* Todo: utf-8 or utf-16 = sqlite3_prepare16_v2 */ errcode = sqlite3_prepare_v2(db_obj->db, sql, sql_len, &(stmt_obj->stmt), NULL); if (errcode != SQLITE_OK) { @@ -410,7 +412,14 @@ 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); } /* }}} */ @@ -1094,7 +1103,6 @@ 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); @@ -1170,11 +1178,6 @@ } 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 */ @@ -1217,6 +1220,7 @@ 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); @@ -1248,6 +1252,12 @@ 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); } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/sqlite3/tests/bug47159.phpt?view=markup&rev=1.1 Index: php-src/ext/sqlite3/tests/bug47159.phpt +++ php-src/ext/sqlite3/tests/bug47159.phpt --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'); class MyStmt extends SQLite3Stmt { } $stmt = $db->prepare("SELECT 1"); var_dump($stmt->close()); var_dump($db->close()); print "done"; ?> --EXPECT-- bool(true) bool(true) done -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php