Merge branch 'PHP-5.5' into PHP-5.6

* PHP-5.5:
  Added PGSQL_TEST_CONNSTR env var support for ext/pgsql tests
  Fixed bug #67462 PDO_PGSQL::beginTransaction() wrongly throws exception when not in transaction
This commit is contained in:
Matteo Beccati 2014-10-31 18:57:59 +01:00
commit e797db8909
3 changed files with 59 additions and 15 deletions

View File

@ -465,6 +465,15 @@ static int pdo_pgsql_check_liveness(pdo_dbh_t *dbh TSRMLS_DC)
}
/* }}} */
static int pgsql_handle_in_transaction(pdo_dbh_t *dbh TSRMLS_DC)
{
pdo_pgsql_db_handle *H;
H = (pdo_pgsql_db_handle *)dbh->driver_data;
return PQtransactionStatus(H->server) > PQTRANS_IDLE;
}
static int pdo_pgsql_transaction_cmd(const char *cmd, pdo_dbh_t *dbh TSRMLS_DC)
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
@ -489,7 +498,15 @@ static int pgsql_handle_begin(pdo_dbh_t *dbh TSRMLS_DC)
static int pgsql_handle_commit(pdo_dbh_t *dbh TSRMLS_DC)
{
return pdo_pgsql_transaction_cmd("COMMIT", dbh TSRMLS_CC);
int ret = pdo_pgsql_transaction_cmd("COMMIT", dbh TSRMLS_CC);
/* When deferred constraints are used the commit could
fail, and a ROLLBACK implicitly ran. See bug #67462 */
if (!ret) {
dbh->in_txn = pgsql_handle_in_transaction(dbh);
}
return ret;
}
static int pgsql_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC)
@ -497,15 +514,6 @@ static int pgsql_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC)
return pdo_pgsql_transaction_cmd("ROLLBACK", dbh TSRMLS_CC);
}
static int pgsql_handle_in_transaction(pdo_dbh_t *dbh TSRMLS_DC)
{
pdo_pgsql_db_handle *H;
H = (pdo_pgsql_db_handle *)dbh->driver_data;
return PQtransactionStatus(H->server);
}
/* {{{ proto string PDO::pgsqlCopyFromArray(string $table_name , array $rows [, string $delimiter [, string $null_as ] [, string $fields])
Returns true if the copy worked fine or false if error */
static PHP_METHOD(PDO, pgsqlCopyFromArray)

View File

@ -0,0 +1,34 @@
--TEST--
PDO PgSQL Bug #67462 (PDO_PGSQL::beginTransaction() wrongly throws exception when not in 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';
$pdo = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
try {
$pdo->query("CREATE TABLE b67462 (a int NOT NULL PRIMARY KEY DEFERRABLE INITIALLY DEFERRED)");
$pdo->query("INSERT INTO b67462 VALUES (1), (1)");
var_dump($pdo->inTransaction());
$pdo->commit(); // This should fail!
} catch (\Exception $e) {
var_dump($pdo->inTransaction());
var_dump($pdo->beginTransaction());
}
?>
--EXPECT--
bool(true)
bool(false)
bool(true)

View File

@ -1,10 +1,12 @@
<?php
// These vars are used to connect db and create test table.
// values can be set to meet your environment
// "test" database must be existed. i.e. "createdb test" before testing
// PostgreSQL uses login name as username, user must have access to "test" database.
$conn_str = "host=localhost dbname=test port=5432"; // connection string
// These vars are used to connect db and create test table.
// values can be set to meet your environment with the
// environment var PGSQL_TEST_CONNSTR
// "test" database must exist. i.e. "createdb test" before testing
$conn_str = getenv('PGSQL_TEST_CONNSTR') ?: "host=localhost dbname=test port=5432"; // connection string
$table_name = "php_pgsql_test"; // test table that will be created
$table_name_92 = "php_pgsql_test_92"; // test table that will be created
$num_test_record = 1000; // Number of records to create