diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 1b5784102d4e8..2ca1cad90df29 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -3865,7 +3865,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */ RETURN_OBJ(&cdata->std); } else { zend_wrong_parameter_class_error(2, "FFI\\CData", zv); - return; + RETURN_THROWS(); } } @@ -4006,7 +4006,7 @@ ZEND_METHOD(FFI, typeof) /* {{{ */ } } else { zend_wrong_parameter_class_error(1, "FFI\\CData", zv); - return; + RETURN_THROWS(); } ctype = (zend_ffi_ctype*)zend_ffi_ctype_new(zend_ffi_ctype_ce); @@ -4110,7 +4110,7 @@ ZEND_METHOD(FFI, addr) /* {{{ */ ZVAL_DEREF(zv); if (Z_TYPE_P(zv) != IS_OBJECT || Z_OBJCE_P(zv) != zend_ffi_cdata_ce) { zend_wrong_parameter_class_error(1, "FFI\\CData", zv); - return; + RETURN_THROWS(); } cdata = (zend_ffi_cdata*)Z_OBJ_P(zv); @@ -4165,7 +4165,7 @@ ZEND_METHOD(FFI, sizeof) /* {{{ */ type = ZEND_FFI_TYPE(ctype->type); } else { zend_wrong_parameter_class_error(1, "FFI\\CData or FFI\\CType", zv); - return; + RETURN_THROWS(); } RETURN_LONG(type->size); @@ -4191,7 +4191,7 @@ ZEND_METHOD(FFI, alignof) /* {{{ */ type = ZEND_FFI_TYPE(ctype->type); } else { zend_wrong_parameter_class_error(1, "FFI\\CData or FFI\\CType", zv); - return; + RETURN_THROWS(); } RETURN_LONG(type->align); @@ -4246,7 +4246,7 @@ ZEND_METHOD(FFI, memcpy) /* {{{ */ } } else { zend_wrong_parameter_class_error(2, "FFI\\CData or string", zv2); - return; + RETURN_THROWS(); } memcpy(ptr1, ptr2, size); @@ -4290,7 +4290,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */ } } else { zend_wrong_parameter_class_error(1, "FFI\\CData or string", zv1); - return; + RETURN_THROWS(); } ZVAL_DEREF(zv2); @@ -4314,7 +4314,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */ } } else { zend_wrong_parameter_class_error(2, "FFI\\CData or string", zv2); - return; + RETURN_THROWS(); } ret = memcmp(ptr1, ptr2, size); @@ -4416,7 +4416,7 @@ ZEND_METHOD(FFI, isNull) /* {{{ */ ZVAL_DEREF(zv); if (Z_TYPE_P(zv) != IS_OBJECT || Z_OBJCE_P(zv) != zend_ffi_cdata_ce) { zend_wrong_parameter_class_error(1, "FFI\\CData", zv); - return; + RETURN_THROWS(); } cdata = (zend_ffi_cdata*)Z_OBJ_P(zv); diff --git a/ext/ffi/ffi.stub.php b/ext/ffi/ffi.stub.php index 0a347b2aa123b..18f51aa254dee 100644 --- a/ext/ffi/ffi.stub.php +++ b/ext/ffi/ffi.stub.php @@ -26,18 +26,24 @@ public static function cast(FFI\CType|string $type, $ptr): ?FFI\CData {} public static function type(string $type): ?FFI\CType {} /** @prefer-ref $ptr */ - public static function typeof(FFI\CData $ptr): ?FFI\CType {} + public static function typeof(FFI\CData $ptr): FFI\CType {} public static function arrayType(FFI\CType $type, array $dimensions): ?FFI\CType {} /** @prefer-ref $ptr */ public static function addr(FFI\CData $ptr): FFI\CData {} - /** @prefer-ref $ptr */ - public static function sizeof(object $ptr): ?int {} + /** + * @param FFI\CData|FFI\CType $ptr + * @prefer-ref $ptr + */ + public static function sizeof($ptr): int {} - /** @prefer-ref $ptr */ - public static function alignof(object $ptr): ?int {} + /** + * @param FFI\CData|FFI\CType $ptr + * @prefer-ref $ptr + */ + public static function alignof($ptr): int {} /** * @param FFI\CData|string $from @@ -52,7 +58,7 @@ public static function memcpy(FFI\CData $to, $from, int $size): void {} * @prefer-ref $ptr2 * @param string|FFI\CData $ptr2 */ - public static function memcmp($ptr1, $ptr2, int $size): ?int {} + public static function memcmp($ptr1, $ptr2, int $size): int {} /** @prefer-ref $ptr */ public static function memset(FFI\CData $ptr, int $value, int $size): void {} diff --git a/ext/ffi/ffi_arginfo.h b/ext/ffi/ffi_arginfo.h index 19e0adb25d7a6..16dcdf7f090d6 100644 --- a/ext/ffi/ffi_arginfo.h +++ b/ext/ffi/ffi_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: abd3bc186ae3f71f2b7eb1d47f3b6bab84fb2bda */ + * Stub hash: 677c62adf295003b4b2d273995a4bda623d507bf */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"") @@ -33,7 +33,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_type, 0, 1, FFI\\CType, ZEND_ARG_TYPE_INFO(0, type, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_typeof, 0, 1, FFI\\CType, 1) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_typeof, 0, 1, FFI\\CType, 0) ZEND_ARG_OBJ_INFO(ZEND_SEND_PREFER_REF, ptr, FFI\\CData, 0) ZEND_END_ARG_INFO() @@ -46,8 +46,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_addr, 0, 1, FFI\\CData, ZEND_ARG_OBJ_INFO(ZEND_SEND_PREFER_REF, ptr, FFI\\CData, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_sizeof, 0, 1, IS_LONG, 1) - ZEND_ARG_TYPE_INFO(ZEND_SEND_PREFER_REF, ptr, IS_OBJECT, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_sizeof, 0, 1, IS_LONG, 0) + ZEND_ARG_INFO(ZEND_SEND_PREFER_REF, ptr) ZEND_END_ARG_INFO() #define arginfo_class_FFI_alignof arginfo_class_FFI_sizeof @@ -58,7 +58,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_memcpy, 0, 3, IS_VOID, ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_memcmp, 0, 3, IS_LONG, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_memcmp, 0, 3, IS_LONG, 0) ZEND_ARG_INFO(ZEND_SEND_PREFER_REF, ptr1) ZEND_ARG_INFO(ZEND_SEND_PREFER_REF, ptr2) ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) diff --git a/ext/imap/php_imap_arginfo.h b/ext/imap/php_imap_arginfo.h index ec292138dfbcb..d164de32935f2 100644 --- a/ext/imap/php_imap_arginfo.h +++ b/ext/imap/php_imap_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 1dbf85a4f8740bf02df35a4e184a67af6cf93e91 */ + * Stub hash: 6fa602f286cb156c92ead840e149456dc0c07869 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_open, 0, 3, IMAPConnection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 08bb61fc0ff57..4f3cb47f29884 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -578,7 +578,7 @@ PHP_METHOD(PDO, prepare) /* }}} */ -static zend_bool pdo_is_in_transaction(pdo_dbh_t *dbh) { +static bool pdo_is_in_transaction(pdo_dbh_t *dbh) { if (dbh->methods->in_transaction) { return dbh->methods->in_transaction(dbh); } @@ -600,14 +600,13 @@ PHP_METHOD(PDO, beginTransaction) } if (!dbh->methods->begin) { - /* TODO: this should be an exception; see the auto-commit mode - * comments below */ + /* Throw an exception when the driver does not support transactions */ zend_throw_exception_ex(php_pdo_get_exception(), 0, "This driver doesn't support transactions"); RETURN_THROWS(); } if (dbh->methods->begin(dbh)) { - dbh->in_txn = 1; + dbh->in_txn = true; RETURN_TRUE; } @@ -631,7 +630,7 @@ PHP_METHOD(PDO, commit) } if (dbh->methods->commit(dbh)) { - dbh->in_txn = 0; + dbh->in_txn = false; RETURN_TRUE; } @@ -655,7 +654,7 @@ PHP_METHOD(PDO, rollBack) } if (dbh->methods->rollback(dbh)) { - dbh->in_txn = 0; + dbh->in_txn = false; RETURN_TRUE; } @@ -894,18 +893,13 @@ PHP_METHOD(PDO, getAttribute) RETURN_FALSE; } - switch (dbh->methods->get_attribute(dbh, attr, return_value)) { - case -1: - PDO_HANDLE_DBH_ERR(); - RETURN_FALSE; - - case 0: - pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support that attribute"); - RETURN_FALSE; - - default: - return; + if (dbh->methods->get_attribute(dbh, attr, return_value) == false) { + pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support that attribute"); + RETURN_FALSE; } + /* No error state, just return as the return_value has been assigned + * by the get_attribute handler */ + return; } /* }}} */ @@ -1461,7 +1455,7 @@ static void pdo_dbh_free_storage(zend_object *std) pdo_dbh_t *dbh = php_pdo_dbh_fetch_inner(std); if (dbh->in_txn && dbh->methods && dbh->methods->rollback) { dbh->methods->rollback(dbh); - dbh->in_txn = 0; + dbh->in_txn = false; } if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) { diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 18116b80fb83c..fc12e44f10549 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2018,7 +2018,7 @@ PHP_METHOD(PDOStatement, getIterator) /* {{{ overloaded handlers for PDOStatement class */ static zval *dbstmt_prop_write(zend_object *object, zend_string *name, zval *value, void **cache_slot) { - if (strcmp(ZSTR_VAL(name), "queryString") == 0) { + if (zend_string_equals_literal(name, "queryString")) { zend_throw_error(NULL, "Property queryString is read only"); return value; } else { @@ -2028,7 +2028,7 @@ static zval *dbstmt_prop_write(zend_object *object, zend_string *name, zval *val static void dbstmt_prop_delete(zend_object *object, zend_string *name, void **cache_slot) { - if (strcmp(ZSTR_VAL(name), "queryString") == 0) { + if (zend_string_equals_literal(name, "queryString")) { zend_throw_error(NULL, "Property queryString is read only"); } else { zend_std_unset_property(object, name, cache_slot); @@ -2282,8 +2282,7 @@ static zval *row_prop_read(zend_object *object, zend_string *name, int type, voi return rv; } } - if (strcmp(ZSTR_VAL(name), "queryString") == 0) { - //zval_ptr_dtor(rv); + if (zend_string_equals_literal(name, "queryString")) { return zend_std_read_property(&stmt->std, name, type, cache_slot, rv); } } @@ -2324,8 +2323,7 @@ static zval *row_dim_read(zend_object *object, zval *member, int type, zval *rv) return rv; } } - if (strcmp(Z_STRVAL_P(member), "queryString") == 0) { - //zval_ptr_dtor(rv); + if (zend_string_equals_literal(Z_STR_P(member), "queryString")) { return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv); } } diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index ea78eb187d96a..d79e316743dfa 100644 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -226,42 +226,48 @@ typedef struct { /* {{{ methods for a database handle */ /* close or otherwise disconnect the database */ -typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh); +typedef void (*pdo_dbh_close_func)(pdo_dbh_t *dbh); -/* prepare a statement and stash driver specific portion into stmt */ -typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options); +/* prepare a statement and stash driver specific portion into stmt + * return true on success, false otherwise */ +typedef bool (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options); /* execute a statement (that does not return a result set) */ typedef zend_long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, size_t sql_len); /* quote a string */ -typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype); +typedef bool (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype); -/* transaction related */ -typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh); +/* transaction related (beingTransaction(), commit, rollBack, inTransaction) + * return true in case of success, false otherwise */ +typedef bool (*pdo_dbh_txn_func)(pdo_dbh_t *dbh); -/* setting of attributes */ -typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val); +/* setting of attributes + * Return true on success and false in case of failure */ +typedef bool (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val); /* return last insert id. NULL indicates error condition, otherwise, the return value * 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: + * to the statement, otherwise fetch global error information. + * Return true if there messages, otherwise return false. + * 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 bool (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info); -/* fetching of attributes */ -typedef int (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val); +/* fetching of attributes + * Return true on success and false in case of failure */ +typedef bool (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val); /* checking/pinging persistent connections; return SUCCESS if the connection * is still alive and ready to be used, FAILURE otherwise. * You may set this handler to NULL, which is equivalent to returning SUCCESS. */ -typedef int (*pdo_dbh_check_liveness_func)(pdo_dbh_t *dbh); +typedef zend_result (*pdo_dbh_check_liveness_func)(pdo_dbh_t *dbh); /* called at request end for each persistent dbh; this gives the driver * the opportunity to safely release resources that only have per-request @@ -301,7 +307,8 @@ struct pdo_dbh_methods { pdo_dbh_check_liveness_func check_liveness; pdo_dbh_get_driver_methods_func get_driver_methods; pdo_dbh_request_shutdown persistent_shutdown; - pdo_dbh_txn_func in_transaction; + pdo_dbh_txn_func in_transaction; /* if defined to NULL, PDO will use + * its internal transaction tracking state */ pdo_dbh_get_gc_func get_gc; }; @@ -442,7 +449,7 @@ struct _pdo_dbh_t { unsigned alloc_own_columns:1; /* if true, commit or rollBack is allowed to be called */ - unsigned in_txn:1; + bool in_txn:1; /* max length a single character can become after correct quoting */ unsigned max_escaped_char_length:3; diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index 085b6990d25f1..a193bbb09412d 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -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 bool 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 false; } spprintf(&message, 0, "%s [%d] (severity %d) [%s]", @@ -70,11 +70,11 @@ static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) add_next_index_string(info, einfo->oserrstr); } - return 1; + return true; } -static int dblib_handle_closer(pdo_dbh_t *dbh) +static void dblib_handle_closer(pdo_dbh_t *dbh) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; @@ -91,10 +91,9 @@ static int dblib_handle_closer(pdo_dbh_t *dbh) pefree(H, dbh->is_persistent); dbh->driver_data = NULL; } - return 0; } -static int dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) +static bool dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; pdo_dblib_stmt *S = ecalloc(1, sizeof(*S)); @@ -106,7 +105,7 @@ static int dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s S->computed_column_name_count = 0; S->err.sqlstate = stmt->error_code; - return 1; + return true; } static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) @@ -145,7 +144,7 @@ static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_l return DBCOUNT(H->link); } -static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype) +static bool dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; zend_bool use_national_character_set = 0; @@ -192,35 +191,35 @@ static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu *q = 0; - return 1; + return true; } -static int pdo_dblib_transaction_cmd(const char *cmd, pdo_dbh_t *dbh) +static bool pdo_dblib_transaction_cmd(const char *cmd, pdo_dbh_t *dbh) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; if (FAIL == dbcmd(H->link, cmd)) { - return 0; + return false; } if (FAIL == dbsqlexec(H->link)) { - return 0; + return false; } - return 1; + return true; } -static int dblib_handle_begin(pdo_dbh_t *dbh) +static bool dblib_handle_begin(pdo_dbh_t *dbh) { return pdo_dblib_transaction_cmd("BEGIN TRANSACTION", dbh); } -static int dblib_handle_commit(pdo_dbh_t *dbh) +static bool dblib_handle_commit(pdo_dbh_t *dbh) { return pdo_dblib_transaction_cmd("COMMIT TRANSACTION", dbh); } -static int dblib_handle_rollback(pdo_dbh_t *dbh) +static bool dblib_handle_rollback(pdo_dbh_t *dbh) { return pdo_dblib_transaction_cmd("ROLLBACK TRANSACTION", dbh); } @@ -269,28 +268,28 @@ char *dblib_handle_last_id(pdo_dbh_t *dbh, const char *name, size_t *len) return id; } -static int dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) +static bool dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; switch(attr) { case PDO_ATTR_DEFAULT_STR_PARAM: H->assume_national_character_set_strings = zval_get_long(val) == PDO_PARAM_STR_NATL ? 1 : 0; - return 1; + return true; case PDO_ATTR_TIMEOUT: case PDO_DBLIB_ATTR_QUERY_TIMEOUT: - return SUCCEED == dbsettime(zval_get_long(val)) ? 1 : 0; + return SUCCEED == dbsettime(zval_get_long(val)); case PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER: H->stringify_uniqueidentifier = zval_get_long(val); - return 1; + return true; case PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS: H->skip_empty_rowsets = zval_is_true(val); - return 1; + return true; case PDO_DBLIB_ATTR_DATETIME_CONVERT: H->datetime_convert = zval_get_long(val); - return 1; + return true; default: - return 0; + return false; } } @@ -361,7 +360,7 @@ static void dblib_get_tds_version(zval *return_value, int tds) } } -static int dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) +static bool dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; @@ -396,10 +395,10 @@ static int dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_valu break; default: - return 0; + return false; } - return 1; + return true; } static const struct pdo_dbh_methods dblib_methods = { @@ -417,7 +416,7 @@ static const struct pdo_dbh_methods dblib_methods = { NULL, /* check liveness */ NULL, /* get driver methods */ NULL, /* request shutdown */ - NULL, /* in transaction */ + NULL, /* in transaction, use PDO's internal tracking mechanism */ NULL /* get gc */ }; diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index 54aaefed6c56f..54ec5ab9f1315 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -389,7 +389,7 @@ int preprocess(const char* sql, int sql_len, char* sql_out, HashTable* named_par } strncpy(pname, start, l); pname[l] = '\0'; - + if (named_params) { zval tmp; ZVAL_LONG(&tmp, pindex); @@ -467,7 +467,7 @@ void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_lo #define RECORD_ERROR(dbh) _firebird_error(dbh, NULL, __FILE__, __LINE__) /* called by PDO to close a db handle */ -static int firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */ +static void firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; @@ -498,13 +498,11 @@ static int firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */ } pefree(H, dbh->is_persistent); - - return 0; } /* }}} */ /* called by PDO to prepare an SQL query */ -static int firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */ +static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */ pdo_stmt_t *stmt, zval *driver_options) { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; @@ -568,7 +566,7 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */ stmt->methods = &firebird_stmt_methods; stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL; - return 1; + return true; } while (0); @@ -584,7 +582,7 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */ efree(S); } - return 0; + return false; } /* }}} */ @@ -651,7 +649,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sq /* }}} */ /* called by the PDO SQL parser to add quotes to values that are copied into SQL */ -static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, /* {{{ */ +static bool firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, /* {{{ */ char **quoted, size_t *quotedlen, enum pdo_param_type paramtype) { int qcount = 0; @@ -662,7 +660,7 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t u *quotedlen = 2; *quoted = emalloc(*quotedlen+1); strcpy(*quoted, "''"); - return 1; + return true; } /* Firebird only requires single quotes to be doubled if string lengths are used */ @@ -686,12 +684,12 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t u (*quoted)[*quotedlen-1] = '\''; (*quoted)[*quotedlen] = '\0'; - return 1; + return true; } /* }}} */ /* called by PDO to start a transaction */ -static int firebird_handle_begin(pdo_dbh_t *dbh) /* {{{ */ +static bool firebird_handle_begin(pdo_dbh_t *dbh) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; char tpb[8] = { isc_tpb_version3 }, *ptpb = tpb+1; @@ -737,35 +735,35 @@ static int firebird_handle_begin(pdo_dbh_t *dbh) /* {{{ */ #endif if (isc_start_transaction(H->isc_status, &H->tr, 1, &H->db, (unsigned short)(ptpb-tpb), tpb)) { RECORD_ERROR(dbh); - return 0; + return false; } - return 1; + return true; } /* }}} */ /* called by PDO to commit a transaction */ -static int firebird_handle_commit(pdo_dbh_t *dbh) /* {{{ */ +static bool firebird_handle_commit(pdo_dbh_t *dbh) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; if (isc_commit_transaction(H->isc_status, &H->tr)) { RECORD_ERROR(dbh); - return 0; + return false; } - return 1; + return true; } /* }}} */ /* called by PDO to rollback a transaction */ -static int firebird_handle_rollback(pdo_dbh_t *dbh) /* {{{ */ +static bool firebird_handle_rollback(pdo_dbh_t *dbh) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; if (isc_rollback_transaction(H->isc_status, &H->tr)) { RECORD_ERROR(dbh); - return 0; + return false; } - return 1; + return true; } /* }}} */ @@ -789,7 +787,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, size_t s if (!firebird_handle_begin(dbh)) { return 0; } - dbh->in_txn = 1; + dbh->in_txn = true; } /* allocate the statement */ @@ -804,7 +802,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, size_t s new_sql[0] = '\0'; if (!preprocess(sql, sql_len, new_sql, named_params)) { strcpy(dbh->error_code, "07000"); - efree(new_sql); + efree(new_sql); return 0; } @@ -821,7 +819,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, size_t s /* }}} */ /* called by PDO to set a driver-specific dbh attribute */ -static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ +static bool firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; @@ -837,29 +835,29 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v /* turning on auto_commit with an open transaction is illegal, because we won't know what to do with it */ H->last_app_error = "Cannot enable auto-commit while a transaction is already open"; - return 0; + return false; } else { /* close the transaction */ if (!firebird_handle_commit(dbh)) { break; } - dbh->in_txn = 0; + dbh->in_txn = false; } } dbh->auto_commit = bval; } } - return 1; + return true; case PDO_ATTR_FETCH_TABLE_NAMES: H->fetch_table_names = zval_get_long(val)? 1 : 0; - return 1; + return true; case PDO_FB_ATTR_DATE_FORMAT: { zend_string *str = zval_try_get_string(val); if (UNEXPECTED(!str)) { - return 0; + return false; } if (H->date_format) { efree(H->date_format); @@ -867,13 +865,13 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v spprintf(&H->date_format, 0, "%s", ZSTR_VAL(str)); zend_string_release_ex(str, 0); } - return 1; + return true; case PDO_FB_ATTR_TIME_FORMAT: { zend_string *str = zval_try_get_string(val); if (UNEXPECTED(!str)) { - return 0; + return false; } if (H->time_format) { efree(H->time_format); @@ -881,13 +879,13 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v spprintf(&H->time_format, 0, "%s", ZSTR_VAL(str)); zend_string_release_ex(str, 0); } - return 1; + return true; case PDO_FB_ATTR_TIMESTAMP_FORMAT: { zend_string *str = zval_try_get_string(val); if (UNEXPECTED(!str)) { - return 0; + return false; } if (H->timestamp_format) { efree(H->timestamp_format); @@ -895,9 +893,9 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v spprintf(&H->timestamp_format, 0, "%s", ZSTR_VAL(str)); zend_string_release_ex(str, 0); } - return 1; + return true; } - return 0; + return false; } /* }}} */ @@ -914,7 +912,7 @@ static void firebird_info_cb(void *arg, char const *s) /* {{{ */ /* }}} */ /* called by PDO to get a driver-specific dbh attribute */ -static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ +static bool firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; @@ -923,11 +921,11 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v case PDO_ATTR_AUTOCOMMIT: ZVAL_LONG(val,dbh->auto_commit); - return 1; + return true; case PDO_ATTR_CONNECTION_STATUS: ZVAL_BOOL(val, !isc_version(&H->db, firebird_info_cb, NULL)); - return 1; + return true; case PDO_ATTR_CLIENT_VERSION: { #if defined(__GNUC__) || defined(PHP_WIN32) @@ -950,7 +948,7 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v ZVAL_NULL(val); #endif } - return 1; + return true; case PDO_ATTR_SERVER_VERSION: case PDO_ATTR_SERVER_INFO: @@ -958,19 +956,20 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v if (!isc_version(&H->db, firebird_info_cb, (void*)tmp)) { ZVAL_STRING(val, tmp); - return 1; + return true; } + /* TODO missing break? */ case PDO_ATTR_FETCH_TABLE_NAMES: ZVAL_BOOL(val, H->fetch_table_names); - return 1; + return true; } - return 0; + return false; } /* }}} */ /* 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 bool 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; @@ -985,11 +984,13 @@ static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval strcpy(&buf[i++], " "); } add_next_index_string(info, buf); + return true; } else if (H->last_app_error) { add_next_index_long(info, -999); add_next_index_string(info, const_cast(H->last_app_error)); + return true; } - return 1; + return false; } /* }}} */ @@ -1008,7 +1009,7 @@ static const struct pdo_dbh_methods firebird_methods = { /* {{{ */ NULL, /* check_liveness */ NULL, /* get driver methods */ NULL, /* request shutdown */ - NULL, /* in transaction */ + NULL, /* in transaction, use PDO's internal tracking mechanism */ NULL /* get gc */ }; /* }}} */ diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 830104952a9c3..3437deb52407b 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -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 bool 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; @@ -134,14 +134,15 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in if (einfo->errcode) { add_next_index_long(info, einfo->errcode); add_next_index_string(info, einfo->errmsg); + PDO_DBG_RETURN(true); } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(false); } /* }}} */ /* {{{ mysql_handle_closer */ -static int mysql_handle_closer(pdo_dbh_t *dbh) +static void mysql_handle_closer(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; @@ -157,12 +158,11 @@ static int mysql_handle_closer(pdo_dbh_t *dbh) pefree(H, dbh->is_persistent); dbh->driver_data = NULL; } - PDO_DBG_RETURN(0); } /* }}} */ /* {{{ mysql_handle_preparer */ -static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) +static bool mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt)); @@ -195,7 +195,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s } else if (ret == -1) { /* failed to parse */ strcpy(dbh->error_code, stmt->error_code); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } if (!(S->stmt = mysql_stmt_init(H->server))) { @@ -203,7 +203,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s if (nsql) { zend_string_release(nsql); } - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } if (mysql_stmt_prepare(S->stmt, ZSTR_VAL(sql), ZSTR_LEN(sql))) { @@ -218,7 +218,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s goto fallback; } pdo_mysql_error(dbh); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } if (nsql) { zend_string_release(nsql); @@ -239,13 +239,13 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s S->max_length = pdo_attr_lval(driver_options, PDO_ATTR_MAX_COLUMN_LEN, 0); - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); fallback: end: stmt->supports_placeholders = PDO_PLACEHOLDER_NONE; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ @@ -302,7 +302,7 @@ static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t * #endif /* {{{ mysql_handle_quoter */ -static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) +static bool mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; zend_bool use_national_character_set = 0; @@ -336,12 +336,12 @@ static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu (*quoted)[++*quotedlen] = '\''; (*quoted)[++*quotedlen] = '\0'; PDO_DBG_INF_FMT("quoted=%.*s", (int)*quotedlen, *quoted); - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ /* {{{ mysql_handle_begin */ -static int mysql_handle_begin(pdo_dbh_t *dbh) +static bool mysql_handle_begin(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_quoter"); PDO_DBG_INF_FMT("dbh=%p", dbh); @@ -350,28 +350,28 @@ static int mysql_handle_begin(pdo_dbh_t *dbh) /* }}} */ /* {{{ mysql_handle_commit */ -static int mysql_handle_commit(pdo_dbh_t *dbh) +static bool mysql_handle_commit(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_commit"); PDO_DBG_INF_FMT("dbh=%p", dbh); if (mysql_commit(((pdo_mysql_db_handle *)dbh->driver_data)->server)) { pdo_mysql_error(dbh); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ /* {{{ mysql_handle_rollback */ -static int mysql_handle_rollback(pdo_dbh_t *dbh) +static bool mysql_handle_rollback(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_rollback"); PDO_DBG_INF_FMT("dbh=%p", dbh); if (mysql_rollback(((pdo_mysql_db_handle *)dbh->driver_data)->server)) { pdo_mysql_error(dbh); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ @@ -390,7 +390,7 @@ static inline int mysql_handle_autocommit(pdo_dbh_t *dbh) /* }}} */ /* {{{ pdo_mysql_set_attribute */ -static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) +static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) { zend_long lval = zval_get_long(val); zend_bool bval = lval ? 1 : 0; @@ -403,29 +403,29 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) if (dbh->auto_commit ^ bval) { dbh->auto_commit = bval; if (!mysql_handle_autocommit(dbh)) { - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_ATTR_DEFAULT_STR_PARAM: ((pdo_mysql_db_handle *)dbh->driver_data)->assume_national_character_set_strings = lval == PDO_PARAM_STR_NATL; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: /* ignore if the new value equals the old one */ ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = bval; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_MYSQL_ATTR_DIRECT_QUERY: case PDO_ATTR_EMULATE_PREPARES: /* ignore if the new value equals the old one */ ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = bval; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_ATTR_FETCH_TABLE_NAMES: ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = bval; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); #ifndef PDO_USE_MYSQLND case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE: @@ -436,18 +436,18 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) } else { ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = lval; } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); break; #endif default: - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } } /* }}} */ /* {{{ pdo_mysql_get_attribute */ -static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) +static bool pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; @@ -512,15 +512,15 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_ break; default: - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ /* {{{ pdo_mysql_check_liveness */ -static int pdo_mysql_check_liveness(pdo_dbh_t *dbh) +static zend_result pdo_mysql_check_liveness(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; @@ -556,7 +556,7 @@ static void pdo_mysql_request_shutdown(pdo_dbh_t *dbh) #endif /* {{{ pdo_mysql_in_transaction */ -static int pdo_mysql_in_transaction(pdo_dbh_t *dbh) +static bool pdo_mysql_in_transaction(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; PDO_DBG_ENTER("pdo_mysql_in_transaction"); diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c index 18faa538b9eff..f912a6532a13a 100644 --- a/ext/pdo_oci/oci_driver.c +++ b/ext/pdo_oci/oci_driver.c @@ -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 bool 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; @@ -47,9 +47,10 @@ static int pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info if (einfo->errcode) { add_next_index_long(info, einfo->errcode); add_next_index_string(info, einfo->errmsg); + return true; } - return 1; + return false; } /* }}} */ @@ -185,7 +186,7 @@ ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, swor } /* }}} */ -static int oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */ +static void oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */ { pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; @@ -233,12 +234,10 @@ static int oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */ } pefree(H, dbh->is_persistent); - - return 0; } /* }}} */ -static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */ +static bool oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */ { pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; pdo_oci_stmt *S = ecalloc(1, sizeof(*S)); @@ -265,7 +264,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stm /* couldn't grok it */ strcpy(dbh->error_code, stmt->error_code); efree(S); - return 0; + return false; } /* create an OCI statement handle */ @@ -285,7 +284,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stm OCIHandleFree(S->stmt, OCI_HTYPE_STMT); OCIHandleFree(S->err, OCI_HTYPE_ERROR); efree(S); - return 0; + return false; } } @@ -306,7 +305,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stm nsql = NULL; } - return 1; + return true; } /* }}} */ @@ -354,7 +353,7 @@ static zend_long oci_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len } /* }}} */ -static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) /* {{{ */ +static bool oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) /* {{{ */ { int qcount = 0; char const *cu, *l, *r; @@ -364,7 +363,7 @@ static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquot *quotedlen = 2; *quoted = emalloc(*quotedlen+1); strcpy(*quoted, "''"); - return 1; + return true; } /* count single quotes */ @@ -387,18 +386,18 @@ static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquot (*quoted)[*quotedlen-1] = '\''; (*quoted)[*quotedlen] = '\0'; - return 1; + return true; } /* }}} */ -static int oci_handle_begin(pdo_dbh_t *dbh) /* {{{ */ +static bool oci_handle_begin(pdo_dbh_t *dbh) /* {{{ */ { /* with Oracle, there is nothing special to be done */ - return 1; + return true; } /* }}} */ -static int oci_handle_commit(pdo_dbh_t *dbh) /* {{{ */ +static bool oci_handle_commit(pdo_dbh_t *dbh) /* {{{ */ { pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; @@ -406,13 +405,13 @@ static int oci_handle_commit(pdo_dbh_t *dbh) /* {{{ */ if (H->last_err) { H->last_err = oci_drv_error("OCITransCommit"); - return 0; + return false; } - return 1; + return true; } /* }}} */ -static int oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */ +static bool oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */ { pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; @@ -420,13 +419,13 @@ static int oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */ if (H->last_err) { H->last_err = oci_drv_error("OCITransRollback"); - return 0; + return false; } - return 1; + return true; } /* }}} */ -static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ +static bool oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ { zend_long lval = zval_get_long(val); pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; @@ -440,25 +439,25 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / if (H->last_err) { H->last_err = oci_drv_error("OCITransCommit"); - return 0; + return false; } - dbh->in_txn = 0; + dbh->in_txn = false; } dbh->auto_commit = (unsigned int)lval? 1 : 0; - return 1; + return true; } case PDO_ATTR_PREFETCH: { H->prefetch = pdo_oci_sanitize_prefetch(lval); - return 1; + return true; } case PDO_OCI_ATTR_ACTION: { #if (OCI_MAJOR_VERSION >= 10) zend_string *action = zval_try_get_string(val); if (UNEXPECTED(!action)) { - return 0; + return false; } H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION, @@ -466,12 +465,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / OCI_ATTR_ACTION, H->err); if (H->last_err) { oci_drv_error("OCIAttrSet: OCI_ATTR_ACTION"); - return 0; + return false; } - return 1; + return true; #else oci_drv_error("Unsupported attribute type"); - return 0; + return false; #endif } case PDO_OCI_ATTR_CLIENT_INFO: @@ -479,7 +478,7 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / #if (OCI_MAJOR_VERSION >= 10) zend_string *client_info = zval_try_get_string(val); if (UNEXPECTED(!client_info)) { - return 0; + return false; } H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION, @@ -487,12 +486,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / OCI_ATTR_CLIENT_INFO, H->err); if (H->last_err) { oci_drv_error("OCIAttrSet: OCI_ATTR_CLIENT_INFO"); - return 0; + return false; } - return 1; + return true; #else oci_drv_error("Unsupported attribute type"); - return 0; + return false; #endif } case PDO_OCI_ATTR_CLIENT_IDENTIFIER: @@ -500,7 +499,7 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / #if (OCI_MAJOR_VERSION >= 10) zend_string *identifier = zval_try_get_string(val); if (UNEXPECTED(!identifier)) { - return 0; + return false; } H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION, @@ -508,12 +507,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / OCI_ATTR_CLIENT_IDENTIFIER, H->err); if (H->last_err) { oci_drv_error("OCIAttrSet: OCI_ATTR_CLIENT_IDENTIFIER"); - return 0; + return false; } - return 1; + return true; #else oci_drv_error("Unsupported attribute type"); - return 0; + return false; #endif } case PDO_OCI_ATTR_MODULE: @@ -521,7 +520,7 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / #if (OCI_MAJOR_VERSION >= 10) zend_string *module = zval_try_get_string(val); if (UNEXPECTED(!module)) { - return 0; + return false; } H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION, @@ -529,12 +528,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / OCI_ATTR_MODULE, H->err); if (H->last_err) { oci_drv_error("OCIAttrSet: OCI_ATTR_MODULE"); - return 0; + return false; } - return 1; + return true; #else oci_drv_error("Unsupported attribute type"); - return 0; + return false; #endif } case PDO_OCI_ATTR_CALL_TIMEOUT: @@ -547,22 +546,22 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / OCI_ATTR_CALL_TIMEOUT, H->err); if (H->last_err) { oci_drv_error("OCIAttrSet: OCI_ATTR_CALL_TIMEOUT"); - return 0; + return false; } - return 1; + return true; #else oci_drv_error("Unsupported attribute type"); - return 0; + return false; #endif } default: - return 0; + return false; } } /* }}} */ -static int oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) /* {{{ */ +static bool oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) /* {{{ */ { pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; @@ -591,7 +590,7 @@ static int oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return ZVAL_STRING(return_value, verstr); } } - return TRUE; + return true; } case PDO_ATTR_CLIENT_VERSION: @@ -608,20 +607,20 @@ static int oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return /* Compile time client version */ ZVAL_STRING(return_value, PHP_PDO_OCI_CLIENT_VERSION); #else - return FALSE; + return false; #endif /* Check for OCIClientVersion() support */ - return TRUE; + return true; } case PDO_ATTR_AUTOCOMMIT: ZVAL_BOOL(return_value, dbh->auto_commit); - return TRUE; + return true; case PDO_ATTR_PREFETCH: ZVAL_LONG(return_value, H->prefetch); - return TRUE; + return true; case PDO_OCI_ATTR_CALL_TIMEOUT: { #if (OCI_MAJOR_VERSION >= 18) @@ -632,26 +631,26 @@ static int oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return OCI_ATTR_CALL_TIMEOUT, H->err); if (H->last_err) { oci_drv_error("OCIAttrGet: OCI_ATTR_CALL_TIMEOUT"); - return FALSE; + return false; } ZVAL_LONG(return_value, (zend_long) timeout); - return TRUE; + return true; #else oci_drv_error("Unsupported attribute type"); - return FALSE; + return false; #endif } default: - return FALSE; + return false; } - return FALSE; + return false; } /* }}} */ -static int pdo_oci_check_liveness(pdo_dbh_t *dbh) /* {{{ */ +static zend_result pdo_oci_check_liveness(pdo_dbh_t *dbh) /* {{{ */ { pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; sb4 error_code = 0; @@ -705,7 +704,7 @@ static const struct pdo_dbh_methods oci_methods = { pdo_oci_check_liveness, /* check_liveness */ NULL, /* get_driver_methods */ NULL, /* request_shutdown */ - NULL, /* in_transaction */ + NULL, /* in transaction, use PDO's internal tracking mechanism */ NULL /* get_gc */ }; diff --git a/ext/pdo_oci/oci_statement.c b/ext/pdo_oci/oci_statement.c index 2a2bd58b9031f..74c59fe9c5ba0 100644 --- a/ext/pdo_oci/oci_statement.c +++ b/ext/pdo_oci/oci_statement.c @@ -760,12 +760,12 @@ static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo_ return 0; } - ZVAL_STRINFL_FAST(result, C->data, C->fetched_len); + ZVAL_STRINGL_FAST(result, C->data, C->fetched_len); return 1; } else { /* it was truncated */ php_error_docref(NULL, E_WARNING, "Column %d data was too large for buffer and was truncated to fit it", colno); - ZVAL_STRINL(result, C->data, C->fetched_len); + ZVAL_STRINGL(result, C->data, C->fetched_len); return 1; } } /* }}} */ diff --git a/ext/pdo_oci/tests/pdo_oci_stmt_getcolumnmeta.phpt b/ext/pdo_oci/tests/pdo_oci_stmt_getcolumnmeta.phpt index 65212f5c9dd97..a8ee0231cc696 100644 --- a/ext/pdo_oci/tests/pdo_oci_stmt_getcolumnmeta.phpt +++ b/ext/pdo_oci/tests/pdo_oci_stmt_getcolumnmeta.phpt @@ -51,8 +51,15 @@ SQL } // invalid offset - $tmp = @$stmt->getColumnMeta(-1); - printf(" 1.3 Expecting false got %s\n", var_export($tmp, true)); + echo " 1.3 "; + try { + $tmp = $stmt->getColumnMeta(-1); + } catch (ValueError $e) { + if (false !== $tmp) { + printf("[1.3] Expecting false got %s\n", var_export($tmp, true)); + } + echo $e->getMessage(), "\n"; + } // PDOStatement::getColumnMeta(): Argument #1 must be of type int, array given in echo " 1.4 "; @@ -311,7 +318,7 @@ Preparations before the test Test 1. calling function with invalid parameters 1.1 Expecting false got false 1.2 PDOStatement::getColumnMeta() expects exactly 1 argument, 0 given - 1.3 Expecting false got false + 1.3 PDOStatement::getColumnMeta(): Argument #1 ($column) must be greater than or equal to 0 1.4 PDOStatement::getColumnMeta(): Argument #1 ($column) must be of type int, array given 1.5 PDOStatement::getColumnMeta() expects exactly 1 argument, 2 given 1.6 Expecting false because of invalid offset got false diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c index 123d86e2cf3ff..4a673d73e0020 100644 --- a/ext/pdo_odbc/odbc_driver.c +++ b/ext/pdo_odbc/odbc_driver.c @@ -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 bool 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; @@ -48,7 +48,7 @@ static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *inf add_next_index_str(info, message); add_next_index_string(info, einfo->last_state); - return 1; + return true; } @@ -120,7 +120,7 @@ void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, } /* }}} */ -static int odbc_handle_closer(pdo_dbh_t *dbh) +static void odbc_handle_closer(pdo_dbh_t *dbh) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle*)dbh->driver_data; @@ -134,11 +134,9 @@ static int odbc_handle_closer(pdo_dbh_t *dbh) H->env = NULL; pefree(H, dbh->is_persistent); dbh->driver_data = NULL; - - return 0; } -static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) +static bool odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) { RETCODE rc; pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; @@ -162,7 +160,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st /* couldn't grok it */ strcpy(dbh->error_code, stmt->error_code); efree(S); - return 0; + return false; } rc = SQLAllocHandle(SQL_HANDLE_STMT, H->dbc, &S->stmt); @@ -173,7 +171,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st zend_string_release(nsql); } pdo_odbc_drv_error("SQLAllocStmt"); - return 0; + return false; } stmt->driver_data = S; @@ -187,7 +185,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st if (nsql) { zend_string_release(nsql); } - return 0; + return false; } } @@ -211,9 +209,9 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *st } if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - return 0; + return false; } - return 1; + return true; } static zend_long odbc_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) @@ -266,7 +264,7 @@ static int odbc_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquo } */ -static int odbc_handle_begin(pdo_dbh_t *dbh) +static bool odbc_handle_begin(pdo_dbh_t *dbh) { if (dbh->auto_commit) { /* we need to disable auto-commit now, to be able to initiate a transaction */ @@ -276,13 +274,13 @@ static int odbc_handle_begin(pdo_dbh_t *dbh) rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_IS_INTEGER); if (rc != SQL_SUCCESS) { pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = OFF"); - return 0; + return false; } } - return 1; + return true; } -static int odbc_handle_commit(pdo_dbh_t *dbh) +static bool odbc_handle_commit(pdo_dbh_t *dbh) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; RETCODE rc; @@ -293,7 +291,7 @@ static int odbc_handle_commit(pdo_dbh_t *dbh) pdo_odbc_drv_error("SQLEndTran: Commit"); if (rc != SQL_SUCCESS_WITH_INFO) { - return 0; + return false; } } @@ -302,13 +300,13 @@ static int odbc_handle_commit(pdo_dbh_t *dbh) rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_IS_INTEGER); if (rc != SQL_SUCCESS) { pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = ON"); - return 0; + return false; } } - return 1; + return true; } -static int odbc_handle_rollback(pdo_dbh_t *dbh) +static bool odbc_handle_rollback(pdo_dbh_t *dbh) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; RETCODE rc; @@ -319,7 +317,7 @@ static int odbc_handle_rollback(pdo_dbh_t *dbh) pdo_odbc_drv_error("SQLEndTran: Rollback"); if (rc != SQL_SUCCESS_WITH_INFO) { - return 0; + return false; } } if (dbh->auto_commit && H->dbc) { @@ -327,35 +325,35 @@ static int odbc_handle_rollback(pdo_dbh_t *dbh) rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_IS_INTEGER); if (rc != SQL_SUCCESS) { pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = ON"); - return 0; + return false; } } - return 1; + return true; } -static int odbc_handle_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) +static bool odbc_handle_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; switch (attr) { case PDO_ODBC_ATTR_ASSUME_UTF8: H->assume_utf8 = zval_is_true(val); - return 1; + return true; default: strcpy(H->einfo.last_err_msg, "Unknown Attribute"); H->einfo.what = "setAttribute"; strcpy(H->einfo.last_state, "IM001"); - return 0; + return false; } } -static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) +static bool odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) { pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; switch (attr) { case PDO_ATTR_CLIENT_VERSION: ZVAL_STRING(val, "ODBC-" PDO_ODBC_TYPE); - return 1; + return true; case PDO_ATTR_SERVER_VERSION: case PDO_ATTR_PREFETCH: @@ -365,10 +363,10 @@ static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) break; case PDO_ODBC_ATTR_ASSUME_UTF8: ZVAL_BOOL(val, H->assume_utf8 ? 1 : 0); - return 1; + return true; } - return 0; + return false; } static const struct pdo_dbh_methods odbc_methods = { @@ -386,7 +384,7 @@ static const struct pdo_dbh_methods odbc_methods = { NULL, /* check_liveness */ NULL, /* get_driver_methods */ NULL, /* request_shutdown */ - NULL, /* in_transaction */ + NULL, /* in transaction, use PDO's internal tracking mechanism */ NULL /* get_gc */ }; diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 3ae15e7511761..2da21e41f7c39 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -107,21 +107,25 @@ 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 bool 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; + bool return_value = false; if (einfo->errcode) { add_next_index_long(info, einfo->errcode); + return_value = true; } 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_value = true; } - return 1; + return return_value; } /* }}} */ @@ -203,7 +207,7 @@ php_stream *pdo_pgsql_create_lob_stream(zval *dbh, int lfd, Oid oid) } /* }}} */ -static int pgsql_handle_closer(pdo_dbh_t *dbh) /* {{{ */ +static void pgsql_handle_closer(pdo_dbh_t *dbh) /* {{{ */ { pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; if (H) { @@ -218,11 +222,10 @@ static int pgsql_handle_closer(pdo_dbh_t *dbh) /* {{{ */ pefree(H, dbh->is_persistent); dbh->driver_data = NULL; } - return 0; } /* }}} */ -static int pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) +static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) { pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; pdo_pgsql_stmt *S = ecalloc(1, sizeof(pdo_pgsql_stmt)); @@ -273,7 +276,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s if (ret == -1) { /* couldn't grok it */ strcpy(dbh->error_code, stmt->error_code); - return 0; + return false; } else if (ret == 1) { /* query was re-written */ S->query = nsql; @@ -287,7 +290,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *s spprintf(&S->stmt_name, 0, "pdo_stmt_%08x", ++H->stmt_counter); } - return 1; + return true; } static zend_long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) @@ -319,7 +322,7 @@ static zend_long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_l return ret; } -static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype) +static bool pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype) { unsigned char *escaped; pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; @@ -345,7 +348,7 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu (*quoted)[*quotedlen + 2] = '\0'; *quotedlen += 2; } - return 1; + return true; } static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *len) @@ -393,7 +396,7 @@ void pdo_libpq_version(char *buf, size_t len) } } -static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) +static bool pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) { pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; @@ -481,14 +484,14 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_ } default: - return 0; + return false; } - return 1; + return true; } /* {{{ */ -static int pdo_pgsql_check_liveness(pdo_dbh_t *dbh) +static zend_result pdo_pgsql_check_liveness(pdo_dbh_t *dbh) { pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; if (!PQconsumeInput(H->server) || PQstatus(H->server) == CONNECTION_BAD) { @@ -498,7 +501,7 @@ static int pdo_pgsql_check_liveness(pdo_dbh_t *dbh) } /* }}} */ -static int pgsql_handle_in_transaction(pdo_dbh_t *dbh) +static bool pgsql_handle_in_transaction(pdo_dbh_t *dbh) { pdo_pgsql_db_handle *H; @@ -507,31 +510,31 @@ static int pgsql_handle_in_transaction(pdo_dbh_t *dbh) return PQtransactionStatus(H->server) > PQTRANS_IDLE; } -static int pdo_pgsql_transaction_cmd(const char *cmd, pdo_dbh_t *dbh) +static bool pdo_pgsql_transaction_cmd(const char *cmd, pdo_dbh_t *dbh) { pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; PGresult *res; - int ret = 1; + bool ret = true; res = PQexec(H->server, cmd); if (PQresultStatus(res) != PGRES_COMMAND_OK) { pdo_pgsql_error(dbh, PQresultStatus(res), pdo_pgsql_sqlstate(res)); - ret = 0; + ret = false; } PQclear(res); return ret; } -static int pgsql_handle_begin(pdo_dbh_t *dbh) +static bool pgsql_handle_begin(pdo_dbh_t *dbh) { return pdo_pgsql_transaction_cmd("BEGIN", dbh); } -static int pgsql_handle_commit(pdo_dbh_t *dbh) +static bool pgsql_handle_commit(pdo_dbh_t *dbh) { - int ret = pdo_pgsql_transaction_cmd("COMMIT", dbh); + bool ret = pdo_pgsql_transaction_cmd("COMMIT", dbh); /* When deferred constraints are used the commit could fail, and a ROLLBACK implicitly ran. See bug #67462 */ @@ -542,7 +545,7 @@ static int pgsql_handle_commit(pdo_dbh_t *dbh) return ret; } -static int pgsql_handle_rollback(pdo_dbh_t *dbh) +static bool pgsql_handle_rollback(pdo_dbh_t *dbh) { return pdo_pgsql_transaction_cmd("ROLLBACK", dbh); } @@ -1149,7 +1152,7 @@ static const zend_function_entry *pdo_pgsql_get_driver_methods(pdo_dbh_t *dbh, i } } -static int pdo_pgsql_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) +static bool pdo_pgsql_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) { zend_bool bval = zval_get_long(val)? 1 : 0; pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; @@ -1157,12 +1160,12 @@ static int pdo_pgsql_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) switch (attr) { case PDO_ATTR_EMULATE_PREPARES: H->emulate_prepares = bval; - return 1; + return true; case PDO_PGSQL_ATTR_DISABLE_PREPARES: H->disable_prepares = bval; - return 1; + return true; default: - return 0; + return false; } } diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c index fcf82c62bf132..3b46afc1ead9f 100644 --- a/ext/pdo_sqlite/sqlite_driver.c +++ b/ext/pdo_sqlite/sqlite_driver.c @@ -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 bool 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; @@ -90,9 +90,10 @@ static int pdo_sqlite_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *i if (einfo->errcode) { add_next_index_long(info, einfo->errcode); add_next_index_string(info, einfo->errmsg); + return true; } - return 1; + return false; } static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H) @@ -148,7 +149,7 @@ static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H) } } -static int sqlite_handle_closer(pdo_dbh_t *dbh) /* {{{ */ +static void sqlite_handle_closer(pdo_dbh_t *dbh) /* {{{ */ { pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; @@ -171,11 +172,10 @@ static int sqlite_handle_closer(pdo_dbh_t *dbh) /* {{{ */ pefree(H, dbh->is_persistent); dbh->driver_data = NULL; } - return 0; } /* }}} */ -static int sqlite_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) +static bool sqlite_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) { pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; pdo_sqlite_stmt *S = ecalloc(1, sizeof(pdo_sqlite_stmt)); @@ -190,17 +190,17 @@ static int sqlite_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t * if (PDO_CURSOR_FWDONLY != pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY)) { H->einfo.errcode = SQLITE_ERROR; pdo_sqlite_error(dbh); - return 0; + return false; } i = sqlite3_prepare_v2(H->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &S->stmt, &tail); if (i == SQLITE_OK) { - return 1; + return true; } pdo_sqlite_error(dbh); - return 0; + return false; } static zend_long sqlite_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) @@ -230,15 +230,15 @@ static char *pdo_sqlite_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t } /* NB: doesn't handle binary strings... use prepared stmts for that */ -static int sqlite_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) +static bool sqlite_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) { *quoted = safe_emalloc(2, unquotedlen, 3); sqlite3_snprintf(2*unquotedlen + 3, *quoted, "'%q'", unquoted); *quotedlen = strlen(*quoted); - return 1; + return true; } -static int sqlite_handle_begin(pdo_dbh_t *dbh) +static bool sqlite_handle_begin(pdo_dbh_t *dbh) { pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; char *errmsg = NULL; @@ -247,12 +247,12 @@ static int sqlite_handle_begin(pdo_dbh_t *dbh) pdo_sqlite_error(dbh); if (errmsg) sqlite3_free(errmsg); - return 0; + return false; } - return 1; + return true; } -static int sqlite_handle_commit(pdo_dbh_t *dbh) +static bool sqlite_handle_commit(pdo_dbh_t *dbh) { pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; char *errmsg = NULL; @@ -261,12 +261,12 @@ static int sqlite_handle_commit(pdo_dbh_t *dbh) pdo_sqlite_error(dbh); if (errmsg) sqlite3_free(errmsg); - return 0; + return false; } - return 1; + return true; } -static int sqlite_handle_rollback(pdo_dbh_t *dbh) +static bool sqlite_handle_rollback(pdo_dbh_t *dbh) { pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; char *errmsg = NULL; @@ -275,12 +275,12 @@ static int sqlite_handle_rollback(pdo_dbh_t *dbh) pdo_sqlite_error(dbh); if (errmsg) sqlite3_free(errmsg); - return 0; + return false; } - return 1; + return true; } -static int pdo_sqlite_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) +static bool pdo_sqlite_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) { switch (attr) { case PDO_ATTR_CLIENT_VERSION: @@ -289,25 +289,25 @@ static int pdo_sqlite_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return break; default: - return 0; + return false; } - return 1; + return true; } -static int pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) +static bool pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) { pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data; switch (attr) { case PDO_ATTR_TIMEOUT: sqlite3_busy_timeout(H->db, zval_get_long(val) * 1000); - return 1; + return true; case PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES: sqlite3_extended_result_codes(H->db, zval_get_long(val)); - return 1; + return true; } - return 0; + return false; } typedef struct { @@ -729,7 +729,7 @@ static const struct pdo_dbh_methods sqlite_methods = { NULL, /* check_liveness: not needed */ get_driver_methods, pdo_sqlite_request_shutdown, - NULL, /* in_transaction */ + NULL, /* in transaction, use PDO's internal tracking mechanism */ pdo_sqlite_get_gc };