Skip to content

Commit

Permalink
add PDO::ATTR_AUTOCOMMIT to getAttribute
Browse files Browse the repository at this point in the history
Signed-off-by: Gina Peter Banyard <girgias@php.net>
  • Loading branch information
SakiTakamachi authored and Girgias committed Dec 18, 2023
1 parent 933dccb commit 2553ffe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext/pdo_odbc/odbc_driver.c
Expand Up @@ -410,7 +410,9 @@ static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
case PDO_ODBC_ATTR_ASSUME_UTF8:
ZVAL_BOOL(val, H->assume_utf8 ? 1 : 0);
return 1;

case PDO_ATTR_AUTOCOMMIT:
ZVAL_BOOL(val, dbh->auto_commit);
return 1;
}
return 0;
}
Expand Down
16 changes: 16 additions & 0 deletions ext/pdo_odbc/tests/autocommit_change_mode.phpt
Expand Up @@ -17,18 +17,22 @@ echo "========== not in transaction ==========\n";

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

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

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

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

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

echo "auto commit OFF from ON, expect error\n";
try {
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
} catch (PDOException $e) {
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
echo $e->getMessage()."\n\n";
}

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

echo "auto commit OFF from OFF, expect error\n";
try {
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
} catch (PDOException $e) {
var_dump($db->getAttribute(PDO::ATTR_AUTOCOMMIT));
echo $e->getMessage()."\n\n";
}

Expand All @@ -84,34 +92,42 @@ echo "done!";
--EXPECT--
========== not in transaction ==========
auto commit ON from ON
bool(true)
Success

auto commit OFF from ON
bool(false)
Success

auto commit OFF from OFF
bool(false)
Success

auto commit ON from OFF
bool(true)
Success

========== in transaction ==========
begin transaction

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

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

end transaction
auto commit OFF
begin transaction

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

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

end transaction
Expand Down

0 comments on commit 2553ffe

Please sign in to comment.