diff options
author | George Peter Banyard <girgias@php.net> | 2020-12-24 01:45:58 +0100 |
---|---|---|
committer | George Peter Banyard <girgias@php.net> | 2021-01-06 10:20:57 +0000 |
commit | 1a58611ae54fba45f7cf6b16ef921f7ad6c3d4b9 (patch) | |
tree | 7f43d5acc1f98a3ce5bda868febb1ea268d854be | |
parent | 60a61afd3c40f029c6bb679754d13f71d63e3283 (diff) | |
download | php-git-1a58611ae54fba45f7cf6b16ef921f7ad6c3d4b9.tar.gz |
Voidify PDO's fetch_error handler
-rw-r--r-- | ext/pdo/pdo_dbh.c | 17 | ||||
-rw-r--r-- | ext/pdo/php_pdo_driver.h | 13 | ||||
-rw-r--r-- | ext/pdo_dblib/dblib_driver.c | 6 | ||||
-rw-r--r-- | ext/pdo_firebird/firebird_driver.c | 3 | ||||
-rw-r--r-- | ext/pdo_mysql/mysql_driver.c | 4 | ||||
-rw-r--r-- | ext/pdo_oci/oci_driver.c | 4 | ||||
-rw-r--r-- | ext/pdo_odbc/odbc_driver.c | 4 | ||||
-rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 5 | ||||
-rw-r--r-- | ext/pdo_sqlite/sqlite_driver.c | 4 |
9 files changed, 26 insertions, 34 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index e64c151f85..a53c9f052d 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -148,21 +148,20 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */ ZVAL_UNDEF(&info); if (dbh->methods->fetch_err) { + zval *item; array_init(&info); add_next_index_string(&info, *pdo_err); - if (dbh->methods->fetch_err(dbh, stmt, &info)) { - zval *item; + dbh->methods->fetch_err(dbh, stmt, &info); - if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL - && Z_TYPE_P(item) == IS_LONG) { - native_code = Z_LVAL_P(item); - } + if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL + && Z_TYPE_P(item) == IS_LONG) { + native_code = Z_LVAL_P(item); + } - if ((item = zend_hash_index_find(Z_ARRVAL(info), 2)) != NULL) { - supp = estrndup(Z_STRVAL_P(item), Z_STRLEN_P(item)); - } + if ((item = zend_hash_index_find(Z_ARRVAL(info), 2)) != NULL) { + supp = estrndup(Z_STRVAL_P(item), Z_STRLEN_P(item)); } } diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index a0e85b589e..c6bdf49f8e 100644 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -250,13 +250,16 @@ typedef bool (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val) * MUST be an emalloc'd NULL terminated string. */ typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, size_t *len); -/* fetch error information. if stmt is not null, fetch information pertaining - * to the statement, otherwise fetch global error information. The driver - * should add the following information to the array "info" in this order: +/* Fetch error information. + * If stmt is not null, fetch information pertaining to the statement, + * otherwise fetch global error information. + * info is an initialized PHP array, if there are no messages leave it empty. + * The driver should add the following information to the array "info" in this order: * - native error code * - string representation of the error code ... any other optional driver - * specific data ... */ -typedef int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info); + * specific data ... + * PDO takes care of normalizing the array. */ +typedef void (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info); /* fetching of attributes * There are 3 return states: diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index 6d65b6f927..00ba5308fc 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -31,7 +31,7 @@ /* Cache of the server supported datatypes, initialized in handle_factory */ zval* pdo_dblib_datatypes; -static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) +static void dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; pdo_dblib_err *einfo = &H->err; @@ -55,7 +55,7 @@ static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* don't return anything if there's nothing to return */ if (msg == NULL && einfo->dberr == 0 && einfo->oserr == 0 && einfo->severity == 0) { - return 0; + return; } spprintf(&message, 0, "%s [%d] (severity %d) [%s]", @@ -69,8 +69,6 @@ static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) if (einfo->oserrstr) { add_next_index_string(info, einfo->oserrstr); } - - return 1; } diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index 2734df9262..d51ca61eff 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -968,7 +968,7 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v /* }}} */ /* called by PDO to retrieve driver-specific information about an error that has occurred */ -static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */ +static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; const ISC_STATUS *s = H->isc_status; @@ -987,7 +987,6 @@ static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval add_next_index_long(info, -999); add_next_index_string(info, const_cast(H->last_app_error)); } - return 1; } /* }}} */ diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 1cc48e9010..70ca64a3e0 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -117,7 +117,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin /* }}} */ /* {{{ pdo_mysql_fetch_error_func */ -static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) +static void pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_error_info *einfo = &H->einfo; @@ -136,7 +136,7 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in add_next_index_string(info, einfo->errmsg); } - PDO_DBG_RETURN(1); + PDO_DBG_VOID_RETURN; } /* }}} */ diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c index f7184e2422..fbe70a5df8 100644 --- a/ext/pdo_oci/oci_driver.c +++ b/ext/pdo_oci/oci_driver.c @@ -29,7 +29,7 @@ static inline ub4 pdo_oci_sanitize_prefetch(long prefetch); -static int pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */ +static void pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */ { pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; pdo_oci_error_info *einfo; @@ -48,8 +48,6 @@ static int pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info add_next_index_long(info, einfo->errcode); add_next_index_string(info, einfo->errmsg); } - - return 1; } /* }}} */ diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c index 20f448c8f1..d2e40d5de5 100644 --- a/ext/pdo_odbc/odbc_driver.c +++ b/ext/pdo_odbc/odbc_driver.c @@ -27,7 +27,7 @@ #include "php_pdo_odbc_int.h" #include "zend_exceptions.h" -static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) +static void pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; pdo_odbc_errinfo *einfo = &H->einfo; @@ -47,8 +47,6 @@ static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *inf add_next_index_long(info, einfo->last_error); add_next_index_str(info, message); add_next_index_string(info, einfo->last_state); - - return 1; } diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 53751b28c7..c7f9d46f7f 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -107,7 +107,7 @@ static void _pdo_pgsql_notice(pdo_dbh_t *dbh, const char *message) /* {{{ */ } /* }}} */ -static int pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */ +static void pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */ { pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; pdo_pgsql_error_info *einfo = &H->einfo; @@ -115,13 +115,12 @@ static int pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in if (einfo->errcode) { add_next_index_long(info, einfo->errcode); } else { + /* Add null to respect expected info array structure */ add_next_index_null(info); } if (einfo->errmsg) { add_next_index_string(info, einfo->errmsg); } - - return 1; } /* }}} */ diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c index cb62816c3a..344850b099 100644 --- a/ext/pdo_sqlite/sqlite_driver.c +++ b/ext/pdo_sqlite/sqlite_driver.c @@ -82,7 +82,7 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li } /* }}} */ -static int pdo_sqlite_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) +static void pdo_sqlite_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) { pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; pdo_sqlite_error_info *einfo = &H->einfo; @@ -91,8 +91,6 @@ static int pdo_sqlite_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *i add_next_index_long(info, einfo->errcode); add_next_index_string(info, einfo->errmsg); } - - return 1; } static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H) |