scottmac Mon Nov 17 19:32:31 2008 UTC Modified files: /php-src/ext/sqlite3 sqlite3.c Log: Fix #46033 - Segfault when instantiating SQLite3stmt and SQLite3Result directly. http://cvs.php.net/viewvc.cgi/php-src/ext/sqlite3/sqlite3.c?r1=1.17&r2=1.18&diff_format=u Index: php-src/ext/sqlite3/sqlite3.c diff -u php-src/ext/sqlite3/sqlite3.c:1.17 php-src/ext/sqlite3/sqlite3.c:1.18 --- php-src/ext/sqlite3/sqlite3.c:1.17 Mon Nov 17 11:26:24 2008 +++ php-src/ext/sqlite3/sqlite3.c Mon Nov 17 19:32:31 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sqlite3.c,v 1.17 2008/11/17 11:26:24 felipe Exp $ */ +/* $Id: sqlite3.c,v 1.18 2008/11/17 19:32:31 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -530,7 +530,7 @@ } /* }}} */ -/* {{{ proto SQLite3Result SQLite3::querySingle(String Query [, entire_row = false]) +/* {{{ proto SQLite3Result SQLite3::querySingle(String Query [, bool entire_row = false]) Returns a string of the first column, or an array of the entire row. */ PHP_METHOD(sqlite3, querySingle) { @@ -1090,6 +1090,8 @@ return; } + SQLITE3_CHECK_INITIALIZED(stmt_obj->initialised, SQLite3) + if (stmt_obj->bound_params) { zend_hash_internal_pointer_reset(stmt_obj->bound_params); while (zend_hash_get_current_data(stmt_obj->bound_params, (void **)¶m) == SUCCESS) { @@ -1195,6 +1197,47 @@ } /* }}} */ +/* {{{ proto int SQLite3Stmt::__construct(SQLite3 dbobject, String Statement) U + __constructor for SQLite3Stmt. */ +PHP_METHOD(sqlite3stmt, __construct) +{ + php_sqlite3_stmt *stmt_obj; + php_sqlite3_db_object *db_obj; + zval *object = getThis(); + zval *db_zval; + stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC); + char *sql; + int sql_len, errcode; + + zend_replace_error_handling(EH_THROW, NULL, NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &db_zval, php_sqlite3_sc_entry, &sql, &sql_len) == FAILURE) { + return; + } + + db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(db_zval TSRMLS_CC); + + SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3) + + if (!sql_len) { + RETURN_FALSE; + } + + stmt_obj->db_obj = db_obj; + stmt_obj->db_obj_zval = db_zval; + + Z_ADDREF_P(db_zval); + + 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; +} +/* }}} */ + /* {{{ proto int SQLite3Result::numColumns() U Number of columns in the result set. */ PHP_METHOD(sqlite3result, numColumns) @@ -1356,6 +1399,21 @@ } /* }}} */ +/* {{{ proto int SQLite3Result::__construct() + __constructor for SQLite3Result. */ +PHP_METHOD(sqlite3result, __construct) +{ + php_sqlite3_result *result_obj; + zval *object = getThis(); + result_obj = (php_sqlite3_result *)zend_object_store_get_object(object TSRMLS_CC); + + zend_replace_error_handling(EH_THROW, NULL, NULL TSRMLS_CC); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "SQLite3Result cannot be directly instantiated"); + +} +/* }}} */ + /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_open, 0) ZEND_ARG_INFO(0, filename) @@ -1446,6 +1504,10 @@ ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_sqlite3stmt_construct, 1) + ZEND_ARG_INFO(0, sqlite3) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_sqlite3result_numcolumns, 0) ZEND_END_ARG_INFO() @@ -1466,6 +1528,9 @@ ZEND_BEGIN_ARG_INFO(arginfo_sqlite3result_finalize, 0) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_sqlite3result_construct, 0) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ php_sqlite3_class_methods */ @@ -1486,7 +1551,7 @@ PHP_ME(sqlite3, createFunction, arginfo_sqlite3_createfunction, ZEND_ACC_PUBLIC) PHP_ME(sqlite3, createAggregate, arginfo_sqlite3_createaggregate, ZEND_ACC_PUBLIC) /* Aliases */ - PHP_MALIAS(sqlite3, __construct, open, arginfo_sqlite3_open, ZEND_ACC_PUBLIC) + PHP_MALIAS(sqlite3, __construct, open, arginfo_sqlite3_open, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) {NULL, NULL, NULL} }; /* }}} */ @@ -1500,6 +1565,7 @@ PHP_ME(sqlite3stmt, execute, arginfo_sqlite3stmt_execute, ZEND_ACC_PUBLIC) PHP_ME(sqlite3stmt, bindParam, arginfo_sqlite3stmt_bindparam, ZEND_ACC_PUBLIC) PHP_ME(sqlite3stmt, bindValue, arginfo_sqlite3stmt_bindvalue, ZEND_ACC_PUBLIC) + PHP_ME(sqlite3stmt, __construct, arginfo_sqlite3stmt_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) {NULL, NULL, NULL} }; /* }}} */ @@ -1511,7 +1577,8 @@ PHP_ME(sqlite3result, columnType, arginfo_sqlite3result_columntype, ZEND_ACC_PUBLIC) PHP_ME(sqlite3result, fetchArray, arginfo_sqlite3result_fetcharray, ZEND_ACC_PUBLIC) PHP_ME(sqlite3result, reset, arginfo_sqlite3result_reset, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3result, finalize, arginfo_sqlite3result_finalize, ZEND_ACC_PUBLIC) + PHP_ME(sqlite3result, finalize, arginfo_sqlite3result_finalize, ZEND_ACC_PUBLIC) + PHP_ME(sqlite3result, __construct, arginfo_sqlite3result_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) {NULL, NULL, NULL} }; /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php