1--TEST-- 2PDO_Firebird: transaction isolation level (Testing for behavior) 3--EXTENSIONS-- 4pdo_firebird 5--SKIPIF-- 6<?php require('skipif.inc'); ?> 7--XLEAK-- 8A bug in firebird causes a memory leak when calling `isc_attach_database()`. 9See https://github.com/FirebirdSQL/firebird/issues/7849 10--FILE-- 11<?php 12 13require("testdb.inc"); 14$dbh = getDbConnection(); 15unset($dbh); 16 17$table = 'txn_isolation_level_behavior'; 18 19$dbh_other = new PDO( 20 PDO_FIREBIRD_TEST_DSN, 21 PDO_FIREBIRD_TEST_USER, 22 PDO_FIREBIRD_TEST_PASS, 23); 24$dbh_other->query("CREATE TABLE {$table} (val INT)"); 25 26 27echo "========== default(REPEATABLE READ) ==========\n"; 28$dbh = new PDO( 29 PDO_FIREBIRD_TEST_DSN, 30 PDO_FIREBIRD_TEST_USER, 31 PDO_FIREBIRD_TEST_PASS, 32); 33echo "begin transaction\n"; 34$dbh->beginTransaction(); 35 36echo "insert by other transaction\n"; 37$dbh_other->exec("INSERT INTO {$table} VALUES (20)"); 38echo "Read\n"; 39$r = $dbh->query("SELECT * FROM {$table}"); 40var_dump($r->fetchAll()); 41 42echo "Close transaction and reset table\n"; 43$dbh->commit(); 44$dbh_other->exec("DELETE FROM {$table}"); 45unset($dbh); 46echo "\n"; 47 48 49echo "========== READ COMMITTED ==========\n"; 50$dbh = new PDO( 51 PDO_FIREBIRD_TEST_DSN, 52 PDO_FIREBIRD_TEST_USER, 53 PDO_FIREBIRD_TEST_PASS, 54 [Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL => Pdo\Firebird::READ_COMMITTED] 55); 56echo "begin transaction\n"; 57$dbh->beginTransaction(); 58 59echo "insert by other transaction\n"; 60$dbh_other->exec("INSERT INTO {$table} VALUES (20)"); 61echo "Read\n"; 62$r = $dbh->query("SELECT * FROM {$table}"); 63var_dump($r->fetchAll()); 64 65echo "Close transaction and reset table\n"; 66$dbh->commit(); 67$dbh_other->exec("DELETE FROM {$table}"); 68unset($dbh); 69echo "\n"; 70 71 72echo "========== REPEATABLE READ ==========\n"; 73$dbh = new PDO( 74 PDO_FIREBIRD_TEST_DSN, 75 PDO_FIREBIRD_TEST_USER, 76 PDO_FIREBIRD_TEST_PASS, 77 [Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL => Pdo\Firebird::REPEATABLE_READ] 78); 79echo "begin transaction\n"; 80$dbh->beginTransaction(); 81 82echo "insert by other transaction\n"; 83$dbh_other->exec("INSERT INTO {$table} VALUES (20)"); 84echo "Read\n"; 85$r = $dbh->query("SELECT * FROM {$table}"); 86var_dump($r->fetchAll()); 87 88echo "Close transaction and reset table\n"; 89$dbh->commit(); 90$dbh_other->exec("DELETE FROM {$table}"); 91unset($dbh); 92echo "\n"; 93 94 95/* 96 * SERIALIZABLE imposes a strong lock, so the lock will not be released and 97 * the test will never end. There is currently no way to confirm. 98 * If we can set the lock timeout, it might be possible to test it, so I'll leave it as is. 99 */ 100 101/* 102echo "========== SERIALIZABLE ==========\n"; 103$dbh = new PDO( 104 PDO_FIREBIRD_TEST_DSN, 105 PDO_FIREBIRD_TEST_USER, 106 PDO_FIREBIRD_TEST_PASS, 107 [Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL => Pdo\Firebird::SERIALIZABLE] 108); 109echo "begin transaction\n"; 110$dbh->beginTransaction(); 111 112echo "insert by other transaction\n"; 113$dbh_other->exec("INSERT INTO {$table} VALUES (20)"); 114echo "Read\n"; 115$r = $dbh->query("SELECT * FROM {$table}"); 116var_dump($r->fetchAll()); 117 118echo "Close transaction and reset table\n"; 119$dbh->commit(); 120$dbh_other->exec("DELETE FROM {$table}"); 121echo "\n"; 122*/ 123 124unset($dbh); 125 126echo "done!"; 127?> 128--CLEAN-- 129<?php 130require 'testdb.inc'; 131$dbh = getDbConnection(); 132@$dbh->exec('DROP TABLE txn_isolation_level_behavior'); 133unset($dbh); 134?> 135--EXPECT-- 136========== default(REPEATABLE READ) ========== 137begin transaction 138insert by other transaction 139Read 140array(0) { 141} 142Close transaction and reset table 143 144========== READ COMMITTED ========== 145begin transaction 146insert by other transaction 147Read 148array(1) { 149 [0]=> 150 array(2) { 151 ["VAL"]=> 152 int(20) 153 [0]=> 154 int(20) 155 } 156} 157Close transaction and reset table 158 159========== REPEATABLE READ ========== 160begin transaction 161insert by other transaction 162Read 163array(0) { 164} 165Close transaction and reset table 166 167done! 168