]> granicus.if.org Git - php/commitdiff
- Fixed bug #61267: pdo_pgsql's PDO::exec() returns the number of SELECTed
authorGustavo André dos Santos Lopes <cataphract@php.net>
Thu, 8 Mar 2012 08:52:28 +0000 (08:52 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Thu, 8 Mar 2012 08:52:28 +0000 (08:52 +0000)
  rows on postgresql >= 9

ext/pdo_pgsql/pgsql_driver.c
ext/pdo_pgsql/tests/bug61267.phpt [new file with mode: 0644]

index d96c3e8e356f5f866d03b5d34689d0953f01dabb..23ea5e58a256cee2aa4af3c3bd6d464045b59bb9 100644 (file)
@@ -299,7 +299,7 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
                return -1;
        }
        H->pgoid = PQoidValue(res);
-       ret = atol(PQcmdTuples(res));
+       ret = (qs == PGRES_COMMAND_OK) ? atol(PQcmdTuples(res)) : 0L;
        PQclear(res);
 
        return ret;
diff --git a/ext/pdo_pgsql/tests/bug61267.phpt b/ext/pdo_pgsql/tests/bug61267.phpt
new file mode 100644 (file)
index 0000000..4214cd9
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+PDO::exec() returns 0 when the statement is a SELECT.
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
+require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+require_once dirname(__FILE__) . '/config.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+require_once dirname(__FILE__) . '/config.inc';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+
+$res = $db->exec('SELECT * from generate_series(1, 42);');
+var_dump($res);
+echo "Done\n";
+?>
+--EXPECTF--
+int(0)
+Done