Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-12767: Fixed to be able to change autocommit mode using setAtt…
…ribute Signed-off-by: Gina Peter Banyard <girgias@php.net>
- Loading branch information
1 parent
abf4c11
commit 933dccb
Showing
4 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--TEST-- | ||
PDO ODBC auto commit mode | ||
--EXTENSIONS-- | ||
pdo_odbc | ||
--SKIPIF-- | ||
<?php | ||
require 'ext/pdo/tests/pdo_test.inc'; | ||
PDOTest::skip(); | ||
?> | ||
--XLEAK-- | ||
A bug in msodbcsql causes a memory leak when reconnecting after closing. See GH-12306 | ||
--FILE-- | ||
<?php | ||
require 'ext/pdo/tests/pdo_test.inc'; | ||
|
||
$table = 'autocommit_pdo_odbc'; | ||
|
||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); | ||
$db->exec("CREATE TABLE {$table} (id INT, name VARCHAR(255))"); | ||
unset($db); | ||
|
||
$db = new PDO(getenv('PDOTEST_DSN'), getenv('PDOTEST_USER'), getenv('PDOTEST_PASS'), [ | ||
PDO::ATTR_AUTOCOMMIT => 0, | ||
]); | ||
|
||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 1); | ||
$db->query("INSERT INTO {$table} (id, name) VALUES (1, 'test')"); | ||
unset($db); | ||
|
||
$db = new PDO(getenv('PDOTEST_DSN'), getenv('PDOTEST_USER'), getenv('PDOTEST_PASS')); | ||
|
||
$r = $db->query("SELECT * FROM {$table}"); | ||
var_dump($r->fetchAll(PDO::FETCH_ASSOC)); | ||
|
||
echo "done!"; | ||
?> | ||
--CLEAN-- | ||
<?php | ||
require 'ext/pdo/tests/pdo_test.inc'; | ||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); | ||
$db->exec("DROP TABLE IF EXISTS autocommit_pdo_odbc"); | ||
?> | ||
--EXPECT-- | ||
array(1) { | ||
[0]=> | ||
array(2) { | ||
["id"]=> | ||
string(1) "1" | ||
["name"]=> | ||
string(4) "test" | ||
} | ||
} | ||
done! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
--TEST-- | ||
PDO ODBC auto commit mode | ||
--EXTENSIONS-- | ||
pdo_odbc | ||
--SKIPIF-- | ||
<?php | ||
require 'ext/pdo/tests/pdo_test.inc'; | ||
PDOTest::skip(); | ||
?> | ||
--FILE-- | ||
<?php | ||
require 'ext/pdo/tests/pdo_test.inc'; | ||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); | ||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
echo "========== not in transaction ==========\n"; | ||
|
||
echo "auto commit ON from ON\n"; | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true); | ||
echo "Success\n\n"; | ||
|
||
echo "auto commit OFF from ON\n"; | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false); | ||
echo "Success\n\n"; | ||
|
||
echo "auto commit OFF from OFF\n"; | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false); | ||
echo "Success\n\n"; | ||
|
||
echo "auto commit ON from OFF\n"; | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true); | ||
echo "Success\n\n"; | ||
|
||
echo "========== in transaction ==========\n"; | ||
|
||
echo "begin transaction\n"; | ||
$db->beginTransaction(); | ||
echo "\n"; | ||
|
||
echo "auto commit ON from ON, expect error\n"; | ||
try { | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true); | ||
} catch (PDOException $e) { | ||
echo $e->getMessage()."\n\n"; | ||
} | ||
|
||
echo "auto commit OFF from ON, expect error\n"; | ||
try { | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false); | ||
} catch (PDOException $e) { | ||
echo $e->getMessage()."\n\n"; | ||
} | ||
|
||
echo "end transaction\n"; | ||
$db->rollback(); | ||
|
||
echo "auto commit OFF\n"; | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false); | ||
|
||
echo "begin transaction\n"; | ||
$db->beginTransaction(); | ||
echo "\n"; | ||
|
||
echo "auto commit ON from OFF, expect error\n"; | ||
try { | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, true); | ||
} catch (PDOException $e) { | ||
echo $e->getMessage()."\n\n"; | ||
} | ||
|
||
echo "auto commit OFF from OFF, expect error\n"; | ||
try { | ||
$db->setAttribute(PDO::ATTR_AUTOCOMMIT, false); | ||
} catch (PDOException $e) { | ||
echo $e->getMessage()."\n\n"; | ||
} | ||
|
||
echo "end transaction\n"; | ||
$db->rollback(); | ||
echo "\n"; | ||
|
||
echo "done!"; | ||
?> | ||
--EXPECT-- | ||
========== not in transaction ========== | ||
auto commit ON from ON | ||
Success | ||
|
||
auto commit OFF from ON | ||
Success | ||
|
||
auto commit OFF from OFF | ||
Success | ||
|
||
auto commit ON from OFF | ||
Success | ||
|
||
========== in transaction ========== | ||
begin transaction | ||
|
||
auto commit ON from ON, expect error | ||
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open | ||
|
||
auto commit OFF from ON, expect error | ||
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 | ||
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open | ||
|
||
auto commit OFF from OFF, expect error | ||
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open | ||
|
||
end transaction | ||
|
||
done! |