diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-02-01 21:25:15 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-02-01 21:25:15 +0100 |
commit | 96fb2ff5760132a915766f1d9ec7c63001feacd8 (patch) | |
tree | 160904a89a8f3522fa4e47632db101b045e7814a /ext/pdo_pgsql | |
parent | 8f1428d29ef91d74b4d272af171675f2971eb15b (diff) | |
download | php-96fb2ff5760132a915766f1d9ec7c63001feacd8.tar.gz |
Imported Upstream version 5.4.0~rc6upstream/5.4.0_rc6
Diffstat (limited to 'ext/pdo_pgsql')
-rw-r--r-- | ext/pdo_pgsql/config.m4 | 12 | ||||
-rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 14 | ||||
-rw-r--r-- | ext/pdo_pgsql/tests/is_in_transaction.phpt | 66 |
3 files changed, 84 insertions, 8 deletions
diff --git a/ext/pdo_pgsql/config.m4 b/ext/pdo_pgsql/config.m4 index 329cdc365..5c01c4680 100644 --- a/ext/pdo_pgsql/config.m4 +++ b/ext/pdo_pgsql/config.m4 @@ -1,4 +1,4 @@ -dnl $Id: config.m4 311041 2011-05-15 05:49:34Z rasmus $ +dnl $Id: config.m4 311040 2011-05-15 05:24:34Z rasmus $ dnl config.m4 for extension pdo_pgsql dnl vim:et:sw=2:ts=2: @@ -110,18 +110,18 @@ if test "$PHP_PDO_PGSQL" != "no"; then ],[ AC_MSG_CHECKING([for PDO includes]) if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then - pdo_inc_path=$abs_srcdir/ext + pdo_cv_inc_path=$abs_srcdir/ext elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then - pdo_inc_path=$abs_srcdir/ext + pdo_cv_inc_path=$abs_srcdir/ext elif test -f $prefix/include/php/ext/pdo/php_pdo_driver.h; then - pdo_inc_path=$prefix/include/php/ext + pdo_cv_inc_path=$prefix/include/php/ext else AC_MSG_ERROR([Cannot find php_pdo_driver.h.]) fi - AC_MSG_RESULT($pdo_inc_path) + AC_MSG_RESULT($pdo_cv_inc_path) ]) - PHP_NEW_EXTENSION(pdo_pgsql, pdo_pgsql.c pgsql_driver.c pgsql_statement.c, $ext_shared,,-I$pdo_inc_path $PDO_PGSQL_CFLAGS) + PHP_NEW_EXTENSION(pdo_pgsql, pdo_pgsql.c pgsql_driver.c pgsql_statement.c, $ext_shared,,-I$pdo_cv_inc_path $PDO_PGSQL_CFLAGS) ifdef([PHP_ADD_EXTENSION_DEP], [ PHP_ADD_EXTENSION_DEP(pdo_pgsql, pdo) diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 78cc926b1..27ce1cdff 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -497,6 +497,15 @@ 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) @@ -619,7 +628,7 @@ static PHP_METHOD(PDO, pgsqlCopyFromFile) ExecStatusType status; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|sss", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sp|sss", &table_name, &table_name_len, &filename, &filename_len, &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len, &pg_fields, &pg_fields_len) == FAILURE) { return; @@ -713,7 +722,7 @@ static PHP_METHOD(PDO, pgsqlCopyToFile) php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|sss", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sp|sss", &table_name, &table_name_len, &filename, &filename_len, &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len, &pg_fields, &pg_fields_len) == FAILURE) { return; @@ -1022,6 +1031,7 @@ static struct pdo_dbh_methods pgsql_methods = { pdo_pgsql_check_liveness, /* check_liveness */ pdo_pgsql_get_driver_methods, /* get_driver_methods */ NULL, + pgsql_handle_in_transaction, }; static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC) /* {{{ */ diff --git a/ext/pdo_pgsql/tests/is_in_transaction.phpt b/ext/pdo_pgsql/tests/is_in_transaction.phpt new file mode 100644 index 000000000..99ff56162 --- /dev/null +++ b/ext/pdo_pgsql/tests/is_in_transaction.phpt @@ -0,0 +1,66 @@ +--TEST-- +PDO PgSQL isInTransaction +--SKIPIF-- +<?php # vim:se ft=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->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + +$db->exec('CREATE TABLE test (a integer not null primary key, b text)'); + +$db->beginTransaction(); +try { +echo "Test PDO::PGSQL_TRANSACTION_INTRANS\n"; +var_dump($db->inTransaction()); + +$stmt = $db->prepare("INSERT INTO test (a, b) values (?, ?)"); +$stmt->bindValue(1, 1); +$stmt->bindValue(2, "test insert"); +$stmt->execute(); + +$db->commit(); + +echo "Test PDO::PGSQL_TRANSACTION_IDLE\n"; +var_dump($db->inTransaction()); + +$db->beginTransaction(); + +try { +$stmt = $db->prepare("INSERT INTO test (a, b) values (?, ?)"); +$stmt->bindValue(1, "error"); +$stmt->bindValue(2, "test insert"); +$stmt->execute(); +} catch (Exception $e) { + /* We catch the exception because the execute will give error and we must test the PDO::PGSQL_TRANSACTION_ERROR */ + echo "Test PDO::PGSQL_TRANSACTION_INERROR\n"; + var_dump($db->inTransaction()); + $db->rollBack(); +} + +echo "Test PDO::PGSQL_TRANSACTION_IDLE\n"; +var_dump($db->inTransaction()); + +} catch (Exception $e) { + /* catch exceptions so that we can show the relative error */ + echo "Exception! at line ", $e->getLine(), "\n"; + var_dump($e->getMessage()); +} + +?> +--EXPECT-- +Test PDO::PGSQL_TRANSACTION_INTRANS +int(2) +Test PDO::PGSQL_TRANSACTION_IDLE +int(0) +Test PDO::PGSQL_TRANSACTION_INERROR +int(3) +Test PDO::PGSQL_TRANSACTION_IDLE +int(0) |