]> granicus.if.org Git - php/commitdiff
Fix bug #69344 (PDO PgSQL Incorrect binding numeric array with gaps)
authorMatteo Beccati <mbeccati@php.net>
Thu, 11 Jun 2015 23:57:22 +0000 (01:57 +0200)
committerMatteo Beccati <mbeccati@php.net>
Fri, 12 Jun 2015 00:05:28 +0000 (02:05 +0200)
NEWS
ext/pdo_pgsql/pgsql_statement.c
ext/pdo_pgsql/tests/bug69344.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 80c2f9e7d84737d1ace286888b3555f3afc76f0e..7d962d2a083f1bb5be5b9c57046352c5f40bf010 100644 (file)
--- 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
index 75c5a4a0419fba76209e2c8b622699c282af8571..51402c3e530dd5a48c50a5bb2f501c9f2dc2437c 100644 (file)
@@ -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 (file)
index 0000000..4349814
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+PDO PgSQL Bug #69344 (PDO PgSQL Incorrect binding numeric array with gaps)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not l$
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$pdo = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$pdo->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
+