diff options
Diffstat (limited to 'ext/sqlite3')
51 files changed, 1035 insertions, 667 deletions
diff --git a/ext/sqlite3/php_sqlite3.h b/ext/sqlite3/php_sqlite3.h index ca09e341ab..9dff343f90 100644 --- a/ext/sqlite3/php_sqlite3.h +++ b/ext/sqlite3/php_sqlite3.h @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index 3de8aac0d4..80e915da68 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -73,6 +71,8 @@ typedef struct _php_sqlite3_db_object { sqlite3 *db; php_sqlite3_func *funcs; php_sqlite3_collation *collations; + zend_fcall_info authorizer_fci; + zend_fcall_info_cache authorizer_fcc; zend_bool exception; @@ -108,7 +108,6 @@ struct _php_sqlite3_result_object { zval stmt_obj_zval; int is_prepared_statement; - int complete; // unused zend_object zo; }; diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index f4d8066ac8..cd91e68fd3 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -25,6 +23,7 @@ #include "ext/standard/info.h" #include "php_sqlite3.h" #include "php_sqlite3_structs.h" +#include "sqlite3_arginfo.h" #include "main/SAPI.h" #include <sqlite3.h> @@ -36,12 +35,11 @@ ZEND_DECLARE_MODULE_GLOBALS(sqlite3) static PHP_GINIT_FUNCTION(sqlite3); -static int php_sqlite3_authorizer(void *autharg, int access_type, const char *arg3, const char *arg4, const char *arg5, const char *arg6); +static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, const char *arg2, const char *arg3, const char *arg4); static void sqlite3_param_dtor(zval *data); static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_free_list **free_list, zval *statement); -/* {{{ Error Handler -*/ +/* {{{ Error Handler */ static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...) { va_list arg; @@ -65,22 +63,21 @@ static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...) #define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \ if (!(db_obj) || !(member)) { \ - php_sqlite3_error(db_obj, "The " #class_name " object has not been correctly initialised"); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \ + RETURN_THROWS(); \ } #define SQLITE3_CHECK_INITIALIZED_STMT(member, class_name) \ if (!(member)) { \ - php_error_docref(NULL, E_WARNING, "The " #class_name " object has not been correctly initialised"); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \ + RETURN_THROWS(); \ } -/* {{{ PHP_INI -*/ +/* {{{ PHP_INI */ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("sqlite3.extension_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, extension_dir, zend_sqlite3_globals, sqlite3_globals) #if SQLITE_VERSION_NUMBER >= 3026000 - STD_PHP_INI_ENTRY("sqlite3.defensive", "1", PHP_INI_SYSTEM, OnUpdateBool, dbconfig_defensive, zend_sqlite3_globals, sqlite3_globals) + STD_PHP_INI_BOOLEAN("sqlite3.defensive", "1", PHP_INI_SYSTEM, OnUpdateBool, dbconfig_defensive, zend_sqlite3_globals, sqlite3_globals) #endif PHP_INI_END() /* }}} */ @@ -95,9 +92,8 @@ zend_class_entry *php_sqlite3_sc_entry; zend_class_entry *php_sqlite3_stmt_entry; zend_class_entry *php_sqlite3_result_entry; -/* {{{ proto void SQLite3::open(String filename [, int Flags [, string Encryption Key]]) - Opens a SQLite 3 Database, if the build includes encryption then it will attempt to use the key. */ -PHP_METHOD(sqlite3, open) +/* {{{ Opens a SQLite 3 Database, if the build includes encryption then it will attempt to use the key. */ +PHP_METHOD(SQLite3, open) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -108,26 +104,26 @@ PHP_METHOD(sqlite3, open) db_obj = Z_SQLITE3_DB_P(object); - if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|ls", &filename, &filename_len, &flags, &encryption_key, &encryption_key_len)) { - return; + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "p|ls", &filename, &filename_len, &flags, &encryption_key, &encryption_key_len)) { + RETURN_THROWS(); } if (db_obj->initialised) { zend_throw_exception(zend_ce_exception, "Already initialised DB Object", 0); - return; + RETURN_THROWS(); } if (filename_len != 0 && (filename_len != sizeof(":memory:")-1 || memcmp(filename, ":memory:", sizeof(":memory:")-1) != 0)) { if (!(fullpath = expand_filepath(filename, NULL))) { zend_throw_exception(zend_ce_exception, "Unable to expand filepath", 0); - return; + RETURN_THROWS(); } if (php_check_open_basedir(fullpath)) { zend_throw_exception_ex(zend_ce_exception, 0, "open_basedir prohibits opening %s", fullpath); efree(fullpath); - return; + RETURN_THROWS(); } } else { /* filename equals "" or ":memory:" */ @@ -149,21 +145,21 @@ PHP_METHOD(sqlite3, open) return; } -#if SQLITE_HAS_CODEC +#ifdef SQLITE_HAS_CODEC if (encryption_key_len > 0) { if (sqlite3_key(db_obj->db, encryption_key, encryption_key_len) != SQLITE_OK) { zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db)); sqlite3_close(db_obj->db); - return; + RETURN_THROWS(); } } #endif db_obj->initialised = 1; + db_obj->authorizer_fci = empty_fcall_info; + db_obj->authorizer_fcc = empty_fcall_info_cache; - if (PG(open_basedir) && *PG(open_basedir)) { - sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, NULL); - } + sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, db_obj); #if SQLITE_VERSION_NUMBER >= 3026000 if (SQLITE3G(dbconfig_defensive)) { @@ -177,9 +173,8 @@ PHP_METHOD(sqlite3, open) } /* }}} */ -/* {{{ proto bool SQLite3::close() - Close a SQLite 3 Database. */ -PHP_METHOD(sqlite3, close) +/* {{{ Close a SQLite 3 Database. */ +PHP_METHOD(SQLite3, close) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -187,7 +182,7 @@ PHP_METHOD(sqlite3, close) db_obj = Z_SQLITE3_DB_P(object); if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } if (db_obj->initialised) { @@ -206,9 +201,8 @@ PHP_METHOD(sqlite3, close) } /* }}} */ -/* {{{ proto bool SQLite3::exec(String Query) - Executes a result-less query against a given database. */ -PHP_METHOD(sqlite3, exec) +/* {{{ Executes a result-less query against a given database. */ +PHP_METHOD(SQLite3, exec) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -216,12 +210,12 @@ PHP_METHOD(sqlite3, exec) char *errtext = NULL; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "S", &sql)) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + if (sqlite3_exec(db_obj->db, ZSTR_VAL(sql), NULL, NULL, &errtext) != SQLITE_OK) { php_sqlite3_error(db_obj, "%s", errtext); sqlite3_free(errtext); @@ -232,12 +226,11 @@ PHP_METHOD(sqlite3, exec) } /* }}} */ -/* {{{ proto Array SQLite3::version() - Returns the SQLite3 Library version as a string constant and as a number. */ -PHP_METHOD(sqlite3, version) +/* {{{ Returns the SQLite3 Library version as a string constant and as a number. */ +PHP_METHOD(SQLite3, version) { if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } array_init(return_value); @@ -249,38 +242,36 @@ PHP_METHOD(sqlite3, version) } /* }}} */ -/* {{{ proto int SQLite3::lastInsertRowID() - Returns the rowid of the most recent INSERT into the database from the database connection. */ -PHP_METHOD(sqlite3, lastInsertRowID) +/* {{{ Returns the rowid of the most recent INSERT into the database from the database connection. */ +PHP_METHOD(SQLite3, lastInsertRowID) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + RETURN_LONG((zend_long) sqlite3_last_insert_rowid(db_obj->db)); } /* }}} */ -/* {{{ proto int SQLite3::lastErrorCode() - Returns the numeric result code of the most recent failed sqlite API call for the database connection. */ -PHP_METHOD(sqlite3, lastErrorCode) +/* {{{ Returns the numeric result code of the most recent failed sqlite API call for the database connection. */ +PHP_METHOD(SQLite3, lastErrorCode) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) + if (db_obj->initialised) { RETURN_LONG(sqlite3_errcode(db_obj->db)); } else { @@ -289,20 +280,19 @@ PHP_METHOD(sqlite3, lastErrorCode) } /* }}} */ -/* {{{ proto int SQLite3::lastExtendedErrorCode() - Returns the numeric extended result code of the most recent failed sqlite API call for the database connection. */ -PHP_METHOD(sqlite3, lastExtendedErrorCode) +/* {{{ Returns the numeric extended result code of the most recent failed sqlite API call for the database connection. */ +PHP_METHOD(SQLite3, lastExtendedErrorCode) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) + if (db_obj->initialised) { RETURN_LONG(sqlite3_extended_errcode(db_obj->db)); } else { @@ -311,9 +301,8 @@ PHP_METHOD(sqlite3, lastExtendedErrorCode) } /* }}} */ -/* {{{ proto bool SQLite3::enableExtendedResultCodes([bool enable = true]) - Turns on or off the extended result codes feature of SQLite. */ -PHP_METHOD(sqlite3, enableExtendedResultCodes) +/* {{{ Turns on or off the extended result codes feature of SQLite. */ +PHP_METHOD(SQLite3, enableExtendedResultCodes) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -321,12 +310,12 @@ PHP_METHOD(sqlite3, enableExtendedResultCodes) db_obj = Z_SQLITE3_DB_P(object); int ret; - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &enable) == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) + if (db_obj->initialised) { ret = sqlite3_extended_result_codes(db_obj->db, enable ? 1 : 0); if (ret == SQLITE_OK) @@ -339,20 +328,19 @@ PHP_METHOD(sqlite3, enableExtendedResultCodes) } /* }}} */ -/* {{{ proto string SQLite3::lastErrorMsg() - Returns english text describing the most recent failed sqlite API call for the database connection. */ -PHP_METHOD(sqlite3, lastErrorMsg) +/* {{{ Returns english text describing the most recent failed sqlite API call for the database connection. */ +PHP_METHOD(SQLite3, lastErrorMsg) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->db, SQLite3) + if (db_obj->initialised) { RETURN_STRING((char *)sqlite3_errmsg(db_obj->db)); } else { @@ -361,9 +349,8 @@ PHP_METHOD(sqlite3, lastErrorMsg) } /* }}} */ -/* {{{ proto bool SQLite3::busyTimeout(int msecs) - Sets a busy handler that will sleep until database is not locked or timeout is reached. Passing a value less than or equal to zero turns off all busy handlers. */ -PHP_METHOD(sqlite3, busyTimeout) +/* {{{ Sets a busy handler that will sleep until database is not locked or timeout is reached. Passing a value less than or equal to zero turns off all busy handlers. */ +PHP_METHOD(SQLite3, busyTimeout) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -373,12 +360,12 @@ PHP_METHOD(sqlite3, busyTimeout) #endif db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ms)) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + #ifdef SQLITE_ENABLE_API_ARMOR return_code = sqlite3_busy_timeout(db_obj->db, ms); if (return_code != SQLITE_OK) { @@ -395,9 +382,8 @@ PHP_METHOD(sqlite3, busyTimeout) #ifndef SQLITE_OMIT_LOAD_EXTENSION -/* {{{ proto bool SQLite3::loadExtension(String Shared Library) - Attempts to load an SQLite extension library. */ -PHP_METHOD(sqlite3, loadExtension) +/* {{{ Attempts to load an SQLite extension library. */ +PHP_METHOD(SQLite3, loadExtension) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -406,12 +392,12 @@ PHP_METHOD(sqlite3, loadExtension) size_t extension_len, extension_dir_len; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &extension, &extension_len)) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + #ifdef ZTS if ((strncmp(sapi_module.name, "cgi", 3) != 0) && (strcmp(sapi_module.name, "cli") != 0) && @@ -468,33 +454,31 @@ PHP_METHOD(sqlite3, loadExtension) /* }}} */ #endif -/* {{{ proto int SQLite3::changes() - Returns the number of database rows that were changed (or inserted or deleted) by the most recent SQL statement. */ -PHP_METHOD(sqlite3, changes) +/* {{{ Returns the number of database rows that were changed (or inserted or deleted) by the most recent SQL statement. */ +PHP_METHOD(SQLite3, changes) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + RETURN_LONG(sqlite3_changes(db_obj->db)); } /* }}} */ -/* {{{ proto String SQLite3::escapeString(String value) - Returns a string that has been properly escaped. */ -PHP_METHOD(sqlite3, escapeString) +/* {{{ Returns a string that has been properly escaped. */ +PHP_METHOD(SQLite3, escapeString) { zend_string *sql; char *ret; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "S", &sql)) { - return; + RETURN_THROWS(); } if (ZSTR_LEN(sql)) { @@ -509,9 +493,8 @@ PHP_METHOD(sqlite3, escapeString) } /* }}} */ -/* {{{ proto SQLite3Stmt SQLite3::prepare(String Query) - Returns a prepared SQL statement for execution. */ -PHP_METHOD(sqlite3, prepare) +/* {{{ Returns a prepared SQL statement for execution. */ +PHP_METHOD(SQLite3, prepare) { php_sqlite3_db_object *db_obj; php_sqlite3_stmt *stmt_obj; @@ -522,12 +505,12 @@ PHP_METHOD(sqlite3, prepare) db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "S", &sql)) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + if (!ZSTR_LEN(sql)) { RETURN_FALSE; } @@ -535,8 +518,7 @@ PHP_METHOD(sqlite3, prepare) object_init_ex(return_value, php_sqlite3_stmt_entry); stmt_obj = Z_SQLITE3_STMT_P(return_value); stmt_obj->db_obj = db_obj; - Z_ADDREF_P(object); - ZVAL_OBJ(&stmt_obj->db_obj_zval, Z_OBJ_P(object)); + ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(object)); errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (errcode != SQLITE_OK) { @@ -555,9 +537,8 @@ PHP_METHOD(sqlite3, prepare) } /* }}} */ -/* {{{ proto SQLite3Result SQLite3::query(String Query) - Returns true or false, for queries that return data it will return a SQLite3Result object. */ -PHP_METHOD(sqlite3, query) +/* {{{ Returns true or false, for queries that return data it will return a SQLite3Result object. */ +PHP_METHOD(SQLite3, query) { php_sqlite3_db_object *db_obj; php_sqlite3_result *result; @@ -569,12 +550,12 @@ PHP_METHOD(sqlite3, query) int return_code; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "S", &sql)) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + if (!ZSTR_LEN(sql)) { RETURN_FALSE; } @@ -591,8 +572,7 @@ PHP_METHOD(sqlite3, query) object_init_ex(&stmt, php_sqlite3_stmt_entry); stmt_obj = Z_SQLITE3_STMT_P(&stmt); stmt_obj->db_obj = db_obj; - Z_ADDREF_P(object); - ZVAL_OBJ(&stmt_obj->db_obj_zval, Z_OBJ_P(object)); + ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(object)); return_code = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (return_code != SQLITE_OK) { @@ -672,9 +652,8 @@ static void sqlite_value_to_zval(sqlite3_stmt *stmt, int column, zval *data) /* } /* }}} */ -/* {{{ 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) +/* {{{ Returns a string of the first column, or an array of the entire row. */ +PHP_METHOD(SQLite3, querySingle) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -685,12 +664,12 @@ PHP_METHOD(sqlite3, querySingle) sqlite3_stmt *stmt; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &sql, &entire_row)) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + if (!ZSTR_LEN(sql)) { RETURN_FALSE; } @@ -965,34 +944,27 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in } /* }}} */ -/* {{{ proto bool SQLite3::createFunction(string name, mixed callback [, int argcount, int flags]) - Allows registration of a PHP function as a SQLite UDF that can be called within SQL statements. */ -PHP_METHOD(sqlite3, createFunction) +/* {{{ Allows registration of a PHP function as a SQLite UDF that can be called within SQL statements. */ +PHP_METHOD(SQLite3, createFunction) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; php_sqlite3_func *func; char *sql_func; size_t sql_func_len; - zval *callback_func; + zend_fcall_info fci; + zend_fcall_info_cache fcc; zend_long sql_func_num_args = -1; zend_long flags = 0; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz|ll", &sql_func, &sql_func_len, &callback_func, &sql_func_num_args, &flags) == FAILURE) { - return; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sf|ll", &sql_func, &sql_func_len, &fci, &fcc, &sql_func_num_args, &flags) == FAILURE) { + RETURN_THROWS(); } - if (!sql_func_len) { - RETURN_FALSE; - } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (!zend_is_callable(callback_func, 0, NULL)) { - zend_string *callback_name = zend_get_callable_name(callback_func); - php_sqlite3_error(db_obj, "Not a valid callback function %s", ZSTR_VAL(callback_name)); - zend_string_release_ex(callback_name, 0); + if (!sql_func_len) { RETURN_FALSE; } @@ -1001,7 +973,7 @@ PHP_METHOD(sqlite3, createFunction) if (sqlite3_create_function(db_obj->db, sql_func, sql_func_num_args, flags | SQLITE_UTF8, func, php_sqlite3_callback_func, NULL, NULL) == SQLITE_OK) { func->func_name = estrdup(sql_func); - ZVAL_COPY(&func->func, callback_func); + ZVAL_COPY(&func->func, &fci.function_name); func->argc = sql_func_num_args; func->next = db_obj->funcs; @@ -1015,40 +987,26 @@ PHP_METHOD(sqlite3, createFunction) } /* }}} */ -/* {{{ proto bool SQLite3::createAggregate(string name, mixed step, mixed final [, int argcount]) - Allows registration of a PHP function for use as an aggregate. */ -PHP_METHOD(sqlite3, createAggregate) +/* {{{ Allows registration of a PHP function for use as an aggregate. */ +PHP_METHOD(SQLite3, createAggregate) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; php_sqlite3_func *func; char *sql_func; size_t sql_func_len; - zval *step_callback, *fini_callback; + zend_fcall_info step_fci, fini_fci; + zend_fcall_info_cache step_fcc, fini_fcc; zend_long sql_func_num_args = -1; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "szz|l", &sql_func, &sql_func_len, &step_callback, &fini_callback, &sql_func_num_args) == FAILURE) { - return; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sff|l", &sql_func, &sql_func_len, &step_fci, &step_fcc, &fini_fci, &fini_fcc, &sql_func_num_args) == FAILURE) { + RETURN_THROWS(); } - if (!sql_func_len) { - RETURN_FALSE; - } - - if (!zend_is_callable(step_callback, 0, NULL)) { - zend_string *callback_name = zend_get_callable_name(step_callback); - php_sqlite3_error(db_obj, "Not a valid callback function %s", ZSTR_VAL(callback_name)); - zend_string_release_ex(callback_name, 0); - RETURN_FALSE; - } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (!zend_is_callable(fini_callback, 0, NULL)) { - zend_string *callback_name = zend_get_callable_name(fini_callback); - php_sqlite3_error(db_obj, "Not a valid callback function %s", ZSTR_VAL(callback_name)); - zend_string_release_ex(callback_name, 0); + if (!sql_func_len) { RETURN_FALSE; } @@ -1057,8 +1015,8 @@ PHP_METHOD(sqlite3, createAggregate) if (sqlite3_create_function(db_obj->db, sql_func, sql_func_num_args, SQLITE_UTF8, func, NULL, php_sqlite3_callback_step, php_sqlite3_callback_final) == SQLITE_OK) { func->func_name = estrdup(sql_func); - ZVAL_COPY(&func->step, step_callback); - ZVAL_COPY(&func->fini, fini_callback); + ZVAL_COPY(&func->step, &step_fci.function_name); + ZVAL_COPY(&func->fini, &fini_fci.function_name); func->argc = sql_func_num_args; func->next = db_obj->funcs; @@ -1072,32 +1030,25 @@ PHP_METHOD(sqlite3, createAggregate) } /* }}} */ -/* {{{ proto bool SQLite3::createCollation(string name, mixed callback) - Registers a PHP function as a comparator that can be used with the SQL COLLATE operator. Callback must accept two strings and return an integer (as strcmp()). */ -PHP_METHOD(sqlite3, createCollation) +/* {{{ Registers a PHP function as a comparator that can be used with the SQL COLLATE operator. Callback must accept two strings and return an integer (as strcmp()). */ +PHP_METHOD(SQLite3, createCollation) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; php_sqlite3_collation *collation; char *collation_name; size_t collation_name_len; - zval *callback_func; + zend_fcall_info fci; + zend_fcall_info_cache fcc; db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &collation_name, &collation_name_len, &callback_func) == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sf", &collation_name, &collation_name_len, &fci, &fcc) == FAILURE) { + RETURN_THROWS(); } - if (!collation_name_len) { - RETURN_FALSE; - } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - if (!zend_is_callable(callback_func, 0, NULL)) { - zend_string *callback_name = zend_get_callable_name(callback_func); - php_sqlite3_error(db_obj, "Not a valid callback function %s", ZSTR_VAL(callback_name)); - zend_string_release_ex(callback_name, 0); + if (!collation_name_len) { RETURN_FALSE; } @@ -1105,7 +1056,7 @@ PHP_METHOD(sqlite3, createCollation) if (sqlite3_create_collation(db_obj->db, collation_name, SQLITE_UTF8, collation, php_sqlite3_callback_compare) == SQLITE_OK) { collation->collation_name = estrdup(collation_name); - ZVAL_COPY(&collation->cmp_func, callback_func); + ZVAL_COPY(&collation->cmp_func, &fci.function_name); collation->next = db_obj->collations; db_obj->collations = collation; @@ -1278,9 +1229,8 @@ static const php_stream_ops php_stream_sqlite3_ops = { NULL }; -/* {{{ proto resource SQLite3::openBlob(string table, string column, int rowid [, string dbname [, int flags]]) - Open a blob as a stream which we can read / write to. */ -PHP_METHOD(sqlite3, openBlob) +/* {{{ Open a blob as a stream which we can read / write to. */ +PHP_METHOD(SQLite3, openBlob) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -1293,12 +1243,12 @@ PHP_METHOD(sqlite3, openBlob) db_obj = Z_SQLITE3_DB_P(object); - SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssl|sl", &table, &table_len, &column, &column_len, &rowid, &dbname, &dbname_len, &flags) == FAILURE) { - return; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssl|pl", &table, &table_len, &column, &column_len, &rowid, &dbname, &dbname_len, &flags) == FAILURE) { + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + sqlite_flags = (flags & SQLITE_OPEN_READWRITE) ? 1 : 0; if (sqlite3_blob_open(db_obj->db, dbname, table, column, rowid, sqlite_flags, &blob) != SQLITE_OK) { @@ -1326,9 +1276,8 @@ PHP_METHOD(sqlite3, openBlob) } /* }}} */ -/* {{{ proto bool SQLite3::enableExceptions([bool enableExceptions = false]) - Enables an exception error mode. */ -PHP_METHOD(sqlite3, enableExceptions) +/* {{{ Enables an exception error mode. */ +PHP_METHOD(SQLite3, enableExceptions) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; @@ -1337,7 +1286,7 @@ PHP_METHOD(sqlite3, enableExceptions) db_obj = Z_SQLITE3_DB_P(object); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &enableExceptions) == FAILURE) { - return; + RETURN_THROWS(); } RETVAL_BOOL(db_obj->exception); @@ -1346,10 +1295,42 @@ PHP_METHOD(sqlite3, enableExceptions) } /* }}} */ +/* {{{ Register a callback function to be used as an authorizer by SQLite. The callback should return SQLite3::OK, SQLite3::IGNORE or SQLite3::DENY. */ +PHP_METHOD(SQLite3, setAuthorizer) +{ + php_sqlite3_db_object *db_obj; + zval *object = ZEND_THIS; + db_obj = Z_SQLITE3_DB_P(object); + zend_fcall_info fci; + zend_fcall_info_cache fcc; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_FUNC_OR_NULL(fci, fcc) + ZEND_PARSE_PARAMETERS_END(); + + SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3) + + /* Clear previously set callback */ + if (ZEND_FCI_INITIALIZED(db_obj->authorizer_fci)) { + zval_ptr_dtor(&db_obj->authorizer_fci.function_name); + db_obj->authorizer_fci.size = 0; + } + + /* Only enable userland authorizer if argument is not NULL */ + if (ZEND_FCI_INITIALIZED(fci)) { + db_obj->authorizer_fci = fci; + Z_ADDREF(db_obj->authorizer_fci.function_name); + db_obj->authorizer_fcc = fcc; + } + + RETURN_TRUE; +} +/* }}} */ + + #if SQLITE_VERSION_NUMBER >= 3006011 -/* {{{ proto bool SQLite3::backup(SQLite3 destination_db[, string source_dbname = "main"[, string destination_dbname = "main"]]) - Backups the current database to another one. */ -PHP_METHOD(sqlite3, backup) +/* {{{ Backups the current database to another one. */ +PHP_METHOD(SQLite3, backup) { php_sqlite3_db_object *source_obj; php_sqlite3_db_object *destination_obj; @@ -1360,13 +1341,13 @@ PHP_METHOD(sqlite3, backup) sqlite3_backup *dbBackup; int rc; // Return code + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|pp", &destination_zval, php_sqlite3_sc_entry, &source_dbname, &source_dbname_length, &destination_dbname, &destination_dbname_length) == FAILURE) { + RETURN_THROWS(); + } + source_obj = Z_SQLITE3_DB_P(source_zval); SQLITE3_CHECK_INITIALIZED(source_obj, source_obj->initialised, SQLite3) - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ss", &destination_zval, php_sqlite3_sc_entry, &source_dbname, &source_dbname_length, &destination_dbname, &destination_dbname_length) == FAILURE) { - return; - } - destination_obj = Z_SQLITE3_DB_P(destination_zval); SQLITE3_CHECK_INITIALIZED(destination_obj, destination_obj->initialised, SQLite3) @@ -1403,16 +1384,15 @@ PHP_METHOD(sqlite3, backup) /* }}} */ #endif -/* {{{ proto int SQLite3Stmt::paramCount() - Returns the number of parameters within the prepared statement. */ -PHP_METHOD(sqlite3stmt, paramCount) +/* {{{ Returns the number of parameters within the prepared statement. */ +PHP_METHOD(SQLite3Stmt, paramCount) { php_sqlite3_stmt *stmt_obj; zval *object = ZEND_THIS; stmt_obj = Z_SQLITE3_STMT_P(object); if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); @@ -1422,16 +1402,15 @@ PHP_METHOD(sqlite3stmt, paramCount) } /* }}} */ -/* {{{ proto bool SQLite3Stmt::close() - Closes the prepared statement. */ -PHP_METHOD(sqlite3stmt, close) +/* {{{ Closes the prepared statement. */ +PHP_METHOD(SQLite3Stmt, close) { php_sqlite3_stmt *stmt_obj; zval *object = ZEND_THIS; stmt_obj = Z_SQLITE3_STMT_P(object); if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); @@ -1444,16 +1423,15 @@ PHP_METHOD(sqlite3stmt, close) } /* }}} */ -/* {{{ proto bool SQLite3Stmt::reset() - Reset the prepared statement to the state before it was executed, bindings still remain. */ -PHP_METHOD(sqlite3stmt, reset) +/* {{{ Reset the prepared statement to the state before it was executed, bindings still remain. */ +PHP_METHOD(SQLite3Stmt, reset) { php_sqlite3_stmt *stmt_obj; zval *object = ZEND_THIS; stmt_obj = Z_SQLITE3_STMT_P(object); if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); @@ -1467,16 +1445,15 @@ PHP_METHOD(sqlite3stmt, reset) } /* }}} */ -/* {{{ proto bool SQLite3Stmt::clear() - Clear all current bound parameters. */ -PHP_METHOD(sqlite3stmt, clear) +/* {{{ Clear all current bound parameters. */ +PHP_METHOD(SQLite3Stmt, clear) { php_sqlite3_stmt *stmt_obj; zval *object = ZEND_THIS; stmt_obj = Z_SQLITE3_STMT_P(object); if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); @@ -1497,16 +1474,15 @@ PHP_METHOD(sqlite3stmt, clear) } /* }}} */ -/* {{{ proto bool SQLite3Stmt::readOnly() - Returns true if a statement is definitely read only */ -PHP_METHOD(sqlite3stmt, readOnly) +/* {{{ Returns true if a statement is definitely read only */ +PHP_METHOD(SQLite3Stmt, readOnly) { php_sqlite3_stmt *stmt_obj; zval *object = ZEND_THIS; stmt_obj = Z_SQLITE3_STMT_P(object); if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); @@ -1627,9 +1603,8 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ /* }}} */ -/* {{{ proto string SQLite3Stmt::getSQL([expanded = false]) - Returns the SQL statement used to prepare the query. If expanded is true, binded parameters and values will be expanded. */ -PHP_METHOD(sqlite3stmt, getSQL) +/* {{{ Returns the SQL statement used to prepare the query. If expanded is true, binded parameters and values will be expanded. */ +PHP_METHOD(SQLite3Stmt, getSQL) { php_sqlite3_stmt *stmt_obj; zend_bool expanded = 0; @@ -1638,7 +1613,7 @@ PHP_METHOD(sqlite3stmt, getSQL) int bind_rc; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &expanded) == FAILURE) { - return; + RETURN_THROWS(); } SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); @@ -1734,9 +1709,8 @@ static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *pa } /* }}} */ -/* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type]) - Bind Parameter to a stmt variable. */ -PHP_METHOD(sqlite3stmt, bindParam) +/* {{{ Common implementation of ::bindParam() and ::bindValue */ +static void sqlite3stmt_bind(INTERNAL_FUNCTION_PARAMETERS) { php_sqlite3_stmt *stmt_obj; zval *object = ZEND_THIS; @@ -1747,11 +1721,12 @@ PHP_METHOD(sqlite3stmt, bindParam) param.param_number = -1; param.type = SQLITE3_TEXT; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "lz|l", ¶m.param_number, ¶meter, ¶m.type) == FAILURE) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", ¶m.name, ¶meter, ¶m.type) == FAILURE) { - return; - } - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STR_OR_LONG(param.name, param.param_number) + Z_PARAM_ZVAL(parameter) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(param.type) + ZEND_PARSE_PARAMETERS_END(); SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt); @@ -1773,50 +1748,24 @@ PHP_METHOD(sqlite3stmt, bindParam) } /* }}} */ -/* {{{ proto bool SQLite3Stmt::bindValue(int parameter_number, mixed parameter [, int type]) - Bind Value of a parameter to a stmt variable. */ -PHP_METHOD(sqlite3stmt, bindValue) +/* {{{ Bind Parameter to a stmt variable. */ +PHP_METHOD(SQLite3Stmt, bindParam) { - php_sqlite3_stmt *stmt_obj; - zval *object = ZEND_THIS; - struct php_sqlite3_bound_param param = {0}; - zval *parameter; - stmt_obj = Z_SQLITE3_STMT_P(object); - - param.param_number = -1; - param.type = SQLITE3_TEXT; - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "lz|l", ¶m.param_number, ¶meter, ¶m.type) == FAILURE) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", ¶m.name, ¶meter, ¶m.type) == FAILURE) { - return; - } - } - - SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); - SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt); - - ZVAL_COPY(¶m.parameter, parameter); - - if (ZEND_NUM_ARGS() < 3) { - PHP_SQLITE3_SET_TYPE(parameter, param); - } + sqlite3stmt_bind(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ - if (!register_bound_parameter_to_sqlite(¶m, stmt_obj)) { - if (!Z_ISUNDEF(param.parameter)) { - zval_ptr_dtor(&(param.parameter)); - ZVAL_UNDEF(¶m.parameter); - } - RETURN_FALSE; - } - RETURN_TRUE; +/* {{{ Bind Value of a parameter to a stmt variable. */ +PHP_METHOD(SQLite3Stmt, bindValue) +{ + sqlite3stmt_bind(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ #undef PHP_SQLITE3_SET_TYPE -/* {{{ proto SQLite3Result SQLite3Stmt::execute() - Executes a prepared statement and returns a result set object. */ -PHP_METHOD(sqlite3stmt, execute) +/* {{{ Executes a prepared statement and returns a result set object. */ +PHP_METHOD(SQLite3Stmt, execute) { php_sqlite3_stmt *stmt_obj; php_sqlite3_result *result; @@ -1827,7 +1776,7 @@ PHP_METHOD(sqlite3stmt, execute) stmt_obj = Z_SQLITE3_STMT_P(object); if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); @@ -1855,8 +1804,7 @@ PHP_METHOD(sqlite3stmt, execute) result->is_prepared_statement = 1; result->db_obj = stmt_obj->db_obj; result->stmt_obj = stmt_obj; - Z_ADDREF_P(object); - ZVAL_OBJ(&result->stmt_obj_zval, Z_OBJ_P(object)); + ZVAL_OBJ_COPY(&result->stmt_obj_zval, Z_OBJ_P(object)); break; } @@ -1875,9 +1823,8 @@ PHP_METHOD(sqlite3stmt, execute) } /* }}} */ -/* {{{ proto SQLite3Stmt::__construct(SQLite3 dbobject, String Statement) - __constructor for SQLite3Stmt. */ -PHP_METHOD(sqlite3stmt, __construct) +/* {{{ __constructor for SQLite3Stmt. */ +PHP_METHOD(SQLite3Stmt, __construct) { php_sqlite3_stmt *stmt_obj; php_sqlite3_db_object *db_obj; @@ -1890,8 +1837,8 @@ PHP_METHOD(sqlite3stmt, __construct) stmt_obj = Z_SQLITE3_STMT_P(object); - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "OS", &db_zval, php_sqlite3_sc_entry, &sql) == FAILURE) { - return; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &db_zval, php_sqlite3_sc_entry, &sql) == FAILURE) { + RETURN_THROWS(); } db_obj = Z_SQLITE3_DB_P(db_zval); @@ -1905,8 +1852,7 @@ PHP_METHOD(sqlite3stmt, __construct) } stmt_obj->db_obj = db_obj; - Z_ADDREF_P(db_zval); - ZVAL_OBJ(&stmt_obj->db_obj_zval, Z_OBJ_P(db_zval)); + ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(db_zval)); errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (errcode != SQLITE_OK) { @@ -1925,27 +1871,25 @@ PHP_METHOD(sqlite3stmt, __construct) } /* }}} */ -/* {{{ proto int SQLite3Result::numColumns() - Number of columns in the result set. */ -PHP_METHOD(sqlite3result, numColumns) +/* {{{ Number of columns in the result set. */ +PHP_METHOD(SQLite3Result, numColumns) { php_sqlite3_result *result_obj; zval *object = ZEND_THIS; result_obj = Z_SQLITE3_RESULT_P(object); - SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) + RETURN_LONG(sqlite3_column_count(result_obj->stmt_obj->stmt)); } /* }}} */ -/* {{{ proto string SQLite3Result::columnName(int column) - Returns the name of the nth column. */ -PHP_METHOD(sqlite3result, columnName) +/* {{{ Returns the name of the nth column. */ +PHP_METHOD(SQLite3Result, columnName) { php_sqlite3_result *result_obj; zval *object = ZEND_THIS; @@ -1953,11 +1897,12 @@ PHP_METHOD(sqlite3result, columnName) char *column_name; result_obj = Z_SQLITE3_RESULT_P(object); - SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &column) == FAILURE) { - return; + RETURN_THROWS(); } + + SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) + column_name = (char*) sqlite3_column_name(result_obj->stmt_obj->stmt, column); if (column_name == NULL) { @@ -1968,21 +1913,20 @@ PHP_METHOD(sqlite3result, columnName) } /* }}} */ -/* {{{ proto int SQLite3Result::columnType(int column) - Returns the type of the nth column. */ -PHP_METHOD(sqlite3result, columnType) +/* {{{ Returns the type of the nth column. */ +PHP_METHOD(SQLite3Result, columnType) { php_sqlite3_result *result_obj; zval *object = ZEND_THIS; zend_long column = 0; result_obj = Z_SQLITE3_RESULT_P(object); - SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &column) == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) + if (!sqlite3_data_count(result_obj->stmt_obj->stmt)) { RETURN_FALSE; } @@ -1991,9 +1935,8 @@ PHP_METHOD(sqlite3result, columnType) } /* }}} */ -/* {{{ proto array SQLite3Result::fetchArray([int mode]) - Fetch a result row as both an associative or numerically indexed array or both. */ -PHP_METHOD(sqlite3result, fetchArray) +/* {{{ Fetch a result row as both an associative or numerically indexed array or both. */ +PHP_METHOD(SQLite3Result, fetchArray) { php_sqlite3_result *result_obj; zval *object = ZEND_THIS; @@ -2001,12 +1944,12 @@ PHP_METHOD(sqlite3result, fetchArray) zend_long mode = PHP_SQLITE3_BOTH; result_obj = Z_SQLITE3_RESULT_P(object); - SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mode) == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) + ret = sqlite3_step(result_obj->stmt_obj->stmt); switch (ret) { case SQLITE_ROW: @@ -2047,20 +1990,19 @@ PHP_METHOD(sqlite3result, fetchArray) } /* }}} */ -/* {{{ proto bool SQLite3Result::reset() - Resets the result set back to the first row. */ -PHP_METHOD(sqlite3result, reset) +/* {{{ Resets the result set back to the first row. */ +PHP_METHOD(SQLite3Result, reset) { php_sqlite3_result *result_obj; zval *object = ZEND_THIS; result_obj = Z_SQLITE3_RESULT_P(object); - SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) + if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) { RETURN_FALSE; } @@ -2069,20 +2011,19 @@ PHP_METHOD(sqlite3result, reset) } /* }}} */ -/* {{{ proto bool SQLite3Result::finalize() - Closes the result set. */ -PHP_METHOD(sqlite3result, finalize) +/* {{{ Closes the result set. */ +PHP_METHOD(SQLite3Result, finalize) { php_sqlite3_result *result_obj; zval *object = ZEND_THIS; result_obj = Z_SQLITE3_RESULT_P(object); - SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) - if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } + SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) + /* We need to finalize an internal statement */ if (result_obj->is_prepared_statement == 0) { zend_llist_del_element(&(result_obj->db_obj->free_list), &result_obj->stmt_obj_zval, @@ -2095,219 +2036,103 @@ PHP_METHOD(sqlite3result, finalize) } /* }}} */ -/* {{{ proto SQLite3Result::__construct() - __constructor for SQLite3Result. */ -PHP_METHOD(sqlite3result, __construct) +/* {{{ __constructor for SQLite3Result. */ +PHP_METHOD(SQLite3Result, __construct) { zend_throw_exception(zend_ce_exception, "SQLite3Result cannot be directly instantiated", 0); } /* }}} */ -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_open, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, encryption_key) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_busytimeout, 0) - ZEND_ARG_INFO(0, ms) -ZEND_END_ARG_INFO() - -#ifndef SQLITE_OMIT_LOAD_EXTENSION -ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_loadextension, 0) - ZEND_ARG_INFO(0, shared_library) -ZEND_END_ARG_INFO() -#endif - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_escapestring, 0, 0, 1) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_query, 0, 0, 1) - ZEND_ARG_INFO(0, query) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_querysingle, 0, 0, 1) - ZEND_ARG_INFO(0, query) - ZEND_ARG_INFO(0, entire_row) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createfunction, 0, 0, 2) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, argument_count) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createaggregate, 0, 0, 3) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, step_callback) - ZEND_ARG_INFO(0, final_callback) - ZEND_ARG_INFO(0, argument_count) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_createcollation, 0, 0, 2) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, callback) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_openblob, 0, 0, 3) - ZEND_ARG_INFO(0, table) - ZEND_ARG_INFO(0, column) - ZEND_ARG_INFO(0, rowid) - ZEND_ARG_INFO(0, dbname) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_enableexceptions, 0, 0, 0) - ZEND_ARG_INFO(0, enableExceptions) -ZEND_END_ARG_INFO() - -#if SQLITE_VERSION_NUMBER >= 3006011 -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_backup, 0, 0, 1) - ZEND_ARG_INFO(0, destination_db) - ZEND_ARG_INFO(0, source_dbname) - ZEND_ARG_INFO(0, destination_dbname) -ZEND_END_ARG_INFO() -#endif - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3stmt_bindparam, 0, 0, 2) - ZEND_ARG_INFO(0, param_number) - ZEND_ARG_INFO(1, param) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3stmt_bindvalue, 0, 0, 2) - ZEND_ARG_INFO(0, param_number) - ZEND_ARG_INFO(0, param) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3stmt_construct, 0, 0, 1) - ZEND_ARG_INFO(0, sqlite3) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3stmt_getsql, 0, 0, 0) - ZEND_ARG_INFO(0, expanded) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3result_columnname, 0, 0, 1) - ZEND_ARG_INFO(0, column_number) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3result_columntype, 0, 0, 1) - ZEND_ARG_INFO(0, column_number) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3result_fetcharray, 0, 0, 0) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sqlite3_enableextended, 0, 0, 1) - ZEND_ARG_INFO(0, enable) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_void, 0) -ZEND_END_ARG_INFO() -/* }}} */ - -/* {{{ php_sqlite3_class_methods */ -static const zend_function_entry php_sqlite3_class_methods[] = { - PHP_ME(sqlite3, open, arginfo_sqlite3_open, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, close, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, exec, arginfo_sqlite3_query, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, version, arginfo_sqlite3_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(sqlite3, lastInsertRowID, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, lastErrorCode, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, lastExtendedErrorCode, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, enableExtendedResultCodes, arginfo_sqlite3_enableextended, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, lastErrorMsg, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, busyTimeout, arginfo_sqlite3_busytimeout, ZEND_ACC_PUBLIC) -#ifndef SQLITE_OMIT_LOAD_EXTENSION - PHP_ME(sqlite3, loadExtension, arginfo_sqlite3_loadextension, ZEND_ACC_PUBLIC) -#endif - PHP_ME(sqlite3, changes, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, escapeString, arginfo_sqlite3_escapestring, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(sqlite3, prepare, arginfo_sqlite3_query, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, query, arginfo_sqlite3_query, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, querySingle, arginfo_sqlite3_querysingle, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, createFunction, arginfo_sqlite3_createfunction, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, createAggregate, arginfo_sqlite3_createaggregate, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, createCollation, arginfo_sqlite3_createcollation, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, openBlob, arginfo_sqlite3_openblob, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3, enableExceptions, arginfo_sqlite3_enableexceptions, ZEND_ACC_PUBLIC) -#if SQLITE_VERSION_NUMBER >= 3006011 - PHP_ME(sqlite3, backup, arginfo_sqlite3_backup, ZEND_ACC_PUBLIC) -#endif - /* Aliases */ - PHP_MALIAS(sqlite3, __construct, open, arginfo_sqlite3_open, ZEND_ACC_PUBLIC) - PHP_FE_END -}; -/* }}} */ - -/* {{{ php_sqlite3_stmt_class_methods */ -static const zend_function_entry php_sqlite3_stmt_class_methods[] = { - PHP_ME(sqlite3stmt, paramCount, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3stmt, close, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3stmt, reset, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3stmt, clear, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3stmt, execute, arginfo_sqlite3_void, 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, readOnly, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3stmt, getSQL, arginfo_sqlite3stmt_getsql, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3stmt, __construct, arginfo_sqlite3stmt_construct, ZEND_ACC_PRIVATE) - PHP_FE_END -}; -/* }}} */ - -/* {{{ php_sqlite3_result_class_methods */ -static const zend_function_entry php_sqlite3_result_class_methods[] = { - PHP_ME(sqlite3result, numColumns, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3result, columnName, arginfo_sqlite3result_columnname, ZEND_ACC_PUBLIC) - 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_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3result, finalize, arginfo_sqlite3_void, ZEND_ACC_PUBLIC) - PHP_ME(sqlite3result, __construct, arginfo_sqlite3_void, ZEND_ACC_PRIVATE) - PHP_FE_END -}; -/* }}} */ - -/* {{{ Authorization Callback -*/ -static int php_sqlite3_authorizer(void *autharg, int access_type, const char *arg3, const char *arg4, const char *arg5, const char *arg6) +/* {{{ Authorization Callback */ +static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, const char *arg2, const char *arg3, const char *arg4) { - switch (access_type) { - case SQLITE_ATTACH: - { - if (memcmp(arg3, ":memory:", sizeof(":memory:")) && *arg3) { - if (strncmp(arg3, "file:", 5) == 0) { + /* Check open_basedir restrictions first */ + if (PG(open_basedir) && *PG(open_basedir)) { + if (action == SQLITE_ATTACH) { + if (memcmp(arg1, ":memory:", sizeof(":memory:")) && *arg1) { + if (strncmp(arg1, "file:", 5) == 0) { /* starts with "file:" */ - if (!arg3[5]) { + if (!arg1[5]) { return SQLITE_DENY; } - if (php_check_open_basedir(arg3 + 5)) { + if (php_check_open_basedir(arg1 + 5)) { return SQLITE_DENY; } } - if (php_check_open_basedir(arg3)) { + if (php_check_open_basedir(arg1)) { return SQLITE_DENY; } } - return SQLITE_OK; } + } - default: - /* access allowed */ - return SQLITE_OK; + php_sqlite3_db_object *db_obj = (php_sqlite3_db_object *)autharg; + zend_fcall_info *fci = &db_obj->authorizer_fci; + + /* fallback to access allowed if authorizer callback is not defined */ + if (fci->size == 0) { + return SQLITE_OK; + } + + /* call userland authorizer callback, if set */ + zval retval; + zval argv[5]; + + ZVAL_LONG(&argv[0], action); + + if (NULL == arg1) { + ZVAL_NULL(&argv[1]); + } else { + ZVAL_STRING(&argv[1], arg1); } + + if (NULL == arg2) { + ZVAL_NULL(&argv[2]); + } else { + ZVAL_STRING(&argv[2], arg2); + } + + if (NULL == arg3) { + ZVAL_NULL(&argv[3]); + } else { + ZVAL_STRING(&argv[3], arg3); + } + + if (NULL == arg4) { + ZVAL_NULL(&argv[4]); + } else { + ZVAL_STRING(&argv[4], arg4); + } + + fci->retval = &retval; + fci->param_count = 5; + fci->params = argv; + + int authreturn = SQLITE_DENY; + + if (zend_call_function(fci, &db_obj->authorizer_fcc) != SUCCESS || Z_ISUNDEF(retval)) { + php_sqlite3_error(db_obj, "An error occurred while invoking the authorizer callback"); + } else { + if (Z_TYPE(retval) != IS_LONG) { + php_sqlite3_error(db_obj, "The authorizer callback returned an invalid type: expected int"); + } else { + authreturn = Z_LVAL(retval); + + if (authreturn != SQLITE_OK && authreturn != SQLITE_IGNORE && authreturn != SQLITE_DENY) { + php_sqlite3_error(db_obj, "The authorizer callback returned an invalid value"); + authreturn = SQLITE_DENY; + } + } + } + + zend_fcall_info_args_clear(fci, 0); + zval_ptr_dtor(&retval); + + return authreturn; } /* }}} */ -/* {{{ php_sqlite3_free_list_dtor -*/ +/* {{{ php_sqlite3_free_list_dtor */ static void php_sqlite3_free_list_dtor(void **item) { php_sqlite3_free_list *free_item = (php_sqlite3_free_list *)*item; @@ -2342,6 +2167,11 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */ return; } + /* Release function_name from authorizer */ + if (intern->authorizer_fci.size > 0) { + zval_ptr_dtor(&intern->authorizer_fci.function_name); + } + while (intern->funcs) { func = intern->funcs; intern->funcs = func->next; @@ -2499,13 +2329,12 @@ static void sqlite3_param_dtor(zval *data) /* {{{ */ } /* }}} */ -/* {{{ PHP_MINIT_FUNCTION -*/ +/* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(sqlite3) { zend_class_entry ce; -#if defined(ZTS) +#ifdef ZTS /* Refuse to load if this wasn't a threasafe library loaded */ if (!sqlite3_threadsafe()) { php_error_docref(NULL, E_WARNING, "A thread safe version of SQLite is required when using a thread safe version of PHP."); @@ -2518,7 +2347,7 @@ PHP_MINIT_FUNCTION(sqlite3) memcpy(&sqlite3_result_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); /* Register SQLite 3 Class */ - INIT_CLASS_ENTRY(ce, "SQLite3", php_sqlite3_class_methods); + INIT_CLASS_ENTRY(ce, "SQLite3", class_SQLite3_methods); ce.create_object = php_sqlite3_object_new; sqlite3_object_handlers.offset = XtOffsetOf(php_sqlite3_db_object, zo); sqlite3_object_handlers.clone_obj = NULL; @@ -2528,7 +2357,7 @@ PHP_MINIT_FUNCTION(sqlite3) php_sqlite3_sc_entry->unserialize = zend_class_unserialize_deny; /* Register SQLite 3 Prepared Statement Class */ - INIT_CLASS_ENTRY(ce, "SQLite3Stmt", php_sqlite3_stmt_class_methods); + INIT_CLASS_ENTRY(ce, "SQLite3Stmt", class_SQLite3Stmt_methods); ce.create_object = php_sqlite3_stmt_object_new; sqlite3_stmt_object_handlers.offset = XtOffsetOf(php_sqlite3_stmt, zo); sqlite3_stmt_object_handlers.clone_obj = NULL; @@ -2538,7 +2367,7 @@ PHP_MINIT_FUNCTION(sqlite3) php_sqlite3_stmt_entry->unserialize = zend_class_unserialize_deny; /* Register SQLite 3 Result Class */ - INIT_CLASS_ENTRY(ce, "SQLite3Result", php_sqlite3_result_class_methods); + INIT_CLASS_ENTRY(ce, "SQLite3Result", class_SQLite3Result_methods); ce.create_object = php_sqlite3_result_object_new; sqlite3_result_object_handlers.offset = XtOffsetOf(php_sqlite3_result, zo); sqlite3_result_object_handlers.clone_obj = NULL; @@ -2563,6 +2392,51 @@ PHP_MINIT_FUNCTION(sqlite3) REGISTER_LONG_CONSTANT("SQLITE3_OPEN_READWRITE", SQLITE_OPEN_READWRITE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLITE3_OPEN_CREATE", SQLITE_OPEN_CREATE, CONST_CS | CONST_PERSISTENT); + /* Class constants */ + zend_declare_class_constant_long(php_sqlite3_sc_entry, "OK", sizeof("OK") - 1, SQLITE_OK); + + /* Constants for authorizer return */ + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DENY", sizeof("DENY") - 1, SQLITE_DENY); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "IGNORE", sizeof("IGNORE") - 1, SQLITE_IGNORE); + + /* Constants for authorizer actions */ + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_INDEX", sizeof("CREATE_INDEX") - 1, SQLITE_CREATE_INDEX); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_TABLE", sizeof("CREATE_TABLE") - 1, SQLITE_CREATE_TABLE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_TEMP_INDEX", sizeof("CREATE_TEMP_INDEX") - 1, SQLITE_CREATE_TEMP_INDEX); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_TEMP_TABLE", sizeof("CREATE_TEMP_TABLE") - 1, SQLITE_CREATE_TEMP_TABLE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_TEMP_TRIGGER", sizeof("CREATE_TEMP_TRIGGER") - 1, SQLITE_CREATE_TEMP_TRIGGER); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_TEMP_VIEW", sizeof("CREATE_TEMP_VIEW") - 1, SQLITE_CREATE_TEMP_VIEW); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_TRIGGER", sizeof("CREATE_TRIGGER") - 1, SQLITE_CREATE_TRIGGER); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_VIEW", sizeof("CREATE_VIEW") - 1, SQLITE_CREATE_VIEW); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DELETE", sizeof("DELETE") - 1, SQLITE_DELETE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_INDEX", sizeof("DROP_INDEX") - 1, SQLITE_DROP_INDEX); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_TABLE", sizeof("DROP_TABLE") - 1, SQLITE_DROP_TABLE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_TEMP_INDEX", sizeof("DROP_TEMP_INDEX") - 1, SQLITE_DROP_TEMP_INDEX); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_TEMP_TABLE", sizeof("DROP_TEMP_TABLE") - 1, SQLITE_DROP_TEMP_TABLE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_TEMP_TRIGGER", sizeof("DROP_TEMP_TRIGGER") - 1, SQLITE_DROP_TEMP_TRIGGER); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_TEMP_VIEW", sizeof("DROP_TEMP_VIEW") - 1, SQLITE_DROP_TEMP_VIEW); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_TRIGGER", sizeof("DROP_TRIGGER") - 1, SQLITE_DROP_TRIGGER); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_VIEW", sizeof("DROP_VIEW") - 1, SQLITE_DROP_VIEW); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "INSERT", sizeof("INSERT") - 1, SQLITE_INSERT); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "PRAGMA", sizeof("PRAGMA") - 1, SQLITE_PRAGMA); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "READ", sizeof("READ") - 1, SQLITE_READ); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "SELECT", sizeof("SELECT") - 1, SQLITE_SELECT); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "TRANSACTION", sizeof("TRANSACTION") - 1, SQLITE_TRANSACTION); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "UPDATE", sizeof("UPDATE") - 1, SQLITE_UPDATE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "ATTACH", sizeof("ATTACH") - 1, SQLITE_ATTACH); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DETACH", sizeof("DETACH") - 1, SQLITE_DETACH); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "ALTER_TABLE", sizeof("ALTER_TABLE") - 1, SQLITE_ALTER_TABLE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "REINDEX", sizeof("REINDEX") - 1, SQLITE_REINDEX); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "ANALYZE", sizeof("ANALYZE") - 1, SQLITE_ANALYZE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "CREATE_VTABLE", sizeof("CREATE_VTABLE") - 1, SQLITE_CREATE_VTABLE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "DROP_VTABLE", sizeof("DROP_VTABLE") - 1, SQLITE_DROP_VTABLE); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "FUNCTION", sizeof("FUNCTION") - 1, SQLITE_FUNCTION); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "SAVEPOINT", sizeof("SAVEPOINT") - 1, SQLITE_SAVEPOINT); + zend_declare_class_constant_long(php_sqlite3_sc_entry, "COPY", sizeof("COPY") - 1, SQLITE_COPY); +#ifdef SQLITE_RECURSIVE + zend_declare_class_constant_long(php_sqlite3_sc_entry, "RECURSIVE", sizeof("RECURSIVE") - 1, SQLITE_RECURSIVE); +#endif + #ifdef SQLITE_DETERMINISTIC REGISTER_LONG_CONSTANT("SQLITE3_DETERMINISTIC", SQLITE_DETERMINISTIC, CONST_CS | CONST_PERSISTENT); #endif @@ -2571,8 +2445,7 @@ PHP_MINIT_FUNCTION(sqlite3) } /* }}} */ -/* {{{ PHP_MSHUTDOWN_FUNCTION -*/ +/* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(sqlite3) { UNREGISTER_INI_ENTRIES(); @@ -2581,8 +2454,7 @@ PHP_MSHUTDOWN_FUNCTION(sqlite3) } /* }}} */ -/* {{{ PHP_MINFO_FUNCTION -*/ +/* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(sqlite3) { php_info_print_table_start(); @@ -2594,8 +2466,7 @@ PHP_MINFO_FUNCTION(sqlite3) } /* }}} */ -/* {{{ PHP_GINIT_FUNCTION -*/ +/* {{{ PHP_GINIT_FUNCTION */ static PHP_GINIT_FUNCTION(sqlite3) { #if defined(COMPILE_DL_SQLITE3) && defined(ZTS) @@ -2605,8 +2476,7 @@ static PHP_GINIT_FUNCTION(sqlite3) } /* }}} */ -/* {{{ sqlite3_module_entry -*/ +/* {{{ sqlite3_module_entry */ zend_module_entry sqlite3_module_entry = { STANDARD_MODULE_HEADER, "sqlite3", diff --git a/ext/sqlite3/sqlite3.stub.php b/ext/sqlite3/sqlite3.stub.php new file mode 100644 index 0000000000..95bfb312d8 --- /dev/null +++ b/ext/sqlite3/sqlite3.stub.php @@ -0,0 +1,137 @@ +<?php + +/** @generate-function-entries */ + +class SQLite3 +{ + /** @implementation-alias SQLite3::open */ + public function __construct(string $filename, int $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $encryptionKey = "") {} + + /** @return void */ + public function open(string $filename, int $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $encryptionKey = "") {} + + /** @return bool */ + public function close() {} + + /** @return array */ + public static function version() {} + + /** @return int */ + public function lastInsertRowID() {} + + /** @return int */ + public function lastErrorCode() {} + + /** @return int */ + public function lastExtendedErrorCode() {} + + /** @return string */ + public function lastErrorMsg() {} + + /** @return int */ + public function changes() {} + + /** @return bool */ + public function busyTimeout(int $milliseconds) {} + +#ifndef SQLITE_OMIT_LOAD_EXTENSION + /** @return bool */ + public function loadExtension(string $name) {} +#endif + +#if SQLITE_VERSION_NUMBER >= 3006011 + /** @return bool */ + public function backup(SQLite3 $destination, string $sourceDatabase = "main", string $destinationDatabase = "main") {} +#endif + + /** @return string */ + public static function escapeString(string $string) {} + + /** @return SQLite3Stmt|false */ + public function prepare(string $query) {} + + /** @return bool */ + public function exec(string $query) {} + + /** @return SQLite3Result|false */ + public function query(string $query) {} + + /** @return mixed */ + public function querySingle(string $query, bool $entireRow = false) {} + + /** @return bool */ + public function createFunction(string $name, callable $callback, int $argCount = -1, int $flags = 0) {} + + /** @return bool */ + public function createAggregate(string $name, callable $stepCallback, callable $finalCallback, int $argCount = -1) {} + + /** @return bool */ + public function createCollation(string $name, callable $callback) {} + + /** @return resource|false */ + public function openBlob(string $table, string $column, int $rowid, string $database = "main", int $flags = SQLITE3_OPEN_READONLY) {} + + /** @return bool */ + public function enableExceptions(bool $enable = false) {} + + /** @return bool */ + public function enableExtendedResultCodes(bool $enable = true) {} + + /** @return bool */ + public function setAuthorizer(?callable $callback) {} +} + +class SQLite3Stmt +{ + private function __construct(SQLite3 $sqlite3, string $query) {} + + /** @return bool */ + public function bindParam(string|int $param, mixed &$var, int $type = SQLITE3_TEXT) {} + + /** @return bool */ + public function bindValue(string|int $param, mixed $value, int $type = SQLITE3_TEXT) {} + + /** @return bool */ + public function clear() {} + + /** @return bool */ + public function close() {} + + /** @return SQLite3Result|false */ + public function execute() {} + + /** @return string|false */ + public function getSQL(bool $expand = false) {} + + /** @return int */ + public function paramCount() {} + + /** @return bool */ + public function readOnly() {} + + /** @return bool */ + public function reset() {} +} + +class SQLite3Result +{ + private function __construct() {} + + /** @return int */ + public function numColumns() {} + + /** @return string|false */ + public function columnName(int $column) {} + + /** @return int|false */ + public function columnType(int $column) {} + + /** @return array|false */ + public function fetchArray(int $mode = SQLITE3_BOTH) {} + + /** @return bool */ + public function reset() {} + + /** @return bool */ + public function finalize() {} +} diff --git a/ext/sqlite3/sqlite3_arginfo.h b/ext/sqlite3/sqlite3_arginfo.h new file mode 100644 index 0000000000..39e026c52d --- /dev/null +++ b/ext/sqlite3/sqlite3_arginfo.h @@ -0,0 +1,256 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 61a684b6c221a15538a5f8cc32bc4e7d4cf3c8fd */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3___construct, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encryptionKey, IS_STRING, 0, "\"\"") +ZEND_END_ARG_INFO() + +#define arginfo_class_SQLite3_open arginfo_class_SQLite3___construct + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_close, 0, 0, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_SQLite3_version arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3_lastInsertRowID arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3_lastErrorCode arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3_lastExtendedErrorCode arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3_lastErrorMsg arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3_changes arginfo_class_SQLite3_close + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_busyTimeout, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, milliseconds, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_loadExtension, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) +ZEND_END_ARG_INFO() +#endif + +#if SQLITE_VERSION_NUMBER >= 3006011 +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_backup, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, destination, SQLite3, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sourceDatabase, IS_STRING, 0, "\"main\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, destinationDatabase, IS_STRING, 0, "\"main\"") +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_escapeString, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_prepare, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_SQLite3_exec arginfo_class_SQLite3_prepare + +#define arginfo_class_SQLite3_query arginfo_class_SQLite3_prepare + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_querySingle, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, entireRow, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_createFunction, 0, 0, 2) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, argCount, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_createAggregate, 0, 0, 3) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, stepCallback, IS_CALLABLE, 0) + ZEND_ARG_TYPE_INFO(0, finalCallback, IS_CALLABLE, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, argCount, IS_LONG, 0, "-1") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_createCollation, 0, 0, 2) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_openBlob, 0, 0, 3) + ZEND_ARG_TYPE_INFO(0, table, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, column, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, rowid, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, database, IS_STRING, 0, "\"main\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "SQLITE3_OPEN_READONLY") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_enableExceptions, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_enableExtendedResultCodes, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "true") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_setAuthorizer, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Stmt___construct, 0, 0, 2) + ZEND_ARG_OBJ_INFO(0, sqlite3, SQLite3, 0) + ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Stmt_bindParam, 0, 0, 2) + ZEND_ARG_TYPE_MASK(0, param, MAY_BE_STRING|MAY_BE_LONG, NULL) + ZEND_ARG_TYPE_INFO(1, var, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "SQLITE3_TEXT") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Stmt_bindValue, 0, 0, 2) + ZEND_ARG_TYPE_MASK(0, param, MAY_BE_STRING|MAY_BE_LONG, NULL) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "SQLITE3_TEXT") +ZEND_END_ARG_INFO() + +#define arginfo_class_SQLite3Stmt_clear arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3Stmt_close arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3Stmt_execute arginfo_class_SQLite3_close + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Stmt_getSQL, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, expand, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +#define arginfo_class_SQLite3Stmt_paramCount arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3Stmt_readOnly arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3Stmt_reset arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3Result___construct arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3Result_numColumns arginfo_class_SQLite3_close + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Result_columnName, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, column, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_SQLite3Result_columnType arginfo_class_SQLite3Result_columnName + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Result_fetchArray, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "SQLITE3_BOTH") +ZEND_END_ARG_INFO() + +#define arginfo_class_SQLite3Result_reset arginfo_class_SQLite3_close + +#define arginfo_class_SQLite3Result_finalize arginfo_class_SQLite3_close + + +ZEND_METHOD(SQLite3, open); +ZEND_METHOD(SQLite3, close); +ZEND_METHOD(SQLite3, version); +ZEND_METHOD(SQLite3, lastInsertRowID); +ZEND_METHOD(SQLite3, lastErrorCode); +ZEND_METHOD(SQLite3, lastExtendedErrorCode); +ZEND_METHOD(SQLite3, lastErrorMsg); +ZEND_METHOD(SQLite3, changes); +ZEND_METHOD(SQLite3, busyTimeout); +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) +ZEND_METHOD(SQLite3, loadExtension); +#endif +#if SQLITE_VERSION_NUMBER >= 3006011 +ZEND_METHOD(SQLite3, backup); +#endif +ZEND_METHOD(SQLite3, escapeString); +ZEND_METHOD(SQLite3, prepare); +ZEND_METHOD(SQLite3, exec); +ZEND_METHOD(SQLite3, query); +ZEND_METHOD(SQLite3, querySingle); +ZEND_METHOD(SQLite3, createFunction); +ZEND_METHOD(SQLite3, createAggregate); +ZEND_METHOD(SQLite3, createCollation); +ZEND_METHOD(SQLite3, openBlob); +ZEND_METHOD(SQLite3, enableExceptions); +ZEND_METHOD(SQLite3, enableExtendedResultCodes); +ZEND_METHOD(SQLite3, setAuthorizer); +ZEND_METHOD(SQLite3Stmt, __construct); +ZEND_METHOD(SQLite3Stmt, bindParam); +ZEND_METHOD(SQLite3Stmt, bindValue); +ZEND_METHOD(SQLite3Stmt, clear); +ZEND_METHOD(SQLite3Stmt, close); +ZEND_METHOD(SQLite3Stmt, execute); +ZEND_METHOD(SQLite3Stmt, getSQL); +ZEND_METHOD(SQLite3Stmt, paramCount); +ZEND_METHOD(SQLite3Stmt, readOnly); +ZEND_METHOD(SQLite3Stmt, reset); +ZEND_METHOD(SQLite3Result, __construct); +ZEND_METHOD(SQLite3Result, numColumns); +ZEND_METHOD(SQLite3Result, columnName); +ZEND_METHOD(SQLite3Result, columnType); +ZEND_METHOD(SQLite3Result, fetchArray); +ZEND_METHOD(SQLite3Result, reset); +ZEND_METHOD(SQLite3Result, finalize); + + +static const zend_function_entry class_SQLite3_methods[] = { + ZEND_MALIAS(SQLite3, __construct, open, arginfo_class_SQLite3___construct, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, open, arginfo_class_SQLite3_open, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, close, arginfo_class_SQLite3_close, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, version, arginfo_class_SQLite3_version, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME(SQLite3, lastInsertRowID, arginfo_class_SQLite3_lastInsertRowID, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, lastErrorCode, arginfo_class_SQLite3_lastErrorCode, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, lastExtendedErrorCode, arginfo_class_SQLite3_lastExtendedErrorCode, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, lastErrorMsg, arginfo_class_SQLite3_lastErrorMsg, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, changes, arginfo_class_SQLite3_changes, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, busyTimeout, arginfo_class_SQLite3_busyTimeout, ZEND_ACC_PUBLIC) +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) + ZEND_ME(SQLite3, loadExtension, arginfo_class_SQLite3_loadExtension, ZEND_ACC_PUBLIC) +#endif +#if SQLITE_VERSION_NUMBER >= 3006011 + ZEND_ME(SQLite3, backup, arginfo_class_SQLite3_backup, ZEND_ACC_PUBLIC) +#endif + ZEND_ME(SQLite3, escapeString, arginfo_class_SQLite3_escapeString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME(SQLite3, prepare, arginfo_class_SQLite3_prepare, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, exec, arginfo_class_SQLite3_exec, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, query, arginfo_class_SQLite3_query, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, querySingle, arginfo_class_SQLite3_querySingle, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, createFunction, arginfo_class_SQLite3_createFunction, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, createAggregate, arginfo_class_SQLite3_createAggregate, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, createCollation, arginfo_class_SQLite3_createCollation, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, openBlob, arginfo_class_SQLite3_openBlob, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, enableExceptions, arginfo_class_SQLite3_enableExceptions, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, enableExtendedResultCodes, arginfo_class_SQLite3_enableExtendedResultCodes, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3, setAuthorizer, arginfo_class_SQLite3_setAuthorizer, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + + +static const zend_function_entry class_SQLite3Stmt_methods[] = { + ZEND_ME(SQLite3Stmt, __construct, arginfo_class_SQLite3Stmt___construct, ZEND_ACC_PRIVATE) + ZEND_ME(SQLite3Stmt, bindParam, arginfo_class_SQLite3Stmt_bindParam, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, bindValue, arginfo_class_SQLite3Stmt_bindValue, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, clear, arginfo_class_SQLite3Stmt_clear, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, close, arginfo_class_SQLite3Stmt_close, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, execute, arginfo_class_SQLite3Stmt_execute, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, getSQL, arginfo_class_SQLite3Stmt_getSQL, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, paramCount, arginfo_class_SQLite3Stmt_paramCount, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, readOnly, arginfo_class_SQLite3Stmt_readOnly, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, reset, arginfo_class_SQLite3Stmt_reset, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + + +static const zend_function_entry class_SQLite3Result_methods[] = { + ZEND_ME(SQLite3Result, __construct, arginfo_class_SQLite3Result___construct, ZEND_ACC_PRIVATE) + ZEND_ME(SQLite3Result, numColumns, arginfo_class_SQLite3Result_numColumns, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Result, columnName, arginfo_class_SQLite3Result_columnName, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Result, columnType, arginfo_class_SQLite3Result_columnType, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Result, fetchArray, arginfo_class_SQLite3Result_fetchArray, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Result, reset, arginfo_class_SQLite3Result_reset, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Result, finalize, arginfo_class_SQLite3Result_finalize, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; diff --git a/ext/sqlite3/tests/bug45798.phpt b/ext/sqlite3/tests/bug45798.phpt index 9637c1fc9b..7184d58d54 100644 --- a/ext/sqlite3/tests/bug45798.phpt +++ b/ext/sqlite3/tests/bug45798.phpt @@ -18,7 +18,7 @@ $stmt->bindParam(1, $foo, SQLITE3_TEXT); $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/bug66550.phpt b/ext/sqlite3/tests/bug66550.phpt index a44515b0d9..244f358a5f 100644 --- a/ext/sqlite3/tests/bug66550.phpt +++ b/ext/sqlite3/tests/bug66550.phpt @@ -15,9 +15,11 @@ $stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id'); // Close the database connection and free the internal sqlite3_stmt object $db->close(); // Access the sqlite3_stmt object via the php_sqlite3_stmt container -$stmt->reset(); +try { + $stmt->reset(); +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> -==DONE== ---EXPECTF-- -Warning: SQLite3Stmt::reset(): The SQLite3 object has not been correctly initialised in %s -==DONE== +--EXPECT-- +The SQLite3 object has not been correctly initialised or is already closed diff --git a/ext/sqlite3/tests/bug68760.phpt b/ext/sqlite3/tests/bug68760.phpt index 7eb97ee013..7cc646780b 100644 --- a/ext/sqlite3/tests/bug68760.phpt +++ b/ext/sqlite3/tests/bug68760.phpt @@ -7,8 +7,8 @@ if (!extension_loaded('sqlite3')) die('skip'); --FILE-- <?php function oopsFunction($a, $b) { - echo "callback".PHP_EOL; - throw new \Exception("oops"); + echo "callback".PHP_EOL; + throw new \Exception("oops"); } $db = new SQLite3(":memory:"); diff --git a/ext/sqlite3/tests/bug72668.phpt b/ext/sqlite3/tests/bug72668.phpt index 2845fa0a7c..6f566d2df1 100644 --- a/ext/sqlite3/tests/bug72668.phpt +++ b/ext/sqlite3/tests/bug72668.phpt @@ -6,33 +6,33 @@ if (!extension_loaded('sqlite3')) die('skip'); ?> --FILE-- <?php function my_udf_md5($string) { - throw new \Exception("test exception\n"); + throw new \Exception("test exception\n"); } $db = new SQLite3(':memory:'); $db->createFunction('my_udf_md5', 'my_udf_md5'); try { - $result = $db->query('SELECT my_udf_md5("test")'); - var_dump($result); + $result = $db->query('SELECT my_udf_md5("test")'); + var_dump($result); } catch(\Exception $e) { - echo "Exception: ".$e->getMessage(); + echo "Exception: ".$e->getMessage(); } try { - $result = $db->querySingle('SELECT my_udf_md5("test")'); - var_dump($result); + $result = $db->querySingle('SELECT my_udf_md5("test")'); + var_dump($result); } catch(\Exception $e) { - echo "Exception: ".$e->getMessage(); + echo "Exception: ".$e->getMessage(); } $statement = $db->prepare('SELECT my_udf_md5("test")'); try { - $result = $statement->execute(); - var_dump($result); + $result = $statement->execute(); + var_dump($result); } catch(\Exception $e) { - echo "Exception: ".$e->getMessage(); + echo "Exception: ".$e->getMessage(); } ?> --EXPECT-- diff --git a/ext/sqlite3/tests/bug73333.phpt b/ext/sqlite3/tests/bug73333.phpt index 8634b67f76..f9521209e8 100644 --- a/ext/sqlite3/tests/bug73333.phpt +++ b/ext/sqlite3/tests/bug73333.phpt @@ -19,8 +19,6 @@ while (($row = $res->fetchArray(SQLITE3_NUM)) !== false) { echo gettype($row[0]), PHP_EOL; } ?> -===DONE=== --EXPECT-- integer integer -===DONE=== diff --git a/ext/sqlite3/tests/bug76665.phpt b/ext/sqlite3/tests/bug76665.phpt index 0e1de136f7..f56f358bae 100644 --- a/ext/sqlite3/tests/bug76665.phpt +++ b/ext/sqlite3/tests/bug76665.phpt @@ -13,7 +13,5 @@ $stmt->bindValue(':bar', 17, SQLITE3_FLOAT); $stmt->execute(); var_dump($db->querySingle("SELECT bar FROM foo LIMIT 1")); ?> -===DONE=== --EXPECT-- float(17) -===DONE=== diff --git a/ext/sqlite3/tests/skipif.inc b/ext/sqlite3/tests/skipif.inc index 9614e679b9..0f930332ea 100644 --- a/ext/sqlite3/tests/skipif.inc +++ b/ext/sqlite3/tests/skipif.inc @@ -1,7 +1,7 @@ <?php if (!extension_loaded('sqlite3')) { - die("skip sqlite3 extension not loaded"); + die("skip sqlite3 extension not loaded"); } ?> diff --git a/ext/sqlite3/tests/sqlite3_02_open.phpt b/ext/sqlite3/tests/sqlite3_02_open.phpt index dcc38d1407..db31587f68 100644 --- a/ext/sqlite3/tests/sqlite3_02_open.phpt +++ b/ext/sqlite3/tests/sqlite3_02_open.phpt @@ -16,4 +16,4 @@ try { ?> --EXPECT-- -string(60) "SQLite3::__construct() expects at least 1 parameter, 0 given" +string(59) "SQLite3::__construct() expects at least 1 argument, 0 given" diff --git a/ext/sqlite3/tests/sqlite3_03_insert.phpt b/ext/sqlite3/tests/sqlite3_03_insert.phpt index 1a0690a000..60880de880 100644 --- a/ext/sqlite3/tests/sqlite3_03_insert.phpt +++ b/ext/sqlite3/tests/sqlite3_03_insert.phpt @@ -19,7 +19,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_04_update.phpt b/ext/sqlite3/tests/sqlite3_04_update.phpt index 3ce7d9cf8b..fe55464ef6 100644 --- a/ext/sqlite3/tests/sqlite3_04_update.phpt +++ b/ext/sqlite3/tests/sqlite3_04_update.phpt @@ -19,7 +19,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); @@ -30,7 +30,7 @@ echo "Checking results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_05_delete.phpt b/ext/sqlite3/tests/sqlite3_05_delete.phpt index 9ce50c4789..8768d0b575 100644 --- a/ext/sqlite3/tests/sqlite3_05_delete.phpt +++ b/ext/sqlite3/tests/sqlite3_05_delete.phpt @@ -19,7 +19,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); @@ -30,7 +30,7 @@ echo "Checking results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt b/ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt index 710813e8f5..28fd2d264a 100644 --- a/ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt +++ b/ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt @@ -24,7 +24,7 @@ $foo = 'a'; $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt b/ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt index d9a2408123..393386fead 100644 --- a/ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt +++ b/ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt @@ -23,7 +23,7 @@ var_dump($stmt->bindValue(1, $foo, SQLITE3_TEXT)); $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_08_udf.phpt b/ext/sqlite3/tests/sqlite3_08_udf.phpt index 7f00dbb1c4..24862ddda8 100644 --- a/ext/sqlite3/tests/sqlite3_08_udf.phpt +++ b/ext/sqlite3/tests/sqlite3_08_udf.phpt @@ -7,7 +7,7 @@ SQLite3::createFunction function my_udf_md5($foo) { - return md5($foo); + return md5($foo); } require_once(__DIR__ . '/new_db.inc'); @@ -27,7 +27,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT my_udf_md5(id) FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt b/ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt index 994503dd03..27497f7448 100644 --- a/ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt +++ b/ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt @@ -30,7 +30,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT id, quote(data) AS data FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt b/ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt index 712ad2e539..f7bd34f388 100644 --- a/ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt +++ b/ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt @@ -25,7 +25,7 @@ var_dump($stmt->bindValue('id', $foo, SQLITE3_TEXT)); $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_11_numrows.phpt b/ext/sqlite3/tests/sqlite3_11_numrows.phpt index 49b8cd7cc7..b6622dd25f 100644 --- a/ext/sqlite3/tests/sqlite3_11_numrows.phpt +++ b/ext/sqlite3/tests/sqlite3_11_numrows.phpt @@ -4,9 +4,9 @@ SQLite3::prepare number of rows <?php require_once(__DIR__ . '/skipif.inc'); // Create an instance of the ReflectionMethod class try { - $method = new ReflectionMethod('sqlite3result', 'numRows'); + $method = new ReflectionMethod('sqlite3result', 'numRows'); } catch (ReflectionException $e) { - die("skip SQLite3Result::numRows method does not exist"); + die("skip SQLite3Result::numRows method does not exist"); } ?> --FILE-- diff --git a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt index eac5a59a8a..34af57128a 100644 --- a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt +++ b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt @@ -19,15 +19,19 @@ echo "SELECTING results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); - /* Only read one row and break */ - break; + var_dump($result); + /* Only read one row and break */ + break; } echo "Closing database\n"; var_dump($db->close()); echo "Check db was closed\n"; -var_dump($results->numColumns()); +try { + var_dump($results->numColumns()); +} catch (\Error $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> --EXPECTF-- @@ -46,7 +50,5 @@ array(2) { Closing database bool(true) Check db was closed - -Warning: SQLite3Result::numColumns(): The SQLite3Result object has not been correctly initialised in %s on line %d -bool(false) +The SQLite3Result object has not been correctly initialised or is already closed Done diff --git a/ext/sqlite3/tests/sqlite3_13_skip_all_cleanup.phpt b/ext/sqlite3/tests/sqlite3_13_skip_all_cleanup.phpt index daeacc0832..0bced8c19a 100644 --- a/ext/sqlite3/tests/sqlite3_13_skip_all_cleanup.phpt +++ b/ext/sqlite3/tests/sqlite3_13_skip_all_cleanup.phpt @@ -19,7 +19,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } echo "Done\n"; ?> diff --git a/ext/sqlite3/tests/sqlite3_15_open_error-win.phpt b/ext/sqlite3/tests/sqlite3_15_open_error-win.phpt index d9c7e2fa41..4bdb9fade4 100644 --- a/ext/sqlite3/tests/sqlite3_15_open_error-win.phpt +++ b/ext/sqlite3/tests/sqlite3_15_open_error-win.phpt @@ -3,7 +3,7 @@ SQLite3::open error test --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) != 'WIN' ) { - die('skip windows only test'); + die('skip windows only test'); } require_once(__DIR__ . '/skipif.inc'); ?> @@ -19,9 +19,9 @@ $cmd = $icacls . ' ' . $unreadable . ' /inheritance:r /deny ' . $user . ':(F,M,R exec($cmd); try { - $db = new SQLite3($unreadable); + $db = new SQLite3($unreadable); } catch (Exception $e) { - echo $e . "\n"; + echo $e . "\n"; } echo "Done\n"; diff --git a/ext/sqlite3/tests/sqlite3_15_open_error.phpt b/ext/sqlite3/tests/sqlite3_15_open_error.phpt index 74bcc920d0..219cb6051a 100644 --- a/ext/sqlite3/tests/sqlite3_15_open_error.phpt +++ b/ext/sqlite3/tests/sqlite3_15_open_error.phpt @@ -3,9 +3,12 @@ SQLite3::open error test --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) == 'WIN' ) { - die('skip non windows test'); + die('skip non windows test'); } require_once(__DIR__ . '/skipif.inc'); +if (!function_exists('posix_geteui')) { + die('SKIP posix_geteuid() not defined so cannot check if run as root'); +} if (posix_geteuid() == 0) { die('SKIP Cannot run test as root.'); } @@ -16,9 +19,9 @@ $unreadable = __DIR__ . '/unreadable.db'; touch($unreadable); chmod($unreadable, 0200); try { - $db = new SQLite3($unreadable); + $db = new SQLite3($unreadable); } catch (Exception $e) { - echo $e . "\n"; + echo $e . "\n"; } echo "Done\n"; unlink($unreadable); diff --git a/ext/sqlite3/tests/sqlite3_16_select_no_results.phpt b/ext/sqlite3/tests/sqlite3_16_select_no_results.phpt index 91875b68ad..08fe5eeb24 100644 --- a/ext/sqlite3/tests/sqlite3_16_select_no_results.phpt +++ b/ext/sqlite3/tests/sqlite3_16_select_no_results.phpt @@ -15,7 +15,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_19_columninfo.phpt b/ext/sqlite3/tests/sqlite3_19_columninfo.phpt index 2395c75399..51017bb0bc 100644 --- a/ext/sqlite3/tests/sqlite3_19_columninfo.phpt +++ b/ext/sqlite3/tests/sqlite3_19_columninfo.phpt @@ -18,10 +18,10 @@ var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')")) echo "SELECTING results\n"; $result = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($row = $result->fetchArray(SQLITE3_NUM)) { - $totalColumns = $result->numColumns(); - for ($i = 0; $i < $totalColumns; $i++) { - echo "Name: " . $result->columnName($i) . " - Type: " . $result->columnType($i) . "\n"; - } + $totalColumns = $result->numColumns(); + for ($i = 0; $i < $totalColumns; $i++) { + echo "Name: " . $result->columnName($i) . " - Type: " . $result->columnType($i) . "\n"; + } } $result->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_20_error.phpt b/ext/sqlite3/tests/sqlite3_20_error.phpt index a9324c3999..9b1579a83e 100644 --- a/ext/sqlite3/tests/sqlite3_20_error.phpt +++ b/ext/sqlite3/tests/sqlite3_20_error.phpt @@ -10,8 +10,8 @@ require_once(__DIR__ . '/new_db.inc'); echo "SELECTING from invalid table\n"; $result = $db->query("SELECT * FROM non_existent_table"); if (!$result) { - echo "Error Code: " . $db->lastErrorCode() . "\n"; - echo "Error Msg: " . $db->lastErrorMsg() . "\n"; + echo "Error Code: " . $db->lastErrorCode() . "\n"; + echo "Error Msg: " . $db->lastErrorMsg() . "\n"; } echo "Closing database\n"; var_dump($db->close()); diff --git a/ext/sqlite3/tests/sqlite3_21_security.phpt b/ext/sqlite3/tests/sqlite3_21_security.phpt index 5221807cd5..407869b3f8 100644 --- a/ext/sqlite3/tests/sqlite3_21_security.phpt +++ b/ext/sqlite3/tests/sqlite3_21_security.phpt @@ -19,9 +19,9 @@ unlink($directory . $file); echo "Above test directory\n"; try { - $db = new SQLite3('../bad' . $file); + $db = new SQLite3('../bad' . $file); } catch (Exception $e) { - echo $e . "\n"; + echo $e . "\n"; } echo "Done\n"; diff --git a/ext/sqlite3/tests/sqlite3_22_loadextension.phpt b/ext/sqlite3/tests/sqlite3_22_loadextension.phpt index 52a533d542..d4750b5f5e 100644 --- a/ext/sqlite3/tests/sqlite3_22_loadextension.phpt +++ b/ext/sqlite3/tests/sqlite3_22_loadextension.phpt @@ -5,7 +5,7 @@ SQLite3 load extension require_once(__DIR__ . '/skipif.inc'); $r = new ReflectionClass("sqlite3"); if (!$r->hasMethod("loadExtension")) { - die("skip - sqlite3 doesn't have loadExtension enabled"); + die("skip - sqlite3 doesn't have loadExtension enabled"); } ?> --INI-- diff --git a/ext/sqlite3/tests/sqlite3_23_escape_string.phpt b/ext/sqlite3/tests/sqlite3_23_escape_string.phpt index 6552c222a7..f91213ae64 100644 --- a/ext/sqlite3/tests/sqlite3_23_escape_string.phpt +++ b/ext/sqlite3/tests/sqlite3_23_escape_string.phpt @@ -19,7 +19,7 @@ echo "SELECTING results\n"; $results = $db->query("SELECT * FROM test ORDER BY id ASC"); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt index 84993571ec..c8a033e738 100644 --- a/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt +++ b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt @@ -8,17 +8,17 @@ SQLite3::createAggregate() test require_once(__DIR__ . '/new_db.inc'); function sum_list_step($context, $rows, $string) { - if (empty($context)) - { - $context = array('total' => 0, 'values' => array()); - } - $context['total'] += intval($string); - $context['values'][] = $context['total']; - return $context; + if (empty($context)) + { + $context = array('total' => 0, 'values' => array()); + } + $context['total'] += intval($string); + $context['values'][] = $context['total']; + return $context; } function sum_list_finalize($context) { - return implode(',', $context['values']); + return implode(',', $context['values']); } echo "Creating Table\n"; diff --git a/ext/sqlite3/tests/sqlite3_26_reset_prepared_stmt.phpt b/ext/sqlite3/tests/sqlite3_26_reset_prepared_stmt.phpt index ffd05d3329..39e9e48676 100644 --- a/ext/sqlite3/tests/sqlite3_26_reset_prepared_stmt.phpt +++ b/ext/sqlite3/tests/sqlite3_26_reset_prepared_stmt.phpt @@ -23,11 +23,11 @@ var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT)); $foo = 'a'; $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $stmt->reset(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_27_reset_prepared_stmt_result.phpt b/ext/sqlite3/tests/sqlite3_27_reset_prepared_stmt_result.phpt index 646cb473f3..6257d6483c 100644 --- a/ext/sqlite3/tests/sqlite3_27_reset_prepared_stmt_result.phpt +++ b/ext/sqlite3/tests/sqlite3_27_reset_prepared_stmt_result.phpt @@ -23,11 +23,11 @@ var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT)); $foo = 'a'; $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->reset(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_28_clear_bindings.phpt b/ext/sqlite3/tests/sqlite3_28_clear_bindings.phpt index a17e1fb3f1..4472b878bc 100644 --- a/ext/sqlite3/tests/sqlite3_28_clear_bindings.phpt +++ b/ext/sqlite3/tests/sqlite3_28_clear_bindings.phpt @@ -23,14 +23,14 @@ var_dump($stmt->bindParam(1, $foo, SQLITE3_TEXT)); $foo = 'a'; $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $stmt->reset(); $stmt->clear(); var_dump($stmt->bindValue(1, 'b', SQLITE3_TEXT)); $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_33_createAggregate_notcallable.phpt b/ext/sqlite3/tests/sqlite3_33_createAggregate_notcallable.phpt index fe7c8fb75a..f05e053b25 100644 --- a/ext/sqlite3/tests/sqlite3_33_createAggregate_notcallable.phpt +++ b/ext/sqlite3/tests/sqlite3_33_createAggregate_notcallable.phpt @@ -13,17 +13,26 @@ function aggregate_final ($var) { return $var; } $db = new SQLite3(':memory:'); -$db->createAggregate ('TESTAGGREGATE', 'aggregate_test_step', 'aggregate_final'); -$db->createAggregate ('TESTAGGREGATE2', 'aggregate_step', 'aggregate_test_final'); +try { + $db->createAggregate('TESTAGGREGATE', 'aggregate_test_step', 'aggregate_final'); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + $db->createAggregate('TESTAGGREGATE2', 'aggregate_step', 'aggregate_test_final'); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump($db->createAggregate ('TESTAGGREGATE3', 'aggregate_step', 'aggregate_final')); $db->close(); echo "Done" ?> ---EXPECTF-- -Warning: SQLite3::createAggregate(): Not a valid callback function aggregate_test_step in %s on line %d - -Warning: SQLite3::createAggregate(): Not a valid callback function aggregate_test_final in %s on line %d +--EXPECT-- +SQLite3::createAggregate(): Argument #2 ($stepCallback) must be a valid callback, function "aggregate_test_step" not found or invalid function name +SQLite3::createAggregate(): Argument #3 ($finalCallback) must be a valid callback, function "aggregate_test_final" not found or invalid function name bool(true) Done diff --git a/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt b/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt index ab5d3fc99a..d8f59a5edb 100644 --- a/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt +++ b/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt @@ -10,7 +10,7 @@ sqlite3.extension_dir="{TMP}" require_once(__DIR__ . '/skipif.inc'); if (!method_exists('SQLite3', 'loadExtension')) { - die("skip if SQLITE_OMIT_LOAD_EXTENSION defined"); + die("skip if SQLITE_OMIT_LOAD_EXTENSION defined"); } ?> --FILE-- diff --git a/ext/sqlite3/tests/sqlite3_33_reset.phpt b/ext/sqlite3/tests/sqlite3_33_reset.phpt index 531874ceb6..48abc829c7 100644 --- a/ext/sqlite3/tests/sqlite3_33_reset.phpt +++ b/ext/sqlite3/tests/sqlite3_33_reset.phpt @@ -15,13 +15,11 @@ $db->exec("INSERT INTO foo (id, bar) VALUES (1, 'This is a test')"); $stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id'); $stmt->bindValue(':id', 1, SQLITE3_INTEGER); -$stmt->reset("dummy"); $stmt->reset(); //var_dump($db); //var_dump($db->close()); echo "Done\n"; ?> ---EXPECTF-- -Warning: SQLite3Stmt::reset() expects exactly 0 parameters, 1 given in %s on line %d +--EXPECT-- Done diff --git a/ext/sqlite3/tests/sqlite3_34_load_extension_ext_dir.phpt b/ext/sqlite3/tests/sqlite3_34_load_extension_ext_dir.phpt index f04df7750b..7b0d5fea53 100644 --- a/ext/sqlite3/tests/sqlite3_34_load_extension_ext_dir.phpt +++ b/ext/sqlite3/tests/sqlite3_34_load_extension_ext_dir.phpt @@ -8,7 +8,7 @@ Jelle Lampaert require_once(__DIR__ . '/skipif.inc'); if (!method_exists('SQLite3', 'loadExtension')) { - die("skip if SQLITE_OMIT_LOAD_EXTENSION defined"); + die("skip if SQLITE_OMIT_LOAD_EXTENSION defined"); } ?> --FILE-- diff --git a/ext/sqlite3/tests/sqlite3_36_create_collation.phpt b/ext/sqlite3/tests/sqlite3_36_create_collation.phpt index 90fbd9d37b..644ceb02c6 100644 --- a/ext/sqlite3/tests/sqlite3_36_create_collation.phpt +++ b/ext/sqlite3/tests/sqlite3_36_create_collation.phpt @@ -13,8 +13,8 @@ $db->exec('CREATE TABLE t (s varchar(4))'); $stmt = $db->prepare('INSERT INTO t VALUES (?)'); foreach(array('a1', 'a10', 'a2') as $s){ - $stmt->bindParam(1, $s); - $stmt->execute(); + $stmt->bindParam(1, $s); + $stmt->execute(); } $defaultSort = $db->query('SELECT s FROM t ORDER BY s'); //memcmp() sort @@ -22,12 +22,12 @@ $naturalSort = $db->query('SELECT s FROM t ORDER BY s COLLATE NAT'); //strnatcmp echo "default\n"; while ($row = $defaultSort->fetchArray()){ - echo $row['s'], "\n"; + echo $row['s'], "\n"; } echo "natural\n"; while ($row = $naturalSort->fetchArray()){ - echo $row['s'], "\n"; + echo $row['s'], "\n"; } $db->close(); diff --git a/ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt b/ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt new file mode 100644 index 0000000000..459beeca53 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt @@ -0,0 +1,104 @@ +--TEST-- +SQLite3 user authorizer callback +--SKIPIF-- +<?php require_once(__DIR__ . '/skipif.inc'); ?> +--FILE-- +<?php + +$db = new SQLite3(':memory:'); +$db->enableExceptions(true); + +$db->setAuthorizer(function (int $action) { + if ($action == SQLite3::SELECT) { + return SQLite3::OK; + } + + return SQLite3::DENY; +}); + +// This query should be accepted +var_dump($db->querySingle('SELECT 1;')); + +try { + // This one should fail + var_dump($db->querySingle('CREATE TABLE test (a, b);')); +} catch (\Exception $e) { + echo $e->getMessage() . "\n"; +} + +// Test disabling the authorizer +$db->setAuthorizer(null); + +// This should now succeed +var_dump($db->exec('CREATE TABLE test (a); INSERT INTO test VALUES (42);')); +var_dump($db->querySingle('SELECT a FROM test;')); + +// Test if we are getting the correct arguments +$db->setAuthorizer(function (int $action) { + $constants = (new ReflectionClass('SQLite3'))->getConstants(); + $constants = array_flip($constants); + + var_dump($constants[$action], implode(',', array_slice(func_get_args(), 1))); + return SQLITE3::OK; +}); + +var_dump($db->exec('SELECT * FROM test WHERE a = 42;')); +var_dump($db->exec('DROP TABLE test;')); + +// Try to return something invalid from the authorizer +$db->setAuthorizer(function () { + return 'FAIL'; +}); + +try { + var_dump($db->querySingle('SELECT 1;')); +} catch (\Exception $e) { + echo $e->getMessage() . "\n"; + echo $e->getPrevious()->getMessage() . "\n"; +} + +$db->setAuthorizer(function () { + return 4200; +}); + +try { + var_dump($db->querySingle('SELECT 1;')); +} catch (\Exception $e) { + echo $e->getMessage() . "\n"; + echo $e->getPrevious()->getMessage() . "\n"; +} + +?> +--EXPECT-- +int(1) +Unable to prepare statement: 23, not authorized +bool(true) +int(42) +string(6) "SELECT" +string(3) ",,," +string(4) "READ" +string(12) "test,a,main," +string(4) "READ" +string(12) "test,a,main," +bool(true) +string(6) "DELETE" +string(20) "sqlite_master,,main," +string(10) "DROP_TABLE" +string(11) "test,,main," +string(6) "DELETE" +string(11) "test,,main," +string(6) "DELETE" +string(20) "sqlite_master,,main," +string(4) "READ" +string(28) "sqlite_master,tbl_name,main," +string(4) "READ" +string(24) "sqlite_master,type,main," +string(6) "UPDATE" +string(28) "sqlite_master,rootpage,main," +string(4) "READ" +string(28) "sqlite_master,rootpage,main," +bool(true) +Unable to prepare statement: 23, not authorized +The authorizer callback returned an invalid type: expected int +Unable to prepare statement: 23, not authorized +The authorizer callback returned an invalid value diff --git a/ext/sqlite3/tests/sqlite3_bind_bug68849.phpt b/ext/sqlite3/tests/sqlite3_bind_bug68849.phpt index 7e4a4e8243..179e04d35d 100644 --- a/ext/sqlite3/tests/sqlite3_bind_bug68849.phpt +++ b/ext/sqlite3/tests/sqlite3_bind_bug68849.phpt @@ -8,9 +8,9 @@ Bug #68849 bindValue is not using the right data type $db = new SQLite3(':memory:'); $db->exec("CREATE TABLE test (a INTEGER, b TEXT, c REAL);" . - "INSERT INTO test VALUES (1, 'hello', 3.14);" . - "INSERT INTO test VALUES (3, 'world', 3.15);" . - "INSERT INTO test VALUES (0, '42', 0.42);" + "INSERT INTO test VALUES (1, 'hello', 3.14);" . + "INSERT INTO test VALUES (3, 'world', 3.15);" . + "INSERT INTO test VALUES (0, '42', 0.42);" ); $s = $db->prepare('SELECT * FROM test WHERE (a+2) = ?;'); @@ -34,7 +34,6 @@ $r = $s->execute(); var_dump($r->fetchArray(SQLITE3_ASSOC)); ?> -==DONE== --EXPECT-- array(3) { ["a"]=> @@ -68,4 +67,3 @@ array(3) { ["c"]=> float(3.15) } -==DONE== diff --git a/ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt b/ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt index c35af945db..de7edfbbac 100644 --- a/ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt +++ b/ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt @@ -13,10 +13,10 @@ $insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (1, ?)"); class HelloWrapper { - public function stream_open() { return true; } - public function stream_eof() { return true; } - public function stream_read() { return NULL; } - public function stream_stat() { return array(); } + public function stream_open() { return true; } + public function stream_eof() { return true; } + public function stream_read() { return NULL; } + public function stream_stat() { return array(); } } stream_wrapper_register("hello", "HelloWrapper"); diff --git a/ext/sqlite3/tests/sqlite3_bound_value_at_name.phpt b/ext/sqlite3/tests/sqlite3_bound_value_at_name.phpt index d0eec87a2f..c441b1bc4a 100644 --- a/ext/sqlite3/tests/sqlite3_bound_value_at_name.phpt +++ b/ext/sqlite3/tests/sqlite3_bound_value_at_name.phpt @@ -23,7 +23,7 @@ var_dump($stmt->bindValue('@id', $foo, SQLITE3_TEXT)); $results = $stmt->execute(); while ($result = $results->fetchArray(SQLITE3_NUM)) { - var_dump($result); + var_dump($result); } $results->finalize(); diff --git a/ext/sqlite3/tests/sqlite3_defensive.phpt b/ext/sqlite3/tests/sqlite3_defensive.phpt index 064d87b50a..c8826af24f 100644 --- a/ext/sqlite3/tests/sqlite3_defensive.phpt +++ b/ext/sqlite3/tests/sqlite3_defensive.phpt @@ -4,7 +4,7 @@ SQLite3 defensive mode ini setting <?php require_once(__DIR__ . '/skipif.inc'); if (SQLite3::version()['versionNumber'] < 3026000) { - die("skip: sqlite3 library version < 3.26: no support for defensive mode"); + die("skip: sqlite3 library version < 3.26: no support for defensive mode"); } ?> diff --git a/ext/sqlite3/tests/sqlite3_enable_exceptions.phpt b/ext/sqlite3/tests/sqlite3_enable_exceptions.phpt index 767f9d0065..d921b99dd7 100644 --- a/ext/sqlite3/tests/sqlite3_enable_exceptions.phpt +++ b/ext/sqlite3/tests/sqlite3_enable_exceptions.phpt @@ -17,7 +17,6 @@ try{ } var_dump($db->enableExceptions(false)); $db->query("SELECT * FROM non_existent_table"); -var_dump($db->enableExceptions("wrong_type","wrong_type")); echo "Closing database\n"; var_dump($db->close()); echo "Done\n"; @@ -28,9 +27,6 @@ no such table: non_existent_table bool(true) Warning: SQLite3::query(): no such table: non_existent_table in %s on line %d - -Warning: SQLite3::enableExceptions() expects at most 1 parameter, 2 given in %s on line %d -NULL Closing database bool(true) Done diff --git a/ext/sqlite3/tests/sqlite3_prepare_001.phpt b/ext/sqlite3/tests/sqlite3_prepare_001.phpt index 5142081b3a..f97eaab021 100644 --- a/ext/sqlite3/tests/sqlite3_prepare_001.phpt +++ b/ext/sqlite3/tests/sqlite3_prepare_001.phpt @@ -6,8 +6,8 @@ SQLite3 - memory leak on SQLite3Result and SQLite3Stmt <?php function test(&$x) { - $class = new SQLite3(':memory:'); - $x = $class->prepare('SELECT 1'); + $class = new SQLite3(':memory:'); + $x = $class->prepare('SELECT 1'); } test($foo); diff --git a/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt b/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt index 3f9fe84130..0b677c7378 100644 --- a/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt +++ b/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt @@ -4,7 +4,7 @@ SQLite3Stmt::getSQL expanded test <?php require_once(__DIR__ . '/skipif.inc'); if (SQLite3::version()['versionNumber'] < 3014000) { - die('skip SQLite < 3.14 installed, requires SQLite >= 3.14'); + die('skip SQLite < 3.14 installed, requires SQLite >= 3.14'); } ?> --FILE-- @@ -44,7 +44,7 @@ var_dump($db->close()); echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- Getting expanded SQL statement string(21) "SELECT 42, 'php', 43;" Execute statement diff --git a/ext/sqlite3/tests/sqlite3stmt_paramCount_basic.phpt b/ext/sqlite3/tests/sqlite3stmt_paramCount_basic.phpt index a520f5715b..81eae9e566 100644 --- a/ext/sqlite3/tests/sqlite3stmt_paramCount_basic.phpt +++ b/ext/sqlite3/tests/sqlite3stmt_paramCount_basic.phpt @@ -16,21 +16,21 @@ var_dump($db->exec("INSERT INTO foobar (id, name, city) VALUES (2, 'doe', 'SF')" $queryArray = array( - "SELECT * FROM foobar WHERE id = ? ORDER BY id ASC", - "SELECT * FROM foobar WHERE id = 2 ORDER BY id ASC", - "SELECT * FROM foobar WHERE id = :id AND name = :name ORDER BY id ASC", - "SELECT * FROM foobar WHERE id = 1 AND name = :name ORDER BY id ASC", + "SELECT * FROM foobar WHERE id = ? ORDER BY id ASC", + "SELECT * FROM foobar WHERE id = 2 ORDER BY id ASC", + "SELECT * FROM foobar WHERE id = :id AND name = :name ORDER BY id ASC", + "SELECT * FROM foobar WHERE id = 1 AND name = :name ORDER BY id ASC", ); echo "SELECTING results\n"; foreach($queryArray as $key => $query) { - $stmt = $db->prepare($query); + $stmt = $db->prepare($query); - echo 'Param count for query ' . ($key + 1) . ":\n"; - var_dump($stmt->paramCount()); + echo 'Param count for query ' . ($key + 1) . ":\n"; + var_dump($stmt->paramCount()); - $result = $stmt->execute(); + $result = $stmt->execute(); } echo "Closing database\n"; diff --git a/ext/sqlite3/tests/stream_test.inc b/ext/sqlite3/tests/stream_test.inc index 13fd6f89f9..0d53d0f7be 100644 --- a/ext/sqlite3/tests/stream_test.inc +++ b/ext/sqlite3/tests/stream_test.inc @@ -2,42 +2,42 @@ class SQLite3_Test_Stream { - private $position; - public static $string_length = 10; - public static $string = "abcdefg\0hi"; - - public function stream_open($path, $mode, $options, &$opened_path) - { - $this->position = 0; - return true; - } - - public function stream_read($count) - { - $ret = substr(self::$string, $this->position, $count); - $this->position += strlen($ret); - return $ret; - } - - public function stream_write($data) - { - return 0; - } - - public function stream_stat() - { - return array('size' => self::$string_length); - } - - public function stream_tell() - { - return $this->position; - } - - public function stream_eof() - { - return ($this->position >= self::$string_length); - } + private $position; + public static $string_length = 10; + public static $string = "abcdefg\0hi"; + + public function stream_open($path, $mode, $options, &$opened_path) + { + $this->position = 0; + return true; + } + + public function stream_read($count) + { + $ret = substr(self::$string, $this->position, $count); + $this->position += strlen($ret); + return $ret; + } + + public function stream_write($data) + { + return 0; + } + + public function stream_stat() + { + return array('size' => self::$string_length); + } + + public function stream_tell() + { + return $this->position; + } + + public function stream_eof() + { + return ($this->position >= self::$string_length); + } } stream_wrapper_register('sqliteBlobTest', "SQLite3_Test_Stream") or die("Unable to register sqliteBlobTest stream"); |