Skip to content

Commit 776eeda

Browse files
committed
Boolify PDO's fetch_error handler
1 parent c6f4686 commit 776eeda

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

ext/pdo/php_pdo_driver.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,14 @@ typedef bool (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val)
251251
typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, size_t *len);
252252

253253
/* 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:
254+
* to the statement, otherwise fetch global error information.
255+
* Return true if there messages, otherwise return false.
256+
* The driver should add the following information to the array "info" in this order:
256257
* - native error code
257258
* - 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);
259+
* specific data ...
260+
* PDO takes care of normalizing the array. */
261+
typedef bool (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info);
260262

261263
/* fetching of attributes
262264
* Return true on success and false in case of failure */

ext/pdo_dblib/dblib_driver.c

Lines changed: 3 additions & 3 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 bool 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 false;
5959
}
6060

6161
spprintf(&message, 0, "%s [%d] (severity %d) [%s]",
@@ -70,7 +70,7 @@ static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
7070
add_next_index_string(info, einfo->oserrstr);
7171
}
7272

73-
return 1;
73+
return true;
7474
}
7575

7676

ext/pdo_firebird/firebird_driver.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ static bool firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *
969969
/* }}} */
970970

971971
/* called by PDO to retrieve driver-specific information about an error that has occurred */
972-
static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
972+
static bool pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
973973
{
974974
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
975975
const ISC_STATUS *s = H->isc_status;
@@ -984,11 +984,13 @@ static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval
984984
strcpy(&buf[i++], " ");
985985
}
986986
add_next_index_string(info, buf);
987+
return true;
987988
} else if (H->last_app_error) {
988989
add_next_index_long(info, -999);
989990
add_next_index_string(info, const_cast(H->last_app_error));
991+
return true;
990992
}
991-
return 1;
993+
return false;
992994
}
993995
/* }}} */
994996

ext/pdo_mysql/mysql_driver.c

Lines changed: 3 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 bool 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;
@@ -134,9 +134,10 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in
134134
if (einfo->errcode) {
135135
add_next_index_long(info, einfo->errcode);
136136
add_next_index_string(info, einfo->errmsg);
137+
PDO_DBG_RETURN(true);
137138
}
138139

139-
PDO_DBG_RETURN(1);
140+
PDO_DBG_RETURN(false);
140141
}
141142
/* }}} */
142143

ext/pdo_oci/oci_driver.c

Lines changed: 3 additions & 2 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 bool 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;
@@ -47,9 +47,10 @@ static int pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info
4747
if (einfo->errcode) {
4848
add_next_index_long(info, einfo->errcode);
4949
add_next_index_string(info, einfo->errmsg);
50+
return true;
5051
}
5152

52-
return 1;
53+
return false;
5354
}
5455
/* }}} */
5556

ext/pdo_odbc/odbc_driver.c

Lines changed: 2 additions & 2 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 bool 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;
@@ -48,7 +48,7 @@ static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *inf
4848
add_next_index_str(info, message);
4949
add_next_index_string(info, einfo->last_state);
5050

51-
return 1;
51+
return true;
5252
}
5353

5454

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,22 @@ 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 bool 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;
114+
bool return_value = false;
114115

115116
if (einfo->errcode) {
116117
add_next_index_long(info, einfo->errcode);
117-
} else {
118-
add_next_index_null(info);
118+
return_value = true;
119119
}
120120
if (einfo->errmsg) {
121121
add_next_index_string(info, einfo->errmsg);
122+
return_value = true;
122123
}
123124

124-
return 1;
125+
return return_value;
125126
}
126127
/* }}} */
127128

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,18 @@ 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 bool 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;
8989

9090
if (einfo->errcode) {
9191
add_next_index_long(info, einfo->errcode);
9292
add_next_index_string(info, einfo->errmsg);
93+
return true;
9394
}
9495

95-
return 1;
96+
return false;
9697
}
9798

9899
static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H)

0 commit comments

Comments
 (0)