Permalink
Browse files

- Fixed bug #61267: pdo_pgsql's PDO::exec() returns the number of SEL…

…ECTed

  rows on postgresql >= 9
  • Loading branch information...
1 parent ef61504 commit fee191658d2d51e76911f1d804cf6458ee9243e8 @cataphract cataphract committed Mar 8, 2012
Showing with 23 additions and 1 deletion.
  1. +1 −1 ext/pdo_pgsql/pgsql_driver.c
  2. +22 −0 ext/pdo_pgsql/tests/bug61267.phpt
@@ -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;
@@ -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

0 comments on commit fee1916

Please sign in to comment.