Skip to content

Commit

Permalink
Avoid UNKNOWN default in PDO::query()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Jul 24, 2020
1 parent 70a3a90 commit 7eec281
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,11 @@ PHP 8.0 UPGRADE NOTES
"exceptions". See https://www.php.net/manual/en/pdo.error-handling.php
for details of behavior changes and how to explicitly set this attribute.
RFC: https://wiki.php.net/rfc/pdo_default_errmode
. The method PDOStatement::setFetchMode() now accepts the following signature:
. The signatures of some PDO methods have changed:

PDOStatement::setFetchMode($mode, $classname, $params)
PDO::query(
string $statement, ?int $fetch_mode = null, ...$fetch_mode_args)
PDOStatement::setFetchMode(int $mode, ...$params)

- PDO_ODBC:
. The php.ini directive pdo_odbc.db2_instance_name has been removed
Expand Down
5 changes: 3 additions & 2 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,12 +1026,13 @@ PHP_METHOD(PDO, query)
char *statement;
size_t statement_len;
zend_long fetch_mode;
zend_bool fetch_mode_is_null = 1;
zval *args = NULL;
uint32_t num_args = 0;
pdo_dbh_object_t *dbh_obj = Z_PDO_OBJECT_P(ZEND_THIS);
pdo_dbh_t *dbh = dbh_obj->inner;

if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l*", &statement, &statement_len, &fetch_mode, &args, &num_args)) {
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l!*", &statement, &statement_len, &fetch_mode, &fetch_mode_is_null, &args, &num_args)) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -1061,7 +1062,7 @@ PHP_METHOD(PDO, query)

if (dbh->methods->preparer(dbh, statement, statement_len, stmt, NULL)) {
PDO_STMT_CLEAR_ERR();
if (ZEND_NUM_ARGS() == 1 || SUCCESS == pdo_stmt_setup_fetch_mode(stmt, fetch_mode, args, num_args)) {
if (fetch_mode_is_null || SUCCESS == pdo_stmt_setup_fetch_mode(stmt, fetch_mode, args, num_args)) {

/* now execute the statement */
PDO_STMT_CLEAR_ERR();
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo/pdo_dbh.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function lastInsertId(?string $name = null) {}
public function prepare(string $statement, array $driver_options = []) {}

/** @return PDOStatement|false */
public function query(string $statement, int $fetch_mode = UNKNOWN, ...$fetch_mode_args) {}
public function query(string $statement, ?int $fetch_mode = null, ...$fetch_mode_args) {}

/** @return string|false */
public function quote(string $string, int $parameter_type = PDO::PARAM_STR) {}
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo/pdo_dbh_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: c329bfda55244467a2cd62f9d5c5120ec3f24eef */
* Stub hash: 36270d1418fc4ddd8f79018372b0ef00fb6f5889 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, dsn, IS_STRING, 0)
Expand Down Expand Up @@ -40,7 +40,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_query, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, statement, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, fetch_mode, IS_LONG, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fetch_mode, IS_LONG, 1, "null")
ZEND_ARG_VARIADIC_INFO(0, fetch_mode_args)
ZEND_END_ARG_INFO()

Expand Down
2 changes: 1 addition & 1 deletion ext/pdo/tests/bug_44173.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var_dump($stmt);
--EXPECTF--
Warning: PDO::query(): SQLSTATE[HY000]: General error: fetch mode doesn't allow any extra arguments in %s
bool(false)
PDO::query(): Argument #2 ($fetch_mode) must be of type int, string given
PDO::query(): Argument #2 ($fetch_mode) must be of type ?int, string given

Warning: PDO::query(): SQLSTATE[HY000]: General error: too many arguments in %s
bool(false)
Expand Down

0 comments on commit 7eec281

Please sign in to comment.