Skip to content

Commit 1a58611

Browse files
committed
Voidify PDO's fetch_error handler
1 parent 60a61af commit 1a58611

File tree

9 files changed

+26
-34
lines changed

9 files changed

+26
-34
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,20 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */
148148

149149
ZVAL_UNDEF(&info);
150150
if (dbh->methods->fetch_err) {
151+
zval *item;
151152
array_init(&info);
152153

153154
add_next_index_string(&info, *pdo_err);
154155

155-
if (dbh->methods->fetch_err(dbh, stmt, &info)) {
156-
zval *item;
156+
dbh->methods->fetch_err(dbh, stmt, &info);
157157

158-
if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL
159-
&& Z_TYPE_P(item) == IS_LONG) {
160-
native_code = Z_LVAL_P(item);
161-
}
158+
if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL
159+
&& Z_TYPE_P(item) == IS_LONG) {
160+
native_code = Z_LVAL_P(item);
161+
}
162162

163-
if ((item = zend_hash_index_find(Z_ARRVAL(info), 2)) != NULL) {
164-
supp = estrndup(Z_STRVAL_P(item), Z_STRLEN_P(item));
165-
}
163+
if ((item = zend_hash_index_find(Z_ARRVAL(info), 2)) != NULL) {
164+
supp = estrndup(Z_STRVAL_P(item), Z_STRLEN_P(item));
166165
}
167166
}
168167

ext/pdo/php_pdo_driver.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,16 @@ typedef bool (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val)
250250
* MUST be an emalloc'd NULL terminated string. */
251251
typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, size_t *len);
252252

253-
/* fetch error information. if stmt is not null, fetch information pertaining
254-
* to the statement, otherwise fetch global error information. The driver
255-
* should add the following information to the array "info" in this order:
253+
/* Fetch error information.
254+
* If stmt is not null, fetch information pertaining to the statement,
255+
* otherwise fetch global error information.
256+
* info is an initialized PHP array, if there are no messages leave it empty.
257+
* The driver should add the following information to the array "info" in this order:
256258
* - native error code
257259
* - string representation of the error code ... any other optional driver
258-
* specific data ... */
259-
typedef int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info);
260+
* specific data ...
261+
* PDO takes care of normalizing the array. */
262+
typedef void (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info);
260263

261264
/* fetching of attributes
262265
* There are 3 return states:

ext/pdo_dblib/dblib_driver.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/* Cache of the server supported datatypes, initialized in handle_factory */
3232
zval* pdo_dblib_datatypes;
3333

34-
static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
34+
static void dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
3535
{
3636
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
3737
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)
5555

5656
/* don't return anything if there's nothing to return */
5757
if (msg == NULL && einfo->dberr == 0 && einfo->oserr == 0 && einfo->severity == 0) {
58-
return 0;
58+
return;
5959
}
6060

6161
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)
6969
if (einfo->oserrstr) {
7070
add_next_index_string(info, einfo->oserrstr);
7171
}
72-
73-
return 1;
7472
}
7573

7674

ext/pdo_firebird/firebird_driver.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
968968
/* }}} */
969969

970970
/* called by PDO to retrieve driver-specific information about an error that has occurred */
971-
static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
971+
static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
972972
{
973973
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
974974
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
987987
add_next_index_long(info, -999);
988988
add_next_index_string(info, const_cast(H->last_app_error));
989989
}
990-
return 1;
991990
}
992991
/* }}} */
993992

ext/pdo_mysql/mysql_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
117117
/* }}} */
118118

119119
/* {{{ pdo_mysql_fetch_error_func */
120-
static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
120+
static void pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
121121
{
122122
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
123123
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
136136
add_next_index_string(info, einfo->errmsg);
137137
}
138138

139-
PDO_DBG_RETURN(1);
139+
PDO_DBG_VOID_RETURN;
140140
}
141141
/* }}} */
142142

ext/pdo_oci/oci_driver.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
static inline ub4 pdo_oci_sanitize_prefetch(long prefetch);
3131

32-
static int pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
32+
static void pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
3333
{
3434
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
3535
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
4848
add_next_index_long(info, einfo->errcode);
4949
add_next_index_string(info, einfo->errmsg);
5050
}
51-
52-
return 1;
5351
}
5452
/* }}} */
5553

ext/pdo_odbc/odbc_driver.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "php_pdo_odbc_int.h"
2828
#include "zend_exceptions.h"
2929

30-
static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
30+
static void pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
3131
{
3232
pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;
3333
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
4747
add_next_index_long(info, einfo->last_error);
4848
add_next_index_str(info, message);
4949
add_next_index_string(info, einfo->last_state);
50-
51-
return 1;
5250
}
5351

5452

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,20 @@ static void _pdo_pgsql_notice(pdo_dbh_t *dbh, const char *message) /* {{{ */
107107
}
108108
/* }}} */
109109

110-
static int pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
110+
static void pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
111111
{
112112
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
113113
pdo_pgsql_error_info *einfo = &H->einfo;
114114

115115
if (einfo->errcode) {
116116
add_next_index_long(info, einfo->errcode);
117117
} else {
118+
/* Add null to respect expected info array structure */
118119
add_next_index_null(info);
119120
}
120121
if (einfo->errmsg) {
121122
add_next_index_string(info, einfo->errmsg);
122123
}
123-
124-
return 1;
125124
}
126125
/* }}} */
127126

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li
8282
}
8383
/* }}} */
8484

85-
static int pdo_sqlite_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
85+
static void pdo_sqlite_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
8686
{
8787
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
8888
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
9191
add_next_index_long(info, einfo->errcode);
9292
add_next_index_string(info, einfo->errmsg);
9393
}
94-
95-
return 1;
9694
}
9795

9896
static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H)

0 commit comments

Comments
 (0)