Skip to content

Commit c6f4686

Browse files
committed
Boolify PDO's preparer handler
1 parent a84523d commit c6f4686

File tree

8 files changed

+31
-30
lines changed

8 files changed

+31
-30
lines changed

ext/pdo/php_pdo_driver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ typedef struct {
228228
/* close or otherwise disconnect the database */
229229
typedef void (*pdo_dbh_close_func)(pdo_dbh_t *dbh);
230230

231-
/* prepare a statement and stash driver specific portion into stmt */
232-
typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options);
231+
/* prepare a statement and stash driver specific portion into stmt
232+
* return true on success, false otherwise */
233+
typedef bool (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options);
233234

234235
/* execute a statement (that does not return a result set) */
235236
typedef zend_long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, size_t sql_len);

ext/pdo_dblib/dblib_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void dblib_handle_closer(pdo_dbh_t *dbh)
9393
}
9494
}
9595

96-
static int dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
96+
static bool dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
9797
{
9898
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
9999
pdo_dblib_stmt *S = ecalloc(1, sizeof(*S));
@@ -105,7 +105,7 @@ static int dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s
105105
S->computed_column_name_count = 0;
106106
S->err.sqlstate = stmt->error_code;
107107

108-
return 1;
108+
return true;
109109
}
110110

111111
static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len)

ext/pdo_firebird/firebird_driver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static void firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
502502
/* }}} */
503503

504504
/* called by PDO to prepare an SQL query */
505-
static int firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
505+
static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
506506
pdo_stmt_t *stmt, zval *driver_options)
507507
{
508508
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
@@ -566,7 +566,7 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
566566
stmt->methods = &firebird_stmt_methods;
567567
stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
568568

569-
return 1;
569+
return true;
570570

571571
} while (0);
572572

@@ -582,7 +582,7 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
582582
efree(S);
583583
}
584584

585-
return 0;
585+
return false;
586586
}
587587
/* }}} */
588588

ext/pdo_mysql/mysql_driver.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static void mysql_handle_closer(pdo_dbh_t *dbh)
161161
/* }}} */
162162

163163
/* {{{ mysql_handle_preparer */
164-
static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
164+
static bool mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
165165
{
166166
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
167167
pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt));
@@ -194,15 +194,15 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s
194194
} else if (ret == -1) {
195195
/* failed to parse */
196196
strcpy(dbh->error_code, stmt->error_code);
197-
PDO_DBG_RETURN(0);
197+
PDO_DBG_RETURN(false);
198198
}
199199

200200
if (!(S->stmt = mysql_stmt_init(H->server))) {
201201
pdo_mysql_error(dbh);
202202
if (nsql) {
203203
zend_string_release(nsql);
204204
}
205-
PDO_DBG_RETURN(0);
205+
PDO_DBG_RETURN(false);
206206
}
207207

208208
if (mysql_stmt_prepare(S->stmt, ZSTR_VAL(sql), ZSTR_LEN(sql))) {
@@ -217,7 +217,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s
217217
goto fallback;
218218
}
219219
pdo_mysql_error(dbh);
220-
PDO_DBG_RETURN(0);
220+
PDO_DBG_RETURN(false);
221221
}
222222
if (nsql) {
223223
zend_string_release(nsql);
@@ -238,13 +238,13 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s
238238

239239
S->max_length = pdo_attr_lval(driver_options, PDO_ATTR_MAX_COLUMN_LEN, 0);
240240

241-
PDO_DBG_RETURN(1);
241+
PDO_DBG_RETURN(true);
242242

243243
fallback:
244244
end:
245245
stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
246246

247-
PDO_DBG_RETURN(1);
247+
PDO_DBG_RETURN(true);
248248
}
249249
/* }}} */
250250

ext/pdo_oci/oci_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static void oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */
236236
}
237237
/* }}} */
238238

