diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index 15cb8a8cb303d..7b37ce76a0e33 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -74,8 +74,6 @@ typedef struct _php_sqlite3_db_object { zend_fcall_info authorizer_fci; zend_fcall_info_cache authorizer_fcc; - bool exception; - zend_llist free_list; zend_object zo; } php_sqlite3_db_object; diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 1d00bc758ff0e..fd3a28b94ac47 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -28,6 +28,7 @@ #include #include "zend_exceptions.h" +#include "ext/spl/spl_exceptions.h" #include "SAPI.h" #include "sqlite3_arginfo.h" @@ -38,28 +39,6 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c 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 */ -static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...) -{ - va_list arg; - char *message; - - va_start(arg, format); - vspprintf(&message, 0, format, arg); - va_end(arg); - - if (db_obj && db_obj->exception) { - zend_throw_exception(zend_ce_exception, message, 0); - } else { - php_error_docref(NULL, E_WARNING, "%s", message); - } - - if (message) { - efree(message); - } -} -/* }}} */ - #define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \ if (!(db_obj) || !(member)) { \ zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \ @@ -87,10 +66,29 @@ static zend_object_handlers sqlite3_stmt_object_handlers; static zend_object_handlers sqlite3_result_object_handlers; /* Class entries */ +zend_class_entry *php_sqlite3_exception_ce; zend_class_entry *php_sqlite3_sc_entry; zend_class_entry *php_sqlite3_stmt_entry; zend_class_entry *php_sqlite3_result_entry; +/* {{{ Error Handler */ +static void php_sqlite3_error(int code, char *format, ...) +{ + va_list arg; + char *message; + + va_start(arg, format); + vspprintf(&message, 0, format, arg); + va_end(arg); + + zend_throw_exception(php_sqlite3_exception_ce, message, code); + + if (message) { + efree(message); + } +} +/* }}} */ + /* {{{ Opens a SQLite 3 Database, if the build includes encryption then it will attempt to use the key. */ PHP_METHOD(SQLite3, open) { @@ -189,7 +187,7 @@ PHP_METHOD(SQLite3, close) if(db_obj->db) { errcode = sqlite3_close(db_obj->db); if (errcode != SQLITE_OK) { - php_sqlite3_error(db_obj, "Unable to close database: %d, %s", errcode, sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(errcode, "Unable to close database: %s", sqlite3_errmsg(db_obj->db)); RETURN_FALSE; } } @@ -216,7 +214,7 @@ PHP_METHOD(SQLite3, exec) 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); + php_sqlite3_error(0, "%s", errtext); sqlite3_free(errtext); RETURN_FALSE; } @@ -368,7 +366,7 @@ PHP_METHOD(SQLite3, busyTimeout) #ifdef SQLITE_ENABLE_API_ARMOR return_code = sqlite3_busy_timeout(db_obj->db, ms); if (return_code != SQLITE_OK) { - php_sqlite3_error(db_obj, "Unable to set busy timeout: %d, %s", return_code, sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(return_code, "Unable to set busy timeout: %s", sqlite3_errmsg(db_obj->db)); RETURN_FALSE; } #else @@ -401,18 +399,18 @@ PHP_METHOD(SQLite3, loadExtension) if ((strncmp(sapi_module.name, "cgi", 3) != 0) && (strcmp(sapi_module.name, "cli") != 0) && (strncmp(sapi_module.name, "embed", 5) != 0) - ) { php_sqlite3_error(db_obj, "Not supported in multithreaded Web servers"); + ) { php_sqlite3_error(0, "Not supported in multithreaded Web servers"); RETURN_FALSE; } #endif if (!SQLITE3G(extension_dir)) { - php_sqlite3_error(db_obj, "SQLite Extension are disabled"); + php_sqlite3_error(0, "SQLite Extension are disabled"); RETURN_FALSE; } if (extension_len == 0) { - php_sqlite3_error(db_obj, "Empty string as an extension"); + php_sqlite3_error(0, "Empty string as an extension"); RETURN_FALSE; } @@ -426,7 +424,7 @@ PHP_METHOD(SQLite3, loadExtension) } if (!VCWD_REALPATH(lib_path, fullpath)) { - php_sqlite3_error(db_obj, "Unable to load extension at '%s'", lib_path); + php_sqlite3_error(0, "Unable to load extension at '%s'", lib_path); efree(lib_path); RETURN_FALSE; } @@ -434,14 +432,14 @@ PHP_METHOD(SQLite3, loadExtension) efree(lib_path); if (strncmp(fullpath, extension_dir, extension_dir_len) != 0) { - php_sqlite3_error(db_obj, "Unable to open extensions outside the defined directory"); + php_sqlite3_error(0, "Unable to open extensions outside the defined directory"); RETURN_FALSE; } /* Extension loading should only be enabled for when we attempt to load */ sqlite3_enable_load_extension(db_obj->db, 1); if (sqlite3_load_extension(db_obj->db, fullpath, 0, &errtext) != SQLITE_OK) { - php_sqlite3_error(db_obj, "%s", errtext); + php_sqlite3_error(0, "%s", errtext); sqlite3_free(errtext); sqlite3_enable_load_extension(db_obj->db, 0); RETURN_FALSE; @@ -521,7 +519,7 @@ PHP_METHOD(SQLite3, prepare) errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (errcode != SQLITE_OK) { - php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", errcode, sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(errcode, "Unable to prepare statement: %s", sqlite3_errmsg(db_obj->db)); zval_ptr_dtor(return_value); RETURN_FALSE; } @@ -562,7 +560,7 @@ PHP_METHOD(SQLite3, query) /* If there was no return value then just execute the query */ if (!USED_RET()) { if (sqlite3_exec(db_obj->db, ZSTR_VAL(sql), NULL, NULL, &errtext) != SQLITE_OK) { - php_sqlite3_error(db_obj, "%s", errtext); + php_sqlite3_error(0, "%s", errtext); sqlite3_free(errtext); } RETURN_FALSE; @@ -575,7 +573,7 @@ PHP_METHOD(SQLite3, query) return_code = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (return_code != SQLITE_OK) { - php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", return_code, sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(return_code, "Unable to prepare statement: %s", sqlite3_errmsg(db_obj->db)); zval_ptr_dtor(&stmt); RETURN_FALSE; } @@ -606,7 +604,7 @@ PHP_METHOD(SQLite3, query) } default: if (!EG(exception)) { - php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(0, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db)); } sqlite3_finalize(stmt_obj->stmt); stmt_obj->initialised = 0; @@ -678,7 +676,7 @@ PHP_METHOD(SQLite3, querySingle) /* If there was no return value then just execute the query */ if (!USED_RET()) { if (sqlite3_exec(db_obj->db, ZSTR_VAL(sql), NULL, NULL, &errtext) != SQLITE_OK) { - php_sqlite3_error(db_obj, "%s", errtext); + php_sqlite3_error(0, "%s", errtext); sqlite3_free(errtext); } RETURN_FALSE; @@ -686,7 +684,7 @@ PHP_METHOD(SQLite3, querySingle) return_code = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &stmt, NULL); if (return_code != SQLITE_OK) { - php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", return_code, sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(return_code, "Unable to prepare statement: %s", sqlite3_errmsg(db_obj->db)); RETURN_FALSE; } @@ -719,7 +717,7 @@ PHP_METHOD(SQLite3, querySingle) } default: if (!EG(exception)) { - php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(0, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db)); } RETVAL_FALSE; } @@ -794,7 +792,7 @@ static int sqlite3_do_callback(struct php_sqlite3_fci *fc, zval *cb, int argc, s fc->fci.params = zargs; if ((ret = zend_call_function(&fc->fci, &fc->fcc)) == FAILURE) { - php_error_docref(NULL, E_WARNING, "An error occurred while invoking the callback"); + php_sqlite3_error(0, "An error occurred while invoking the callback"); } if (is_agg) { @@ -922,7 +920,7 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in collation->fci.fci.params = zargs; if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc)) == FAILURE) { - php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback"); + php_sqlite3_error(0, "An error occurred while invoking the compare callback"); } zval_ptr_dtor(&zargs[0]); @@ -934,7 +932,7 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in //retval ought to contain a ZVAL_LONG by now // (the result of a comparison, i.e. most likely -1, 0, or 1) //I suppose we could accept any scalar return type, though. - php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback (invalid return type). Collation behaviour is undefined."); + php_sqlite3_error(0, "An error occurred while invoking the compare callback (invalid return type). Collation behaviour is undefined."); } else { ret = Z_LVAL(retval); } @@ -1082,12 +1080,12 @@ static ssize_t php_sqlite3_stream_write(php_stream *stream, const char *buf, siz php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract; if (sqlite3_stream->flags & SQLITE_OPEN_READONLY) { - php_error_docref(NULL, E_WARNING, "Can't write to blob stream: is open as read only"); + php_sqlite3_error(0, "Can't write to blob stream: is open as read only"); return -1; } if (sqlite3_stream->position + count > sqlite3_stream->size) { - php_error_docref(NULL, E_WARNING, "It is not possible to increase the size of a BLOB"); + php_sqlite3_error(0, "It is not possible to increase the size of a BLOB"); return -1; } @@ -1252,8 +1250,11 @@ PHP_METHOD(SQLite3, openBlob) sqlite_flags = (flags & SQLITE_OPEN_READWRITE) ? 1 : 0; - if (sqlite3_blob_open(db_obj->db, dbname, table, column, rowid, sqlite_flags, &blob) != SQLITE_OK) { - php_sqlite3_error(db_obj, "Unable to open blob: %s", sqlite3_errmsg(db_obj->db)); + int rc; + rc = sqlite3_blob_open(db_obj->db, dbname, table, column, rowid, sqlite_flags, &blob); + + if (rc != SQLITE_OK) { + php_sqlite3_error(rc, "Unable to open blob: %s", sqlite3_errmsg(db_obj->db)); RETURN_FALSE; } @@ -1277,24 +1278,6 @@ PHP_METHOD(SQLite3, openBlob) } /* }}} */ -/* {{{ Enables an exception error mode. */ -PHP_METHOD(SQLite3, enableExceptions) -{ - php_sqlite3_db_object *db_obj; - zval *object = ZEND_THIS; - bool enableExceptions = 0; - - db_obj = Z_SQLITE3_DB_P(object); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &enableExceptions) == FAILURE) { - RETURN_THROWS(); - } - - RETVAL_BOOL(db_obj->exception); - - db_obj->exception = 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) @@ -1369,13 +1352,13 @@ PHP_METHOD(SQLite3, backup) if (rc != SQLITE_OK) { if (rc == SQLITE_BUSY) { - php_sqlite3_error(source_obj, "Backup failed: source database is busy"); + php_sqlite3_error(rc, "Backup failed: source database is busy"); } else if (rc == SQLITE_LOCKED) { - php_sqlite3_error(source_obj, "Backup failed: source database is locked"); + php_sqlite3_error(rc, "Backup failed: source database is locked"); } else { - php_sqlite3_error(source_obj, "Backup failed: %d, %s", rc, sqlite3_errmsg(source_obj->db)); + php_sqlite3_error(rc, "Backup failed: %s", sqlite3_errmsg(source_obj->db)); } RETURN_FALSE; } @@ -1433,7 +1416,7 @@ PHP_METHOD(SQLite3Stmt, reset) SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt); if (sqlite3_reset(stmt_obj->stmt) != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); + php_sqlite3_error(0, "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); RETURN_FALSE; } RETURN_TRUE; @@ -1453,7 +1436,7 @@ PHP_METHOD(SQLite3Stmt, clear) SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt); if (sqlite3_clear_bindings(stmt_obj->stmt) != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to clear statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); + php_sqlite3_error(0, "Unable to clear statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); RETURN_FALSE; } @@ -1506,7 +1489,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ if (Z_TYPE_P(parameter) == IS_NULL) { return_code = sqlite3_bind_null(stmt_obj->stmt, param->param_number); if (return_code != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code); + php_sqlite3_error(return_code, "Unable to bind parameter number " ZEND_LONG_FMT " ", param->param_number); } continue; } @@ -1520,7 +1503,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ return_code = sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(parameter)); #endif if (return_code != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code); + php_sqlite3_error(return_code, "Unable to bind parameter number " ZEND_LONG_FMT " ", param->param_number); } break; @@ -1528,7 +1511,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ convert_to_double(parameter); return_code = sqlite3_bind_double(stmt_obj->stmt, param->param_number, Z_DVAL_P(parameter)); if (return_code != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code); + php_sqlite3_error(return_code, "Unable to bind parameter number " ZEND_LONG_FMT " ", param->param_number); } break; @@ -1539,7 +1522,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ if (Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream_from_zval_no_verify(stream, parameter); if (stream == NULL) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to read stream for parameter %ld", param->param_number); + php_sqlite3_error(0, "Unable to read stream for parameter %ld", param->param_number); return FAILURE; } buffer = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); @@ -1551,12 +1534,12 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ return_code = sqlite3_bind_blob(stmt_obj->stmt, param->param_number, ZSTR_VAL(buffer), ZSTR_LEN(buffer), SQLITE_TRANSIENT); zend_string_release_ex(buffer, 0); if (return_code != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code); + php_sqlite3_error(return_code, "Unable to bind parameter number " ZEND_LONG_FMT " ", param->param_number); } } else { return_code = sqlite3_bind_null(stmt_obj->stmt, param->param_number); if (return_code != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code); + php_sqlite3_error(return_code, "Unable to bind parameter number " ZEND_LONG_FMT " ", param->param_number); } } break; @@ -1569,7 +1552,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ } return_code = sqlite3_bind_text(stmt_obj->stmt, param->param_number, ZSTR_VAL(str), ZSTR_LEN(str), SQLITE_TRANSIENT); if (return_code != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code); + php_sqlite3_error(return_code, "Unable to bind parameter number " ZEND_LONG_FMT " ", param->param_number); } zend_string_release(str); break; @@ -1578,12 +1561,12 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ case SQLITE_NULL: return_code = sqlite3_bind_null(stmt_obj->stmt, param->param_number); if (return_code != SQLITE_OK) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to bind parameter number " ZEND_LONG_FMT " (%d)", param->param_number, return_code); + php_sqlite3_error(return_code, "Unable to bind parameter number " ZEND_LONG_FMT " ", param->param_number); } break; default: - php_sqlite3_error(stmt_obj->db_obj, "Unknown parameter type: %pd for parameter %pd", param->type, param->param_number); + php_sqlite3_error(0, "Unknown parameter type: %pd for parameter %pd", param->type, param->param_number); return FAILURE; } } ZEND_HASH_FOREACH_END(); @@ -1623,7 +1606,7 @@ PHP_METHOD(SQLite3Stmt, getSQL) RETVAL_STRING(sql); sqlite3_free(sql); #else - php_sqlite3_error(stmt_obj->db_obj, "The expanded parameter requires SQLite3 >= 3.14 and %s is installed", sqlite3_libversion()); + php_sqlite3_error(0, "The expanded parameter requires SQLite3 >= 3.14 and %s is installed", sqlite3_libversion()); RETURN_FALSE; #endif } else { @@ -1805,7 +1788,7 @@ PHP_METHOD(SQLite3Stmt, execute) ZEND_FALLTHROUGH; default: if (!EG(exception)) { - php_sqlite3_error(stmt_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); + php_sqlite3_error(0, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt))); } zval_ptr_dtor(return_value); RETURN_FALSE; @@ -1848,7 +1831,7 @@ PHP_METHOD(SQLite3Stmt, __construct) errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (errcode != SQLITE_OK) { - php_sqlite3_error(db_obj, "Unable to prepare statement: %d, %s", errcode, sqlite3_errmsg(db_obj->db)); + php_sqlite3_error(errcode, "Unable to prepare statement: %s", sqlite3_errmsg(db_obj->db)); zval_ptr_dtor(return_value); RETURN_FALSE; } @@ -1992,7 +1975,7 @@ PHP_METHOD(SQLite3Result, fetchArray) break; default: - php_sqlite3_error(result_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt))); + php_sqlite3_error(0, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt))); } } /* }}} */ @@ -2132,15 +2115,15 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c 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"); + php_sqlite3_error(0, "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"); + php_sqlite3_error(0, "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"); + php_sqlite3_error(0, "The authorizer callback returned an invalid value"); authreturn = SQLITE_DENY; } } @@ -2349,10 +2332,12 @@ static void sqlite3_param_dtor(zval *data) /* {{{ */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(sqlite3) { + php_sqlite3_exception_ce = register_class_SQLite3Exception(spl_ce_RuntimeException); + #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."); + php_sqlite3_error(0, "A thread safe version of SQLite is required when using a thread safe version of PHP."); return FAILURE; } #endif @@ -2414,6 +2399,13 @@ PHP_MINFO_FUNCTION(sqlite3) } /* }}} */ +/* {{{ */ +static const zend_module_dep sqlite3_deps[] = { + ZEND_MOD_REQUIRED("spl") + ZEND_MOD_END +}; +/* }}} */ + /* {{{ PHP_GINIT_FUNCTION */ static PHP_GINIT_FUNCTION(sqlite3) { @@ -2426,7 +2418,8 @@ static PHP_GINIT_FUNCTION(sqlite3) /* {{{ sqlite3_module_entry */ zend_module_entry sqlite3_module_entry = { - STANDARD_MODULE_HEADER, + STANDARD_MODULE_HEADER_EX, NULL, + sqlite3_deps, "sqlite3", NULL, PHP_MINIT(sqlite3), diff --git a/ext/sqlite3/sqlite3.stub.php b/ext/sqlite3/sqlite3.stub.php index 8c8bf7edce5df..e108e4e764c8d 100644 --- a/ext/sqlite3/sqlite3.stub.php +++ b/ext/sqlite3/sqlite3.stub.php @@ -68,6 +68,12 @@ const SQLITE3_DETERMINISTIC = UNKNOWN; #endif +class SQLite3Exception extends RuntimeException +{ + /** @var int|string */ + protected $code = 0; +} + /** @not-serializable */ class SQLite3 { @@ -335,9 +341,6 @@ public function createCollation(string $name, callable $callback): bool {} /** @return resource|false */ public function openBlob(string $table, string $column, int $rowid, string $database = "main", int $flags = SQLITE3_OPEN_READONLY) {} - /** @tentative-return-type */ - public function enableExceptions(bool $enable = false): bool {} - /** @tentative-return-type */ public function enableExtendedResultCodes(bool $enable = true): bool {} diff --git a/ext/sqlite3/sqlite3_arginfo.h b/ext/sqlite3/sqlite3_arginfo.h index 4091374dee78c..c21baceaca4d4 100644 --- a/ext/sqlite3/sqlite3_arginfo.h +++ b/ext/sqlite3/sqlite3_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: bdee592c8babbc221080c6ea2d73f94b2b79274a */ + * Stub hash: aff185e82ef4476d6da91191e78473ee03ea930a */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -97,10 +97,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3_openBlob, 0, 0, 3) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "SQLITE3_OPEN_READONLY") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SQLite3_enableExceptions, 0, 0, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "false") -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SQLite3_enableExtendedResultCodes, 0, 0, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() @@ -189,7 +185,6 @@ 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); @@ -211,6 +206,11 @@ ZEND_METHOD(SQLite3Result, reset); ZEND_METHOD(SQLite3Result, finalize); +static const zend_function_entry class_SQLite3Exception_methods[] = { + ZEND_FE_END +}; + + 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) @@ -237,7 +237,6 @@ static const zend_function_entry class_SQLite3_methods[] = { 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 @@ -288,6 +287,22 @@ static void register_sqlite3_symbols(int module_number) #endif } +static zend_class_entry *register_class_SQLite3Exception(zend_class_entry *class_entry_RuntimeException) +{ + zend_class_entry ce, *class_entry; + + INIT_CLASS_ENTRY(ce, "SQLite3Exception", class_SQLite3Exception_methods); + class_entry = zend_register_internal_class_ex(&ce, class_entry_RuntimeException); + + zval property_code_default_value; + ZVAL_LONG(&property_code_default_value, 0); + zend_string *property_code_name = zend_string_init("code", sizeof("code") - 1, 1); + zend_declare_property_ex(class_entry, property_code_name, &property_code_default_value, ZEND_ACC_PROTECTED, NULL); + zend_string_release(property_code_name); + + return class_entry; +} + static zend_class_entry *register_class_SQLite3(void) { zend_class_entry ce, *class_entry; diff --git a/ext/sqlite3/tests/bug69972.phpt b/ext/sqlite3/tests/bug69972.phpt index 3c926a11ab5bb..d04d66f011c87 100644 --- a/ext/sqlite3/tests/bug69972.phpt +++ b/ext/sqlite3/tests/bug69972.phpt @@ -6,7 +6,13 @@ sqlite3 query("SELECT * FROM non_existent_table"); + +try { + $result = $db->query("SELECT * FROM non_existent_table"); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} echo "Closing database\n"; var_dump($db->close()); echo "Done\n"; @@ -17,8 +23,7 @@ echo "Error Msg: " . $db->lastErrorMsg() . "\n"; ?> --EXPECTF-- SELECTING from invalid table - -Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %sbug69972.php on line %d +Unable to prepare statement: no such table: non_existent_table Closing database bool(true) Done diff --git a/ext/sqlite3/tests/bug77051.phpt b/ext/sqlite3/tests/bug77051.phpt index 7b44516b7fdf1..d2e4ebcbdd13f 100644 --- a/ext/sqlite3/tests/bug77051.phpt +++ b/ext/sqlite3/tests/bug77051.phpt @@ -6,7 +6,6 @@ sqlite3 enableExceptions(true); $stmt = $db->prepare('SELECT :a, :b, ?;'); diff --git a/ext/sqlite3/tests/gh9032.phpt b/ext/sqlite3/tests/gh9032.phpt index 069e080406403..888d020eeb179 100644 --- a/ext/sqlite3/tests/gh9032.phpt +++ b/ext/sqlite3/tests/gh9032.phpt @@ -7,7 +7,6 @@ open_basedir=. --FILE-- enableExceptions(true); $db->exec('attach database \':memory:\' AS "db1"'); var_dump($db->exec('create table db1.r (id int)')); @@ -23,4 +22,4 @@ try { ?> --EXPECT-- bool(true) -Unable to prepare statement: 23, not authorized +Unable to prepare statement: not authorized diff --git a/ext/sqlite3/tests/sqlite3_02_create.phpt b/ext/sqlite3/tests/sqlite3_02_create.phpt index afe7dcf49d23d..d974ee4fe26c9 100644 --- a/ext/sqlite3/tests/sqlite3_02_create.phpt +++ b/ext/sqlite3/tests/sqlite3_02_create.phpt @@ -11,7 +11,13 @@ echo "Creating Table\n"; var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); echo "Creating Same Table Again\n"; -var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); + +try { + var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)')); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} echo "Dropping database\n"; var_dump($db->exec('DROP TABLE test')); @@ -24,9 +30,7 @@ echo "Done\n"; Creating Table bool(true) Creating Same Table Again - -Warning: SQLite3::exec(): table test already exists in %s on line %d -bool(false) +table test already exists Dropping database bool(true) Closing database diff --git a/ext/sqlite3/tests/sqlite3_20_error.phpt b/ext/sqlite3/tests/sqlite3_20_error.phpt index f5fb9a890c064..8850648b99d34 100644 --- a/ext/sqlite3/tests/sqlite3_20_error.phpt +++ b/ext/sqlite3/tests/sqlite3_20_error.phpt @@ -8,7 +8,15 @@ sqlite3 require_once(__DIR__ . '/new_db.inc'); echo "SELECTING from invalid table\n"; -$result = $db->query("SELECT * FROM non_existent_table"); +$result = null; + +try { + $result = $db->query("SELECT * FROM non_existent_table"); +} +catch (SQLite3Exception $e) { + echo $e->getCode() . ": " . $e->getMessage() . "\n"; +} + if (!$result) { echo "Error Code: " . $db->lastErrorCode() . "\n"; echo "Error Msg: " . $db->lastErrorMsg() . "\n"; @@ -19,8 +27,7 @@ echo "Done\n"; ?> --EXPECTF-- SELECTING from invalid table - -Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %s on line %d +1: Unable to prepare statement: no such table: non_existent_table Error Code: 1 Error Msg: no such table: non_existent_table Closing database diff --git a/ext/sqlite3/tests/sqlite3_22_loadextension.phpt b/ext/sqlite3/tests/sqlite3_22_loadextension.phpt index cdc7f4d4dc6ea..872f674aee296 100644 --- a/ext/sqlite3/tests/sqlite3_22_loadextension.phpt +++ b/ext/sqlite3/tests/sqlite3_22_loadextension.phpt @@ -21,14 +21,18 @@ $directory = __DIR__; touch($directory . '/myext.txt'); -var_dump($db->loadExtension('myext.txt')); +try { + var_dump($db->loadExtension('myext.txt')); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} var_dump($db->close()); unlink($directory . '/myext.txt'); echo "Done\n"; ?> --EXPECTF-- -Warning: SQLite3::loadExtension(): Unable to load extension at '.%emyext.txt' in %s on line %d -bool(false) +Unable to load extension at '.%emyext.txt' bool(true) Done diff --git a/ext/sqlite3/tests/sqlite3_30_blobopen.phpt b/ext/sqlite3/tests/sqlite3_30_blobopen.phpt index 6937dcd927f27..76b290669f3c5 100644 --- a/ext/sqlite3/tests/sqlite3_30_blobopen.phpt +++ b/ext/sqlite3/tests/sqlite3_30_blobopen.phpt @@ -26,7 +26,12 @@ var_dump($stream); echo "Stream Contents\n"; var_dump(stream_get_contents($stream)); echo "Writing to read-only stream\n"; -var_dump(fwrite($stream, 'ABCD')); +try { + var_dump(fwrite($stream, 'ABCD')); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} echo "Closing Stream\n"; var_dump(fclose($stream)); echo "Opening stream in write mode\n"; @@ -38,7 +43,12 @@ echo "Stream Contents\n"; fseek($stream, 0); var_dump(stream_get_contents($stream)); echo "Expanding blob size\n"; -var_dump(fwrite($stream, 'ABCD ABCD ABCD')); +try { + var_dump(fwrite($stream, 'ABCD ABCD ABCD')); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} echo "Closing Stream\n"; var_dump(fclose($stream)); echo "Closing database\n"; @@ -58,9 +68,7 @@ resource(%d) of type (stream) Stream Contents string(9) "TEST TEST" Writing to read-only stream - -Warning: fwrite(): Can't write to blob stream: is open as read only in %s on line %d -bool(false) +Can't write to blob stream: is open as read only Closing Stream bool(true) Opening stream in write mode @@ -70,9 +78,7 @@ int(4) Stream Contents string(9) "ABCD TEST" Expanding blob size - -Warning: fwrite(): It is not possible to increase the size of a BLOB in %s on line %d -bool(false) +It is not possible to increase the size of a BLOB Closing Stream bool(true) Closing database diff --git a/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt b/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt index bb63e418c64cb..7c04059d2dcc0 100644 --- a/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt +++ b/ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt @@ -20,10 +20,10 @@ $db = new SQLite3(':memory:'); try { $db->loadExtension(""); -} catch (Extension $ex) { - var_dump($ex->getMessage()); +} catch (SQLite3Exception $ex) { + echo $ex->getMessage() . "\n"; } ?> --EXPECTF-- -Warning: SQLite3::loadExtension(): Empty string as an extension in %s on line %d +Empty string as an extension 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 1135d1b702b15..02dfe39f2fcb0 100644 --- a/ext/sqlite3/tests/sqlite3_34_load_extension_ext_dir.phpt +++ b/ext/sqlite3/tests/sqlite3_34_load_extension_ext_dir.phpt @@ -18,10 +18,10 @@ $db = new SQLite3(':memory:'); try { $db->loadExtension(""); -} catch (Extension $ex) { - var_dump($ex->getMessage()); +} catch (SQLite3Exception $ex) { + echo $ex->getMessage() . "\n"; } ?> --EXPECTF-- -Warning: SQLite3::loadExtension(): SQLite Extension are disabled in %s on line %d +SQLite Extension are disabled diff --git a/ext/sqlite3/tests/sqlite3_38_backup.phpt b/ext/sqlite3/tests/sqlite3_38_backup.phpt index 54ca9e95c2317..d1c0425bf6320 100644 --- a/ext/sqlite3/tests/sqlite3_38_backup.phpt +++ b/ext/sqlite3/tests/sqlite3_38_backup.phpt @@ -35,7 +35,13 @@ echo "Locking DB1\n"; var_dump($db->exec('BEGIN EXCLUSIVE;')); echo "Backup to DB2 (should fail)\n"; -var_dump($db->backup($db2)); + +try { + var_dump($db->backup($db2)); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} ?> --EXPECTF-- @@ -53,6 +59,4 @@ Resetting DB2 Locking DB1 bool(true) Backup to DB2 (should fail) - -Warning: SQLite3::backup(): Backup failed: source database is busy in %s on line %d -bool(false) \ No newline at end of file +Backup failed: source database is busy \ No newline at end of file diff --git a/ext/sqlite3/tests/sqlite3_38_extended_error.phpt b/ext/sqlite3/tests/sqlite3_38_extended_error.phpt index 433e1efce0475..8634b0da54c04 100644 --- a/ext/sqlite3/tests/sqlite3_38_extended_error.phpt +++ b/ext/sqlite3/tests/sqlite3_38_extended_error.phpt @@ -10,11 +10,25 @@ require_once(__DIR__ . '/new_db.inc'); $db->query("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )"); echo "Inserting first time which should succeed" . PHP_EOL; -$result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); + +try { + $result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} + echo "First Error Code: " . $db->lastErrorCode() . PHP_EOL; echo "Inserting second time which should fail" . PHP_EOL; -$result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); + +try { + $result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} + echo "Second Error Code: " . $db->lastErrorCode() . PHP_EOL; echo "Second Extended Error Code: " . $db->lastExtendedErrorCode() . PHP_EOL; @@ -26,8 +40,7 @@ echo "Done" . PHP_EOL; Inserting first time which should succeed First Error Code: 0 Inserting second time which should fail - -Warning: SQLite3::query(): Unable to execute statement: UNIQUE constraint failed: dog.id in %s on line %d +Unable to execute statement: UNIQUE constraint failed: dog.id Second Error Code: 19 Second Extended Error Code: 1555 Closing database diff --git a/ext/sqlite3/tests/sqlite3_39_toggleExtended.phpt b/ext/sqlite3/tests/sqlite3_39_toggleExtended.phpt index 135c1cdd10953..aebe41fe953bf 100644 --- a/ext/sqlite3/tests/sqlite3_39_toggleExtended.phpt +++ b/ext/sqlite3/tests/sqlite3_39_toggleExtended.phpt @@ -14,12 +14,22 @@ $result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); echo "First Error Code: " . $db->lastErrorCode() . PHP_EOL; echo "Inserting second time which should fail" . PHP_EOL; -$result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +try { + $result = $db->query("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} echo "Second Error Code: " . $db->lastErrorCode() . PHP_EOL; echo "Toggling extended error codes and re-inserting a third time" . PHP_EOL; $db->enableExtendedResultCodes(true); -$result = $db->query("INSERT INTO DOG VALUES (1, 'Annoying Dog', 1)"); +try { + $result = $db->query("INSERT INTO DOG VALUES (1, 'Annoying Dog', 1)"); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} echo "Third (Extended) Error Code: " . $db->lastErrorCode() . PHP_EOL; echo "Closing database\n"; @@ -30,12 +40,10 @@ echo "Done" . PHP_EOL; Inserting first time which should succeed First Error Code: 0 Inserting second time which should fail - -Warning: SQLite3::query(): Unable to execute statement: UNIQUE constraint failed: dog.id in %s on line %d +Unable to execute statement: UNIQUE constraint failed: dog.id Second Error Code: 19 Toggling extended error codes and re-inserting a third time - -Warning: SQLite3::query(): Unable to execute statement: UNIQUE constraint failed: dog.id in %s on line %d +Unable to execute statement: UNIQUE constraint failed: dog.id Third (Extended) Error Code: 1555 Closing database bool(true) diff --git a/ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt b/ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt index 73fcc790c0f6a..fcc4462679d53 100644 --- a/ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt +++ b/ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt @@ -6,7 +6,6 @@ sqlite3 enableExceptions(true); $db->setAuthorizer(function (int $action) { if ($action == SQLite3::SELECT) { @@ -22,7 +21,7 @@ var_dump($db->querySingle('SELECT 1;')); try { // This one should fail var_dump($db->querySingle('CREATE TABLE test (a, b);')); -} catch (\Exception $e) { +} catch (SQLite3Exception $e) { echo $e->getMessage() . "\n"; } @@ -52,7 +51,7 @@ $db->setAuthorizer(function () { try { var_dump($db->querySingle('SELECT 1;')); -} catch (\Exception $e) { +} catch (SQLite3Exception $e) { echo $e->getMessage() . "\n"; echo $e->getPrevious()->getMessage() . "\n"; } @@ -63,7 +62,7 @@ $db->setAuthorizer(function () { try { var_dump($db->querySingle('SELECT 1;')); -} catch (\Exception $e) { +} catch (SQLite3Exception $e) { echo $e->getMessage() . "\n"; echo $e->getPrevious()->getMessage() . "\n"; } @@ -71,7 +70,7 @@ try { ?> --EXPECT-- int(1) -Unable to prepare statement: 23, not authorized +Unable to prepare statement: not authorized bool(true) int(42) string(6) "SELECT" @@ -98,7 +97,7 @@ string(28) "sqlite_master,rootpage,main," string(4) "READ" string(28) "sqlite_master,rootpage,main," bool(true) -Unable to prepare statement: 23, not authorized +Unable to prepare statement: not authorized The authorizer callback returned an invalid type: expected int -Unable to prepare statement: 23, not authorized +Unable to prepare statement: not authorized The authorizer callback returned an invalid value diff --git a/ext/sqlite3/tests/sqlite3_defensive.phpt b/ext/sqlite3/tests/sqlite3_defensive.phpt index 033e661d8a393..5639e3b6356ca 100644 --- a/ext/sqlite3/tests/sqlite3_defensive.phpt +++ b/ext/sqlite3/tests/sqlite3_defensive.phpt @@ -26,7 +26,12 @@ var_dump($db->querySingle('PRAGMA writable_schema;')); var_dump($db->querySingle('SELECT COUNT(*) FROM sqlite_master;')); // Should generate an error! -var_dump($db->querySingle('DELETE FROM sqlite_master;')); +try { + var_dump($db->querySingle('DELETE FROM sqlite_master;')); +} +catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} // Should still be 1 var_dump($db->querySingle('SELECT COUNT(*) FROM sqlite_master;')); @@ -36,7 +41,5 @@ bool(true) bool(true) int(1) int(1) - -Warning: SQLite3::querySingle(): Unable to prepare statement: 1, table sqlite_master may not be modified in %s on line %d -bool(false) +Unable to prepare statement: table sqlite_master may not be modified int(1) \ No newline at end of file diff --git a/ext/sqlite3/tests/sqlite3_enable_exceptions.phpt b/ext/sqlite3/tests/sqlite3_enable_exceptions.phpt deleted file mode 100644 index 0199b798e020e..0000000000000 --- a/ext/sqlite3/tests/sqlite3_enable_exceptions.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -SQLite3::enableExceptions test ---CREDITS-- -Thijs Feryn -#TestFest PHPBelgium 2009 ---EXTENSIONS-- -sqlite3 ---FILE-- -enableExceptions(true)); -try{ - $db->query("SELECT * FROM non_existent_table"); -} catch(Exception $e) { - echo $e->getMessage().PHP_EOL; -} -var_dump($db->enableExceptions(false)); -$db->query("SELECT * FROM non_existent_table"); -echo "Closing database\n"; -var_dump($db->close()); -echo "Done\n"; -?> ---EXPECTF-- -bool(false) -no such table: non_existent_table -bool(true) - -Warning: SQLite3::query(): no such table: non_existent_table in %s on line %d -Closing database -bool(true) -Done diff --git a/ext/sqlite3/tests/sqlite3_prepare_faultystmt.phpt b/ext/sqlite3/tests/sqlite3_prepare_faultystmt.phpt index 27a548a8aad9f..6185913df913d 100644 --- a/ext/sqlite3/tests/sqlite3_prepare_faultystmt.phpt +++ b/ext/sqlite3/tests/sqlite3_prepare_faultystmt.phpt @@ -11,10 +11,12 @@ $db = new SQLite3(':memory:'); $db->exec('CREATE TABLE foo (id INTEGER, bar STRING)'); $db->exec("INSERT INTO foo (id, bar) VALUES (1, 'This is a test')"); -$stmt = $db->prepare('SELECT foo FROM bar'); +try { + $stmt = $db->prepare('SELECT foo FROM bar'); +} catch (SQLite3Exception $e) { + echo $e->getMessage() . "\n"; +} -var_dump($stmt); ?> --EXPECTF-- -Warning: SQLite3::prepare(): Unable to prepare statement: 1, no such table: bar in %s on line %d -bool(false) +Unable to prepare statement: no such table: bar diff --git a/ext/sqlite3/tests/sqlite3stmt_getsql.phpt b/ext/sqlite3/tests/sqlite3stmt_getsql.phpt index c45e724242d16..98a274dc0173d 100644 --- a/ext/sqlite3/tests/sqlite3stmt_getsql.phpt +++ b/ext/sqlite3/tests/sqlite3stmt_getsql.phpt @@ -7,8 +7,6 @@ sqlite3 require_once(__DIR__ . '/new_db.inc'); -$db->enableExceptions(true); - $stmt = $db->prepare('SELECT :a, :b, ?;'); $stmt->bindValue(':a', 42); diff --git a/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt b/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt index 7ab3019f7bddb..bd57f6d74858f 100644 --- a/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt +++ b/ext/sqlite3/tests/sqlite3stmt_getsql_expanded.phpt @@ -13,8 +13,6 @@ if (SQLite3::version()['versionNumber'] < 3014000) { require_once(__DIR__ . '/new_db.inc'); -$db->enableExceptions(true); - $stmt = $db->prepare('SELECT :a, :b, ?;'); $stmt->bindValue(':a', 42);