1--TEST--
2PDO ODBC auto commit mode
3--EXTENSIONS--
4pdo_odbc
5--SKIPIF--
6<?php
7require 'ext/pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require 'ext/pdo/tests/pdo_test.inc';
13$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15
16echo "========== not in transaction ==========\n";
17
18echo "auto commit ON from ON\n";
19$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
20var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
21echo "Success\n\n";
22
23echo "auto commit OFF from ON\n";
24$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
25var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
26echo "Success\n\n";
27
28echo "auto commit OFF from OFF\n";
29$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
30var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
31echo "Success\n\n";
32
33echo "auto commit ON from OFF\n";
34$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
35var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
36echo "Success\n\n";
37
38echo "========== in transaction ==========\n";
39
40echo "begin transaction\n";
41$db->beginTransaction();
42echo "\n";
43
44echo "auto commit ON from ON, expect error\n";
45try {
46    $db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
47} catch (PDOException $e) {
48    var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
49    echo $e->getMessage()."\n\n";
50}
51
52echo "auto commit OFF from ON, expect error\n";
53try {
54    $db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
55} catch (PDOException $e) {
56    var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
57    echo $e->getMessage()."\n\n";
58}
59
60echo "end transaction\n";
61$db->rollback();
62
63echo "auto commit OFF\n";
64$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
65
66echo "begin transaction\n";
67$db->beginTransaction();
68echo "\n";
69
70echo "auto commit ON from OFF, expect error\n";
71try {
72    $db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
73} catch (PDOException $e) {
74    var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
75    echo $e->getMessage()."\n\n";
76}
77
78echo "auto commit OFF from OFF, expect error\n";
79try {
80    $db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
81} catch (PDOException $e) {
82    var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
83    echo $e->getMessage()."\n\n";
84}
85
86echo "end transaction\n";
87$db->rollback();
88echo "\n";
89
90echo "done!";
91?>
92--EXPECT--
93========== not in transaction ==========
94auto commit ON from ON
95bool(true)
96Success
97
98auto commit OFF from ON
99bool(false)
100Success
101
102auto commit OFF from OFF
103bool(false)
104Success
105
106auto commit ON from OFF
107bool(true)
108Success
109
110========== in transaction ==========
111begin transaction
112
113auto commit ON from ON, expect error
114bool(true)
115SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
116
117auto commit OFF from ON, expect error
118bool(true)
119SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
120
121end transaction
122auto commit OFF
123begin transaction
124
125auto commit ON from OFF, expect error
126bool(false)
127SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
128
129auto commit OFF from OFF, expect error
130bool(false)
131SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
132
133end transaction
134
135done!
136