mbeccati Wed, 04 Nov 2009 19:32:27 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=290214
Log:
- Properly fixed bug #49985 (pdo_pgsql prepare() re-use previous aborted
transaction).
# Removed usage of the memory address when generating prepared statemend names
# as uniqueness can't be enforced. Used a statment counter instead.
Bug: http://bugs.php.net/49985 (Closed) pdo_pgsql prepare() re-use previous
aborted transaction
Changed paths:
U php/php-src/branches/PHP_5_2/NEWS
U php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_driver.c
U php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_statement.c
U php/php-src/branches/PHP_5_2/ext/pdo_pgsql/php_pdo_pgsql_int.h
A php/php-src/branches/PHP_5_2/ext/pdo_pgsql/tests/bug_49985.phpt
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_driver.c
U php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_statement.c
U php/php-src/branches/PHP_5_3/ext/pdo_pgsql/php_pdo_pgsql_int.h
A php/php-src/branches/PHP_5_3/ext/pdo_pgsql/tests/bug_49985.phpt
U php/php-src/trunk/ext/pdo_pgsql/pgsql_driver.c
U php/php-src/trunk/ext/pdo_pgsql/pgsql_statement.c
U php/php-src/trunk/ext/pdo_pgsql/php_pdo_pgsql_int.h
A php/php-src/trunk/ext/pdo_pgsql/tests/bug_49985.phpt
Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_2/NEWS 2009-11-04 19:32:27 UTC (rev 290214)
@@ -24,7 +24,7 @@
- Fixed bug #49990 (SNMP3 warning message about security level printed twice).
(Jani)
- Fixed bug #49985 (pdo_pgsql prepare() re-use previous aborted
- transaction). (ben dot pineau at gmail dot com, Ilia)
+ transaction). (ben dot pineau at gmail dot com, Ilia, Matteo)
- Fixed bug #49921 (Curl post upload functions changed). (Ilia)
- Fixed bug #49972 (AppendIterator undefined function crash). (Johannes)
- Fixed bug #49855 (import_request_variables() always returns NULL). (Ilia,
Modified: php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_driver.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_driver.c 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_driver.c 2009-11-04 19:32:27 UTC (rev 290214)
@@ -233,7 +233,7 @@
efree(S->cursor_name);
}
/* TODO: check how scrollable cursors related to prepared statements */
- spprintf(&S->cursor_name, 0, "pdo_pgsql_cursor_%08x", (unsigned int) stmt);
+ spprintf(&S->cursor_name, 0, "pdo_crsr_%08x", ++H->stmt_counter);
}
#if HAVE_PQPREPARE
@@ -261,7 +261,7 @@
return 0;
}
- spprintf(&S->stmt_name, 0, "pdo_pgsql_stmt_%08x", (unsigned int)stmt);
+ spprintf(&S->stmt_name, 0, "pdo_stmt_%08x", ++H->stmt_counter);
/* that's all for now; we'll defer the actual prepare until the first execute call */
if (nsql) {
Modified: php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_statement.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_statement.c 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_2/ext/pdo_pgsql/pgsql_statement.c 2009-11-04 19:32:27 UTC (rev 290214)
@@ -157,7 +157,7 @@
* deallocate it and retry ONCE (thies 2005.12.15)
*/
if (!strcmp(sqlstate, "42P05")) {
- char buf[100]; /* stmt_name == "pdo_pgsql_cursor_%08x" */
+ char buf[100]; /* stmt_name == "pdo_crsr_%08x" */
PGresult *res;
snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name);
res = PQexec(H->server, buf);
Modified: php/php-src/branches/PHP_5_2/ext/pdo_pgsql/php_pdo_pgsql_int.h
===================================================================
--- php/php-src/branches/PHP_5_2/ext/pdo_pgsql/php_pdo_pgsql_int.h 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_2/ext/pdo_pgsql/php_pdo_pgsql_int.h 2009-11-04 19:32:27 UTC (rev 290214)
@@ -50,6 +50,7 @@
int emulate_prepares;
int disable_native_prepares;
#endif
+ unsigned int stmt_counter;
} pdo_pgsql_db_handle;
typedef struct {
Added: php/php-src/branches/PHP_5_2/ext/pdo_pgsql/tests/bug_49985.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/pdo_pgsql/tests/bug_49985.phpt (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/pdo_pgsql/tests/bug_49985.phpt 2009-11-04 19:32:27 UTC (rev 290214)
@@ -0,0 +1,35 @@
+--TEST--
+Bug #49985 (pdo_pgsql prepare() re-use previous aborted transaction)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
+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';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$db->exec("CREATE TABLE test (a int PRIMARY KEY)");
+
+for ($i = 0; $i < 3; $i++) {
+ try {
+ $db->beginTransaction();
+ $stmt = $db->prepare("INSERT INTO test (a) VALUES (?)");
+ var_dump($stmt->execute(array(1)));
+ $db->commit();
+ } catch (Exception $e) {
+ echo $e->getMessage()."\n";
+ $db->rollback();
+ }
+}
+
+?>
+--EXPECTF--
+bool(true)
+SQLSTATE[23505]: %s"test_pkey"
+SQLSTATE[23505]: %s"test_pkey"
+
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_3/NEWS 2009-11-04 19:32:27 UTC (rev 290214)
@@ -28,7 +28,7 @@
- Fixed bug #49990 (SNMP3 warning message about security level printed twice).
(Jani)
- Fixed bug #49985 (pdo_pgsql prepare() re-use previous aborted
- transaction). (ben dot pineau at gmail dot com, Ilia)
+ transaction). (ben dot pineau at gmail dot com, Ilia, Matteo)
- Fixed bug #49921 (Curl post upload functions changed). (Ilia)
- Fixed bug #49855 (import_request_variables() always returns NULL). (Ilia,
sjoerd at php dot net)
Modified: php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_driver.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_driver.c 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_driver.c 2009-11-04 19:32:27 UTC (rev 290214)
@@ -232,7 +232,7 @@
if (S->cursor_name) {
efree(S->cursor_name);
}
- spprintf(&S->cursor_name, 0, "pdo_crsr_%016lx", (unsigned long) stmt);
+ spprintf(&S->cursor_name, 0, "pdo_crsr_%08x", ++H->stmt_counter);
#if HAVE_PQPREPARE
emulate = 1;
#endif
@@ -262,7 +262,7 @@
return 0;
}
- spprintf(&S->stmt_name, 0, "pdo_stmt_%016lx", (unsigned long)stmt);
+ spprintf(&S->stmt_name, 0, "pdo_stmt_%08x", ++H->stmt_counter);
/* that's all for now; we'll defer the actual prepare until the first execute call */
if (nsql) {
Modified: php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_statement.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_statement.c 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_3/ext/pdo_pgsql/pgsql_statement.c 2009-11-04 19:32:27 UTC (rev 290214)
@@ -185,7 +185,7 @@
* deallocate it and retry ONCE (thies 2005.12.15)
*/
if (!strcmp(sqlstate, "42P05")) {
- char buf[100]; /* stmt_name == "pdo_crsr_%016lx" */
+ char buf[100]; /* stmt_name == "pdo_crsr_%08x" */
PGresult *res;
snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name);
res = PQexec(H->server, buf);
Modified: php/php-src/branches/PHP_5_3/ext/pdo_pgsql/php_pdo_pgsql_int.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_pgsql/php_pdo_pgsql_int.h 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/branches/PHP_5_3/ext/pdo_pgsql/php_pdo_pgsql_int.h 2009-11-04 19:32:27 UTC (rev 290214)
@@ -50,6 +50,7 @@
int emulate_prepares;
int disable_native_prepares;
#endif
+ unsigned int stmt_counter;
} pdo_pgsql_db_handle;
typedef struct {
Added: php/php-src/branches/PHP_5_3/ext/pdo_pgsql/tests/bug_49985.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_pgsql/tests/bug_49985.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/pdo_pgsql/tests/bug_49985.phpt 2009-11-04 19:32:27 UTC (rev 290214)
@@ -0,0 +1,35 @@
+--TEST--
+Bug #49985 (pdo_pgsql prepare() re-use previous aborted transaction)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
+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';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$db->exec("CREATE TABLE test (a int PRIMARY KEY)");
+
+for ($i = 0; $i < 3; $i++) {
+ try {
+ $db->beginTransaction();
+ $stmt = $db->prepare("INSERT INTO test (a) VALUES (?)");
+ var_dump($stmt->execute(array(1)));
+ $db->commit();
+ } catch (Exception $e) {
+ echo $e->getMessage()."\n";
+ $db->rollback();
+ }
+}
+
+?>
+--EXPECTF--
+bool(true)
+SQLSTATE[23505]: %s"test_pkey"
+SQLSTATE[23505]: %s"test_pkey"
+
Modified: php/php-src/trunk/ext/pdo_pgsql/pgsql_driver.c
===================================================================
--- php/php-src/trunk/ext/pdo_pgsql/pgsql_driver.c 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/trunk/ext/pdo_pgsql/pgsql_driver.c 2009-11-04 19:32:27 UTC (rev 290214)
@@ -232,7 +232,7 @@
if (S->cursor_name) {
efree(S->cursor_name);
}
- spprintf(&S->cursor_name, 0, "pdo_crsr_%016lx", (unsigned long) stmt);
+ spprintf(&S->cursor_name, 0, "pdo_crsr_%08x", ++H->stmt_counter);
#if HAVE_PQPREPARE
emulate = 1;
#endif
@@ -262,7 +262,7 @@
return 0;
}
- spprintf(&S->stmt_name, 0, "pdo_stmt_%016lx", (unsigned long)stmt);
+ spprintf(&S->stmt_name, 0, "pdo_stmt_%08x", ++H->stmt_counter);
/* that's all for now; we'll defer the actual prepare until the first execute call */
if (nsql) {
Modified: php/php-src/trunk/ext/pdo_pgsql/pgsql_statement.c
===================================================================
--- php/php-src/trunk/ext/pdo_pgsql/pgsql_statement.c 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/trunk/ext/pdo_pgsql/pgsql_statement.c 2009-11-04 19:32:27 UTC (rev 290214)
@@ -185,7 +185,7 @@
* deallocate it and retry ONCE (thies 2005.12.15)
*/
if (!strcmp(sqlstate, "42P05")) {
- char buf[100]; /* stmt_name == "pdo_crsr_%016lx" */
+ char buf[100]; /* stmt_name == "pdo_crsr_%08x" */
PGresult *res;
snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name);
res = PQexec(H->server, buf);
Modified: php/php-src/trunk/ext/pdo_pgsql/php_pdo_pgsql_int.h
===================================================================
--- php/php-src/trunk/ext/pdo_pgsql/php_pdo_pgsql_int.h 2009-11-04 19:26:37 UTC (rev 290213)
+++ php/php-src/trunk/ext/pdo_pgsql/php_pdo_pgsql_int.h 2009-11-04 19:32:27 UTC (rev 290214)
@@ -50,6 +50,7 @@
int emulate_prepares;
int disable_native_prepares;
#endif
+ unsigned int stmt_counter;
} pdo_pgsql_db_handle;
typedef struct {
Added: php/php-src/trunk/ext/pdo_pgsql/tests/bug_49985.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_pgsql/tests/bug_49985.phpt (rev 0)
+++ php/php-src/trunk/ext/pdo_pgsql/tests/bug_49985.phpt 2009-11-04 19:32:27 UTC (rev 290214)
@@ -0,0 +1,35 @@
+--TEST--
+Bug #49985 (pdo_pgsql prepare() re-use previous aborted transaction)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
+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';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$db->exec("CREATE TABLE test (a int PRIMARY KEY)");
+
+for ($i = 0; $i < 3; $i++) {
+ try {
+ $db->beginTransaction();
+ $stmt = $db->prepare("INSERT INTO test (a) VALUES (?)");
+ var_dump($stmt->execute(array(1)));
+ $db->commit();
+ } catch (Exception $e) {
+ echo $e->getMessage()."\n";
+ $db->rollback();
+ }
+}
+
+?>
+--EXPECTF--
+bool(true)
+SQLSTATE[23505]: %s"test_pkey"
+SQLSTATE[23505]: %s"test_pkey"
+
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php