Skip to content

Commit 2553ffe

Browse files
SakiTakamachiGirgias
authored andcommitted
add PDO::ATTR_AUTOCOMMIT to getAttribute
Signed-off-by: Gina Peter Banyard <[email protected]>
1 parent 933dccb commit 2553ffe

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/pdo_odbc/odbc_driver.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
410410
case PDO_ODBC_ATTR_ASSUME_UTF8:
411411
ZVAL_BOOL(val, H->assume_utf8 ? 1 : 0);
412412
return 1;
413-
413+
case PDO_ATTR_AUTOCOMMIT:
414+
ZVAL_BOOL(val, dbh->auto_commit);
415+
return 1;
414416
}
415417
return 0;
416418
}

ext/pdo_odbc/tests/autocommit_change_mode.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ echo "========== not in transaction ==========\n";
1717

1818
echo "auto commit ON from ON\n";
1919
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
20+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
2021
echo "Success\n\n";
2122

2223
echo "auto commit OFF from ON\n";
2324
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
25+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
2426
echo "Success\n\n";
2527

2628
echo "auto commit OFF from OFF\n";
2729
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
30+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
2831
echo "Success\n\n";
2932

3033
echo "auto commit ON from OFF\n";
3134
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
35+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
3236
echo "Success\n\n";
3337

3438
echo "========== in transaction ==========\n";
@@ -41,13 +45,15 @@ echo "auto commit ON from ON, expect error\n";
4145
try {
4246
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
4347
} catch (PDOException $e) {
48+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
4449
echo $e->getMessage()."\n\n";
4550
}
4651

4752
echo "auto commit OFF from ON, expect error\n";
4853
try {
4954
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
5055
} catch (PDOException $e) {
56+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
5157
echo $e->getMessage()."\n\n";
5258
}
5359

@@ -65,13 +71,15 @@ echo "auto commit ON from OFF, expect error\n";
6571
try {
6672
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
6773
} catch (PDOException $e) {
74+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
6875
echo $e->getMessage()."\n\n";
6976
}
7077

7178
echo "auto commit OFF from OFF, expect error\n";
7279
try {
7380
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
7481
} catch (PDOException $e) {
82+
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
7583
echo $e->getMessage()."\n\n";
7684
}
7785

@@ -84,34 +92,42 @@ echo "done!";
8492
--EXPECT--
8593
========== not in transaction ==========
8694
auto commit ON from ON
95+
bool(true)
8796
Success
8897

8998
auto commit OFF from ON
99+
bool(false)
90100
Success
91101

92102
auto commit OFF from OFF
103+
bool(false)
93104
Success
94105

95106
auto commit ON from OFF
107+
bool(true)
96108
Success
97109

98110
========== in transaction ==========
99111
begin transaction
100112

101113
auto commit ON from ON, expect error
114+
bool(true)
102115
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
103116

104117
auto commit OFF from ON, expect error
118+
bool(true)
105119
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
106120

107121
end transaction
108122
auto commit OFF
109123
begin transaction
110124

111125
auto commit ON from OFF, expect error
126+
bool(false)
112127
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
113128

114129
auto commit OFF from OFF, expect error
130+
bool(false)
115131
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
116132

117133
end transaction

0 commit comments

Comments
 (0)