forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_access_mode.phpt
186 lines (159 loc) · 4.26 KB
/
transaction_access_mode.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
--TEST--
PDO_Firebird: transaction access mode
--EXTENSIONS--
pdo_firebird
--SKIPIF--
<?php require('skipif.inc'); ?>
--XLEAK--
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
See https://github.com/FirebirdSQL/firebird/issues/7849
--FILE--
<?php
require("testdb.inc");
$dbh = getDbConnection();
unset($dbh);
$table = 'transaction_access_mode';
$values = [
['val' => true, 'label' => 'writable'],
['val' => false, 'label' => 'readonly'],
];
echo "========== Set attr in construct ==========\n";
foreach ($values as $value) {
$dbh = new PDO(
PDO_FIREBIRD_TEST_DSN,
PDO_FIREBIRD_TEST_USER,
PDO_FIREBIRD_TEST_PASS,
[
PDO::FB_WRITABLE_TRANSACTION => $value['val'],
],
);
if ($dbh->getAttribute(PDO::FB_WRITABLE_TRANSACTION) === $value['val']) {
echo "OK: {$value['label']}\n";
} else {
echo "NG: {$value['label']}\n";
}
unset($dbh);
}
echo "\n";
echo "========== Set attr in setAttribute and behavior check ==========\n";
$dbh = new PDO(
PDO_FIREBIRD_TEST_DSN,
PDO_FIREBIRD_TEST_USER,
PDO_FIREBIRD_TEST_PASS,
);
$dbh->query("CREATE TABLE {$table} (val INT)");
echo "writable\n";
var_dump($dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, true));
if ($dbh->getAttribute(PDO::FB_WRITABLE_TRANSACTION) === true) {
echo "OK: writable\n";
} else {
echo "NG: writable\n";
}
$dbh->query("INSERT INTO {$table} VALUES (12)");
$r = $dbh->query("SELECT * FROM {$table}");
var_dump($r->fetchAll());
echo "\n";
echo "readonly\n";
var_dump($dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, false));
if ($dbh->getAttribute(PDO::FB_WRITABLE_TRANSACTION) === false) {
echo "OK: readonly\n";
} else {
echo "NG: readonly\n";
}
try {
$dbh->query("INSERT INTO {$table} VALUES (19)");
} catch (PDOException $e) {
echo $e->getMessage()."\n";
}
$r = $dbh->query("SELECT * FROM {$table}");
var_dump($r->fetchAll());
echo "\n";
echo "========== Set attr in setAttribute while transaction ==========\n";
$dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, true);
$dbh->beginTransaction();
echo "writable to writable\n";
try {
$dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, true);
} catch (PDOException $e) {
echo $e->getMessage()."\n";
}
var_dump($dbh->getAttribute(PDO::FB_WRITABLE_TRANSACTION));
echo "\n";
echo "writable to readonly\n";
try {
$dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, false);
} catch (PDOException $e) {
echo $e->getMessage()."\n";
}
var_dump($dbh->getAttribute(PDO::FB_WRITABLE_TRANSACTION));
echo "\n";
$dbh->commit();
$dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, false);
$dbh->beginTransaction();
echo "readonly to writable\n";
try {
$dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, true);
} catch (PDOException $e) {
echo $e->getMessage()."\n";
}
var_dump($dbh->getAttribute(PDO::FB_WRITABLE_TRANSACTION));
echo "\n";
echo "readonly to readonly\n";
try {
$dbh->setAttribute(PDO::FB_WRITABLE_TRANSACTION, false);
} catch (PDOException $e) {
echo $e->getMessage()."\n";
}
var_dump($dbh->getAttribute(PDO::FB_WRITABLE_TRANSACTION));
unset($dbh);
?>
--CLEAN--
<?php
require 'testdb.inc';
$dbh = getDbConnection();
@$dbh->exec('DROP TABLE transaction_access_mode');
unset($dbh);
?>
--EXPECT--
========== Set attr in construct ==========
OK: writable
OK: readonly
========== Set attr in setAttribute and behavior check ==========
writable
bool(true)
OK: writable
array(1) {
[0]=>
array(2) {
["VAL"]=>
int(12)
[0]=>
int(12)
}
}
readonly
bool(true)
OK: readonly
SQLSTATE[42000]: Syntax error or access violation: -817 attempted update during read-only transaction
array(1) {
[0]=>
array(2) {
["VAL"]=>
int(12)
[0]=>
int(12)
}
}
========== Set attr in setAttribute while transaction ==========
writable to writable
SQLSTATE[HY000]: General error: Cannot change access mode while a transaction is already open
bool(true)
writable to readonly
SQLSTATE[HY000]: General error: Cannot change access mode while a transaction is already open
bool(true)
readonly to writable
SQLSTATE[HY000]: General error: Cannot change access mode while a transaction is already open
bool(false)
readonly to readonly
SQLSTATE[HY000]: General error: Cannot change access mode while a transaction is already open
bool(false)