1--TEST--
2PDO PgSQL isInTransaction
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
16$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
17$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
18
19$db->exec('CREATE TABLE test (a integer not null primary key, b text)');
20
21$db->beginTransaction();
22try {
23echo "Test PDO::PGSQL_TRANSACTION_INTRANS\n";
24var_dump($db->inTransaction());
25
26$stmt = $db->prepare("INSERT INTO test (a, b) values (?, ?)");
27$stmt->bindValue(1, 1);
28$stmt->bindValue(2, "test insert");
29$stmt->execute();
30
31$db->commit();
32
33echo "Test PDO::PGSQL_TRANSACTION_IDLE\n";
34var_dump($db->inTransaction());
35
36$db->beginTransaction();
37
38try {
39$stmt = $db->prepare("INSERT INTO test (a, b) values (?, ?)");
40$stmt->bindValue(1, "error");
41$stmt->bindValue(2, "test insert");
42$stmt->execute();
43} catch (Exception $e) {
44    /* We catch the exception because the execute will give error and we must test the PDO::PGSQL_TRANSACTION_ERROR */
45    echo "Test PDO::PGSQL_TRANSACTION_INERROR\n";
46    var_dump($db->inTransaction());
47    $db->rollBack();
48}
49
50echo "Test PDO::PGSQL_TRANSACTION_IDLE\n";
51var_dump($db->inTransaction());
52
53} catch (Exception $e) {
54    /* catch exceptions so that we can show the relative error */
55    echo "Exception! at line ", $e->getLine(), "\n";
56    var_dump($e->getMessage());
57}
58
59?>
60--EXPECT--
61Test PDO::PGSQL_TRANSACTION_INTRANS
62bool(true)
63Test PDO::PGSQL_TRANSACTION_IDLE
64bool(false)
65Test PDO::PGSQL_TRANSACTION_INERROR
66bool(true)
67Test PDO::PGSQL_TRANSACTION_IDLE
68bool(false)
69