Voidify PDO's fetch_error handler

This commit is contained in:
George Peter Banyard 2020-12-24 01:45:58 +01:00
parent 60a61afd3c
commit 1a58611ae5
9 changed files with 26 additions and 34 deletions

View file

@ -148,12 +148,12 @@ 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) {
@ -164,7 +164,6 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */
supp = estrndup(Z_STRVAL_P(item), Z_STRLEN_P(item));
}
}
}
if (native_code && supp) {
message = strpprintf(0, "SQLSTATE[%s]: %s: " ZEND_LONG_FMT " %s", *pdo_err, msg, native_code, supp);

View file

@ -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:

View file

@ -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;
}

View file

@ -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;
}
/* }}} */

View file

@ -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;
}
/* }}} */

View file

@ -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;
}
/* }}} */

View file

@ -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;
}

View file

@ -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;
}
/* }}} */

View file

@ -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)