Skip to content

Commit 7a44bbd

Browse files
committed
Add more transaction tests
1 parent 39dbe8c commit 7a44bbd

File tree

9 files changed

+249
-0
lines changed

9 files changed

+249
-0
lines changed

tests/functions.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,20 @@ function skip_if_fb_gt($v) {
130130
function skip_if_fb_gte($v) {
131131
if(($cv = get_fb_version()) >= $v)die("skip: Firebird version $cv >= $v");
132132
}
133+
134+
function ibase_query_bulk(array $queries, $tr = null) {
135+
foreach($queries as $q){
136+
if(is_array($q)){
137+
[$sql, $args] = $q;
138+
} else {
139+
$sql = $q;
140+
$args = [];
141+
}
142+
143+
if($tr) {
144+
ibase_query($tr, $sql, ...$args);
145+
} else {
146+
ibase_query($sql, ...$args);
147+
}
148+
}
149+
}

tests/ibase_trans_004.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
ibase_trans(): handles
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
$t = ibase_trans();
12+
var_dump(ibase_query($t, "COMMIT"));
13+
var_dump($t);
14+
ibase_query($t, "SELECT * FROM TEST1");
15+
})();
16+
17+
?>
18+
--EXPECTF--
19+
bool(true)
20+
resource(%d) of type (Firebird/InterBase transaction)
21+
22+
Warning: ibase_query(): invalid transaction handle (expecting explicit transaction start)%s

tests/ibase_trans_005.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
ibase_trans(): handles
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
$t = ibase_query("SET TRANSACTION");
12+
var_dump($t);
13+
})();
14+
15+
?>
16+
--EXPECTF--
17+
resource(%d) of type (Firebird/InterBase transaction)

tests/ibase_trans_006.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
ibase_trans(): handles
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
$t = ibase_query("SET TRANSACTION");
12+
ibase_rollback($t);
13+
var_dump($t);
14+
ibase_query($t, "SELECT * FROM TEST1");
15+
})();
16+
17+
?>
18+
--EXPECTF--
19+
resource(%d) of type (Firebird/InterBase transaction)
20+
21+
Warning: ibase_query(): invalid transaction handle (expecting explicit transaction start)%s

tests/ibase_trans_007.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
ibase_trans(): handles
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
$t = ibase_query("SET TRANSACTION");
12+
var_dump(ibase_query($t, "DELETE FROM TEST1"));
13+
print "|---- TEST1 default transaction\n";
14+
dump_table_rows("TEST1");
15+
print "|--------\n";
16+
print "|---- TEST1 t1 transaction\n";
17+
dump_table_rows("TEST1", $t);
18+
print "|--------\n";
19+
ibase_rollback($t);
20+
ibase_rollback();
21+
22+
print "|---- TEST1 default transaction\n";
23+
dump_table_rows("TEST1");
24+
print "|--------\n";
25+
})();
26+
27+
?>
28+
--EXPECT--
29+
int(1)
30+
|---- TEST1 default transaction
31+
array(2) {
32+
["I"]=>
33+
int(1)
34+
["C"]=>
35+
string(32) "test table not created with isql"
36+
}
37+
|--------
38+
|---- TEST1 t1 transaction
39+
|--------
40+
|---- TEST1 default transaction
41+
array(2) {
42+
["I"]=>
43+
int(1)
44+
["C"]=>
45+
string(32) "test table not created with isql"
46+
}
47+
|--------

tests/ibase_trans_008.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
ibase_trans(): transaction control with SQL
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
$queries = [
12+
"SET TRANSACTION",
13+
"DELETE FROM TEST1",
14+
"COMMIT RETAIN",
15+
["INSERT INTO TEST1 (I, C) VALUES (?, ?)", [1, "test1(1)"]],
16+
"SAVEPOINT sp_name",
17+
["INSERT INTO TEST1 (I, C) VALUES (?, ?)", [2, "test1(2)"]],
18+
"ROLLBACK TO SAVEPOINT sp_name",
19+
"COMMIT",
20+
];
21+
ibase_query_bulk($queries);
22+
dump_table_rows("TEST1");
23+
})();
24+
25+
?>
26+
--EXPECT--
27+
array(2) {
28+
["I"]=>
29+
int(1)
30+
["C"]=>
31+
string(8) "test1(1)"
32+
}

tests/ibase_trans_009.phpt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
ibase_trans(): transaction control with SQL
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
$queries = [
12+
"SET TRANSACTION",
13+
"DELETE FROM TEST1",
14+
"COMMIT RETAIN",
15+
["INSERT INTO TEST1 (I, C) VALUES (?, ?)", [1, "test2(1)"]],
16+
"SAVEPOINT sp_name",
17+
["INSERT INTO TEST1 (I, C) VALUES (?, ?)", [2, "test2(2)"]],
18+
];
19+
20+
print "---- current status\n";
21+
ibase_query_bulk($queries);
22+
dump_table_rows("TEST1");
23+
24+
print "---- now rollback\n";
25+
ibase_query_bulk([
26+
"ROLLBACK TO SAVEPOINT sp_name",
27+
"COMMIT",
28+
]);
29+
dump_table_rows("TEST1");
30+
})();
31+
32+
?>
33+
--EXPECT--
34+
---- current status
35+
array(2) {
36+
["I"]=>
37+
int(1)
38+
["C"]=>
39+
string(8) "test2(1)"
40+
}
41+
array(2) {
42+
["I"]=>
43+
int(2)
44+
["C"]=>
45+
string(8) "test2(2)"
46+
}
47+
---- now rollback
48+
array(2) {
49+
["I"]=>
50+
int(1)
51+
["C"]=>
52+
string(8) "test2(1)"
53+
}

tests/ibase_trans_010.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
ibase_trans(): transaction control with SQL - commit default transaction
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
var_dump(ibase_query("COMMIT"));
12+
var_dump(ibase_query("COMMIT"));
13+
})();
14+
15+
?>
16+
--EXPECT--
17+
bool(true)
18+
bool(true)

tests/ibase_trans_011.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
ibase_trans(): transaction control with SQL - commit explicitly
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
require("interbase.inc");
9+
10+
(function() {
11+
var_dump($t = ibase_query("SET TRANSACTION"));
12+
var_dump(ibase_query($t, "COMMIT"));
13+
var_dump(ibase_query($t, "COMMIT"));
14+
})();
15+
16+
?>
17+
--EXPECTF--
18+
resource(%d) of type (Firebird/InterBase transaction)
19+
bool(true)
20+
21+
Warning: ibase_query(): Dynamic SQL Error SQL error code = -901 invalid transaction handle (expecting explicit transaction start)%s
22+
bool(false)

0 commit comments

Comments
 (0)