From b60efdce9fe7e168ba37070a4307269483a66ea4 Mon Sep 17 00:00:00 2001 From: Matteo Beccati Date: Fri, 12 Jun 2015 01:57:22 +0200 Subject: [PATCH] Fix bug #69344 (PDO PgSQL Incorrect binding numeric array with gaps) --- NEWS | 2 ++ ext/pdo_pgsql/pgsql_statement.c | 4 +-- ext/pdo_pgsql/tests/bug69344.phpt | 44 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 ext/pdo_pgsql/tests/bug69344.phpt diff --git a/NEWS b/NEWS index 80c2f9e7d8..7d962d2a08 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ Statements when closeCuror() is u). (Philip Hofstetter) . Fixed bug #69362 (PDO-pgsql fails to connect if password contains a leading single quote). (Matteo) + . Fixed bug #69344 (PDO PgSQL Incorrect binding numeric array with gaps). + (Matteo) - SimpleXML: . Refactored the fix for bug #66084 (simplexml_load_string() mangles empty diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 75c5a4a041..51402c3e53 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -294,8 +294,8 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data * sizeof(Oid)); } if (param->paramno >= 0) { - if (param->paramno >= zend_hash_num_elements(stmt->bound_param_map)) { - pdo_pgsql_error_stmt(stmt, PGRES_FATAL_ERROR, "HY105"); + if (param->paramno >= zend_hash_num_elements(stmt->bound_params)) { + pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC); return 0; } diff --git a/ext/pdo_pgsql/tests/bug69344.phpt b/ext/pdo_pgsql/tests/bug69344.phpt new file mode 100644 index 0000000000..43498145ac --- /dev/null +++ b/ext/pdo_pgsql/tests/bug69344.phpt @@ -0,0 +1,44 @@ +--TEST-- +PDO PgSQL Bug #69344 (PDO PgSQL Incorrect binding numeric array with gaps) +--SKIPIF-- + +--FILE-- +setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); +$pdo->setAttribute (\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); + +$test = function () use ($pdo) { + $arr = [ + 0 => "a", + 2 => "b", + ]; + + $stmt = $pdo->prepare("SELECT (?)::text AS a, (?)::text AS b"); + + try { + $stmt->execute($arr); + var_dump($stmt->fetch()); + } catch (\Exception $e) { + echo $e->getMessage()."\n"; + } +}; + +$test(); + +$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); + +$test(); + +?> +--EXPECT-- +SQLSTATE[HY093]: Invalid parameter number: parameter was not defined +SQLSTATE[HY093]: Invalid parameter number: parameter was not defined + -- 2.40.0