mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Voidify PDO's fetch_error handler
This commit is contained in:
parent
60a61afd3c
commit
1a58611ae5
9 changed files with 26 additions and 34 deletions
|
@ -148,21 +148,20 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */
|
||||||
|
|
||||||
ZVAL_UNDEF(&info);
|
ZVAL_UNDEF(&info);
|
||||||
if (dbh->methods->fetch_err) {
|
if (dbh->methods->fetch_err) {
|
||||||
|
zval *item;
|
||||||
array_init(&info);
|
array_init(&info);
|
||||||
|
|
||||||
add_next_index_string(&info, *pdo_err);
|
add_next_index_string(&info, *pdo_err);
|
||||||
|
|
||||||
if (dbh->methods->fetch_err(dbh, stmt, &info)) {
|
dbh->methods->fetch_err(dbh, stmt, &info);
|
||||||
zval *item;
|
|
||||||
|
|
||||||
if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL
|
if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL
|
||||||
&& Z_TYPE_P(item) == IS_LONG) {
|
&& Z_TYPE_P(item) == IS_LONG) {
|
||||||
native_code = Z_LVAL_P(item);
|
native_code = Z_LVAL_P(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((item = zend_hash_index_find(Z_ARRVAL(info), 2)) != NULL) {
|
if ((item = zend_hash_index_find(Z_ARRVAL(info), 2)) != NULL) {
|
||||||
supp = estrndup(Z_STRVAL_P(item), Z_STRLEN_P(item));
|
supp = estrndup(Z_STRVAL_P(item), Z_STRLEN_P(item));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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. */
|
* 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);
|
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
|
/* Fetch error information.
|
||||||
* to the statement, otherwise fetch global error information. The driver
|
* If stmt is not null, fetch information pertaining to the statement,
|
||||||
* should add the following information to the array "info" in this order:
|
* 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
|
* - native error code
|
||||||
* - string representation of the error code ... any other optional driver
|
* - string representation of the error code ... any other optional driver
|
||||||
* specific data ... */
|
* specific data ...
|
||||||
typedef int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info);
|
* 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
|
/* fetching of attributes
|
||||||
* There are 3 return states:
|
* There are 3 return states:
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
/* Cache of the server supported datatypes, initialized in handle_factory */
|
/* Cache of the server supported datatypes, initialized in handle_factory */
|
||||||
zval* pdo_dblib_datatypes;
|
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_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
|
||||||
pdo_dblib_err *einfo = &H->err;
|
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 */
|
/* don't return anything if there's nothing to return */
|
||||||
if (msg == NULL && einfo->dberr == 0 && einfo->oserr == 0 && einfo->severity == 0) {
|
if (msg == NULL && einfo->dberr == 0 && einfo->oserr == 0 && einfo->severity == 0) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spprintf(&message, 0, "%s [%d] (severity %d) [%s]",
|
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) {
|
if (einfo->oserrstr) {
|
||||||
add_next_index_string(info, einfo->oserrstr);
|
add_next_index_string(info, einfo->oserrstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
/* 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;
|
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
|
||||||
const ISC_STATUS *s = H->isc_status;
|
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_long(info, -999);
|
||||||
add_next_index_string(info, const_cast(H->last_app_error));
|
add_next_index_string(info, const_cast(H->last_app_error));
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
/* {{{ 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_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
||||||
pdo_mysql_error_info *einfo = &H->einfo;
|
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);
|
add_next_index_string(info, einfo->errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
PDO_DBG_RETURN(1);
|
PDO_DBG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
static inline ub4 pdo_oci_sanitize_prefetch(long prefetch);
|
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_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
|
||||||
pdo_oci_error_info *einfo;
|
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_long(info, einfo->errcode);
|
||||||
add_next_index_string(info, einfo->errmsg);
|
add_next_index_string(info, einfo->errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "php_pdo_odbc_int.h"
|
#include "php_pdo_odbc_int.h"
|
||||||
#include "zend_exceptions.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_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;
|
||||||
pdo_odbc_errinfo *einfo = &H->einfo;
|
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_long(info, einfo->last_error);
|
||||||
add_next_index_str(info, message);
|
add_next_index_str(info, message);
|
||||||
add_next_index_string(info, einfo->last_state);
|
add_next_index_string(info, einfo->last_state);
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
|
||||||
pdo_pgsql_error_info *einfo = &H->einfo;
|
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) {
|
if (einfo->errcode) {
|
||||||
add_next_index_long(info, einfo->errcode);
|
add_next_index_long(info, einfo->errcode);
|
||||||
} else {
|
} else {
|
||||||
|
/* Add null to respect expected info array structure */
|
||||||
add_next_index_null(info);
|
add_next_index_null(info);
|
||||||
}
|
}
|
||||||
if (einfo->errmsg) {
|
if (einfo->errmsg) {
|
||||||
add_next_index_string(info, einfo->errmsg);
|
add_next_index_string(info, einfo->errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -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_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
|
||||||
pdo_sqlite_error_info *einfo = &H->einfo;
|
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_long(info, einfo->errcode);
|
||||||
add_next_index_string(info, einfo->errmsg);
|
add_next_index_string(info, einfo->errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H)
|
static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue