2017-05-03 23:09:02 +03:00
|
|
|
--TEST--
|
|
|
|
Test Transactions.
|
|
|
|
--SKIPIF--
|
2017-11-02 03:09:58 +03:00
|
|
|
<?php require('skipif_mid-refactor.inc'); ?>
|
2017-05-03 23:09:02 +03:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2017-11-02 03:09:58 +03:00
|
|
|
require_once("MsCommon_mid-refactor.inc");
|
|
|
|
require_once("MsData_PDO_AllTypes.inc");
|
|
|
|
|
2017-05-03 23:09:02 +03:00
|
|
|
// commit
|
2017-11-02 03:09:58 +03:00
|
|
|
function test1($conn, $tbname)
|
2017-05-03 23:09:02 +03:00
|
|
|
{
|
|
|
|
$conn->beginTransaction();
|
2017-11-02 03:09:58 +03:00
|
|
|
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
|
2017-05-03 23:09:02 +03:00
|
|
|
$conn->commit();
|
2017-11-02 03:09:58 +03:00
|
|
|
echo "Test 1 Passed\n";
|
2017-05-03 23:09:02 +03:00
|
|
|
}
|
2017-11-02 03:09:58 +03:00
|
|
|
|
2017-05-03 23:09:02 +03:00
|
|
|
// rollback
|
2017-11-02 03:09:58 +03:00
|
|
|
function test2($conn, $tbname)
|
2017-05-03 23:09:02 +03:00
|
|
|
{
|
|
|
|
$conn->beginTransaction();
|
2017-11-02 03:09:58 +03:00
|
|
|
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
|
2017-05-03 23:09:02 +03:00
|
|
|
$conn->rollBack();
|
|
|
|
echo "Test 2 Passed\n";
|
|
|
|
}
|
2017-11-02 03:09:58 +03:00
|
|
|
|
2017-05-03 23:09:02 +03:00
|
|
|
// commit
|
2017-11-02 03:09:58 +03:00
|
|
|
function test3($conn, $tbname)
|
2017-05-03 23:09:02 +03:00
|
|
|
{
|
|
|
|
$conn->beginTransaction();
|
2017-11-02 03:09:58 +03:00
|
|
|
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
|
2017-05-03 23:09:02 +03:00
|
|
|
$conn->commit();
|
|
|
|
echo "Test 3 Passed\n";
|
|
|
|
}
|
2017-11-02 03:09:58 +03:00
|
|
|
|
2017-05-03 23:09:02 +03:00
|
|
|
// Rollback twice. Verify that error is thrown
|
2017-11-02 03:09:58 +03:00
|
|
|
function test4($conn, $tbname)
|
2017-05-03 23:09:02 +03:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$conn->beginTransaction();
|
2017-11-02 03:09:58 +03:00
|
|
|
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
|
2017-05-03 23:09:02 +03:00
|
|
|
$conn->rollBack();
|
|
|
|
$conn->rollBack();
|
2017-11-02 03:09:58 +03:00
|
|
|
} catch (PDOException $e) {
|
2017-05-03 23:09:02 +03:00
|
|
|
echo "Test4: ". $e->getMessage() . "\n";
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 03:09:58 +03:00
|
|
|
|
2017-05-03 23:09:02 +03:00
|
|
|
// Commit twice Verify that error is thrown
|
2017-11-02 03:09:58 +03:00
|
|
|
function test5($conn, $tbname)
|
2017-05-03 23:09:02 +03:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$conn->beginTransaction();
|
2017-11-02 03:09:58 +03:00
|
|
|
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
|
2017-05-03 23:09:02 +03:00
|
|
|
$conn->commit();
|
|
|
|
$conn->commit();
|
2017-11-02 03:09:58 +03:00
|
|
|
} catch (PDOException $e) {
|
2017-05-03 23:09:02 +03:00
|
|
|
echo "Test5: ". $e->getMessage() . "\n";
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 03:09:58 +03:00
|
|
|
|
2017-05-03 23:09:02 +03:00
|
|
|
// begin transaction twice. Verify that error is thrown
|
|
|
|
function test6($conn)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$conn->beginTransaction();
|
|
|
|
$conn->beginTransaction();
|
2017-11-02 03:09:58 +03:00
|
|
|
} catch (PDOException $e) {
|
2017-05-03 23:09:02 +03:00
|
|
|
echo "Test6: ". $e->getMessage() . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 03:09:58 +03:00
|
|
|
try {
|
|
|
|
$db = connect();
|
|
|
|
$tbname = "PDO_MainTypes";
|
|
|
|
createTableMainTypes($db, $tbname);
|
|
|
|
test1($db, $tbname);
|
|
|
|
test2($db, $tbname);
|
|
|
|
test3($db, $tbname);
|
|
|
|
test4($db, $tbname);
|
|
|
|
test5($db, $tbname);
|
|
|
|
test6($db);
|
2017-05-03 23:09:02 +03:00
|
|
|
|
2017-11-02 03:09:58 +03:00
|
|
|
dropTable($db, $tbname);
|
|
|
|
unset($conn);
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
var_dump($e);
|
2017-05-03 23:09:02 +03:00
|
|
|
exit;
|
|
|
|
}
|
2017-11-02 03:09:58 +03:00
|
|
|
?>
|
2017-05-03 23:09:02 +03:00
|
|
|
--EXPECT--
|
2017-11-02 03:09:58 +03:00
|
|
|
Test 1 Passed
|
2017-05-03 23:09:02 +03:00
|
|
|
Test 2 Passed
|
|
|
|
Test 3 Passed
|
|
|
|
Test4: There is no active transaction
|
|
|
|
Test5: There is no active transaction
|
2017-11-02 03:09:58 +03:00
|
|
|
Test6: There is already an active transaction
|