Annotation of embedaddon/php/ext/pdo_oci/tests/pdo_oci_attr_autocommit_2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: PDO_OCI: Attribute: beginTransaction and native transactions
3: --SKIPIF--
4: <?php
5: if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
6: require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
7: PDOTest::skip();
8: ?>
9: --FILE--
10: <?php
11:
12: require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
13: $dbh = PDOTest::factory();
14:
15: $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
16: $dbh->exec("drop table pdo_ac_tab");
17: $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
18:
19: $dbh->exec("create table pdo_ac_tab (col1 varchar2(25))");
20:
21: echo "Test 1 Check beginTransaction insertion\n";
22:
23: $dbh->beginTransaction();
24: try {
25: $dbh->exec("insert into pdo_ac_tab (col1) values ('data 1')");
26: $dbh->exec("insert into pdo_ac_tab (col1) values ('data 2')");
27: $dbh->commit();
28: }
29: catch (PDOException $e) {
30: echo "Caught unexpected exception at line " . __LINE__ . "\n";
31: echo $e->getMessage() . "\n";
32: $dbh->rollback();
33: }
34:
35: echo "Test 2 Cause an exception and test beginTransaction rollback\n";
36:
37: $dbh->beginTransaction();
38: try {
39: $dbh->exec("insert into pdo_ac_tab (col1) values ('not committed #1')");
40: $dbh->exec("insert into pdo_ac_tab (col1) values ('data that is too long to fit and will barf')");
41: $dbh->commit();
42: }
43: catch (PDOException $e) {
44: echo "Caught expected exception at line " . __LINE__ . "\n";
45: echo $e->getMessage() . "\n";
46: $dbh->rollback();
47: }
48:
49: echo "Test 3 Setting ATTR_AUTOCOMMIT to true will commit and end the transaction\n";
50:
51: $dbh->exec("insert into pdo_ac_tab (col1) values ('data 3')");
52: $dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
53: print "PDO::ATTR_AUTOCOMMIT: ";
54: var_dump($dbh->getAttribute(PDO::ATTR_AUTOCOMMIT));
55: try {
56: $dbh->rollback();
57: }
58: catch (PDOException $e) {
59: echo "Caught expected exception at line " . __LINE__ . "\n";
60: echo $e->getMessage() . "\n";
61: }
62:
63: echo "Test 4 Setting ATTR_AUTOCOMMIT to false will commit and end the transaction\n";
64:
65: $dbh->beginTransaction();
66: $dbh->exec("insert into pdo_ac_tab (col1) values ('data 4')");
67: $dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
68: print "PDO::ATTR_AUTOCOMMIT: ";
69: var_dump($dbh->getAttribute(PDO::ATTR_AUTOCOMMIT));
70: try {
71: $dbh->rollback();
72: }
73: catch (PDOException $e) {
74: echo "Caught expected exception at line " . __LINE__ . "\n";
75: echo $e->getMessage() . "\n";
76: }
77:
78: echo "Test 5 Handle transactions ourselves\n";
79:
80: print "PDO::ATTR_AUTOCOMMIT: ";
81: var_dump($dbh->getAttribute(PDO::ATTR_AUTOCOMMIT));
82:
83: $dbh->exec("insert into pdo_ac_tab (col1) values ('not committed #2')");
84: $dbh->exec("rollback");
85: $dbh->exec("insert into pdo_ac_tab (col1) values ('data 5')");
86: $dbh->exec("insert into pdo_ac_tab (col1) values ('data 6')");
87:
88: $dbh->exec("commit");
89:
90: // Open new connection to really verify what was inserted
91:
92: $dbh2 = PDOTest::factory();
93:
94: echo "Query Results are:\n";
95: $s = $dbh2->prepare("select col1 from pdo_ac_tab");
96: $s->execute();
97: while ($r = $s->fetch()) {
98: echo $r[0] . "\n";
99: }
100:
101: echo "Done\n";
102:
103: ?>
104: --EXPECTF--
105: Test 1 Check beginTransaction insertion
106: Test 2 Cause an exception and test beginTransaction rollback
107: Caught expected exception at line 35
108: SQLSTATE[HY000]: General error: 12899 OCIStmtExecute: ORA-12899: %s
109: %s
110: Test 3 Setting ATTR_AUTOCOMMIT to true will commit and end the transaction
111: PDO::ATTR_AUTOCOMMIT: bool(true)
112: Caught expected exception at line %d
113: There is no active transaction
114: Test 4 Setting ATTR_AUTOCOMMIT to false will commit and end the transaction
115: PDO::ATTR_AUTOCOMMIT: bool(false)
116: Caught expected exception at line %d
117: There is no active transaction
118: Test 5 Handle transactions ourselves
119: PDO::ATTR_AUTOCOMMIT: bool(false)
120: Query Results are:
121: data 1
122: data 2
123: data 3
124: data 4
125: data 5
126: data 6
127: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>