239-
static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */
239+
static bool oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */
240240
{
241241
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
242242
pdo_oci_stmt *S = ecalloc(1, sizeof(*S));
@@ -263,7 +263,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stm
263263
/* couldn't grok it */
264264
strcpy(dbh->error_code, stmt->error_code);
265265
efree(S);
266-
return 0;
266+
return false;
267267
}
268268

269269
/* create an OCI statement handle */
@@ -283,7 +283,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stm
283283
OCIHandleFree(S->stmt, OCI_HTYPE_STMT);
284284
OCIHandleFree(S->err, OCI_HTYPE_ERROR);
285285
efree(S);
286-
return 0;
286+
return false;
287287
}
288288

289289
}
@@ -304,7 +304,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stm
304304
nsql = NULL;
305305
}
306306

307-
return 1;
307+
return true;
308308
}
309309
/* }}} */
310310

ext/pdo_odbc/odbc_driver.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void odbc_handle_closer(pdo_dbh_t *dbh)
136136
dbh->driver_data = NULL;
137137
}
138138

139-
static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
139+
static bool odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
140140
{
141141
RETCODE rc;
142142
pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;
@@ -160,7 +160,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st
160160
/* couldn't grok it */
161161
strcpy(dbh->error_code, stmt->error_code);
162162
efree(S);
163-
return 0;
163+
return false;
164164
}
165165

166166
rc = SQLAllocHandle(SQL_HANDLE_STMT, H->dbc, &S->stmt);
@@ -171,7 +171,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st
171171
zend_string_release(nsql);
172172
}
173173
pdo_odbc_drv_error("SQLAllocStmt");
174-
return 0;
174+
return false;
175175
}
176176

177177
stmt->driver_data = S;
@@ -185,7 +185,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st
185185
if (nsql) {
186186
zend_string_release(nsql);
187187
}
188-
return 0;
188+
return false;
189189
}
190190
}
191191

@@ -209,9 +209,9 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st
209209
}
210210

211211
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
212-
return 0;
212+
return false;
213213
}
214-
return 1;
214+
return true;
215215
}
216216

217217
static zend_long odbc_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len)

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void pgsql_handle_closer(pdo_dbh_t *dbh) /* {{{ */
221221
}
222222
/* }}} */
223223

224-
static int pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
224+
static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
225225
{
226226
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
227227
pdo_pgsql_stmt *S = ecalloc(1, sizeof(pdo_pgsql_stmt));
@@ -272,7 +272,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s
272272
if (ret == -1) {
273273
/* couldn't grok it */
274274
strcpy(dbh->error_code, stmt->error_code);
275-
return 0;
275+
return false;
276276
} else if (ret == 1) {
277277
/* query was re-written */
278278
S->query = nsql;
@@ -286,7 +286,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s
286286
spprintf(&S->stmt_name, 0, "pdo_stmt_%08x", ++H->stmt_counter);
287287
}
288288

289-
return 1;
289+
return true;
290290
}
291291

292292
static zend_long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len)

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static void sqlite_handle_closer(pdo_dbh_t *dbh) /* {{{ */
174174
}
175175
/* }}} */
176176

177-
static int sqlite_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
177+
static bool sqlite_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
178178
{
179179
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
180180
pdo_sqlite_stmt *S = ecalloc(1, sizeof(pdo_sqlite_stmt));
@@ -189,17 +189,17 @@ static int sqlite_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *
189189
if (PDO_CURSOR_FWDONLY != pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY)) {
190190
H->einfo.errcode = SQLITE_ERROR;
191191
pdo_sqlite_error(dbh);
192-
return 0;
192+
return false;
193193
}
194194

195195
i = sqlite3_prepare_v2(H->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &S->stmt, &tail);
196196
if (i == SQLITE_OK) {
197-
return 1;
197+
return true;
198198
}
199199

200200
pdo_sqlite_error(dbh);
201201

202-
return 0;
202+
return false;
203203
}
204204

205205
static zend_long sqlite_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len)

0 commit comments

Comments
 (0)