xref: /PHP-7.0/ext/interbase/tests/005.phpt (revision 4e7cb057)
1--TEST--
2InterBase: transactions
3--SKIPIF--
4<?php include("skipif.inc"); ?>
5--FILE--
6<?php
7
8    require("interbase.inc");
9
10    ibase_connect($test_base);
11
12    @ibase_query("create table test5 (i integer)");
13    @ibase_query("delete from test5");
14    ibase_close();
15
16
17    echo "default transaction:\n";
18
19/*
20Difference between default and other transactions:
21default committed when you call  ibase_close().
22Other transaction doing rollback.
23
24If you not open default transaction with
25ibase_trans, default transaction open
26when you call ibase_query(), ibase_prepare(),
27ibase_blob_create(), ibase_blob_import()  first time.
28*/
29
30/*
31simple default transaction test without ibase_trans()
32*/
33
34    ibase_connect($test_base);
35
36    echo "empty table\n";
37
38	/*  out_table call ibase_query()
39      and ibase_query() start default transaction */
40    out_table("test5");
41
42    /* in default transaction context */
43    ibase_query("insert into test5 (i) values (1)");
44
45    echo "one row\n";
46    out_table("test5");
47
48    ibase_rollback(); /* default rolled */
49
50    echo "after rollback table empty again\n";
51    out_table("test5");  /* started new default transaction */
52
53    ibase_query("insert into test5 (i) values (2)");
54
55    ibase_close(); /* commit here! */
56
57    ibase_connect($test_base);
58
59    echo "one row\n";
60    out_table("test5");
61    ibase_close();
62
63/*
64default transaction on default link
65First open transaction on link will be default.
66$tr_def_l1 may be omitted. All queryes without link and trans
67parameters run in this context
68*/
69
70    $link_def = ibase_connect($test_base);
71
72    $tr_def_l1 = ibase_trans(IBASE_READ); /* here transaction start */
73
74    /* all default */
75	$res = ibase_query("select * from test5");
76
77    echo "one row\n";
78    out_result($res,"test5");
79
80    ibase_free_result($res);
81
82    /* specify transaction context...  */
83	$res = ibase_query($tr_def_l1, "select * from test5");
84
85    echo "one row... again.\n";
86    out_result($res,"test5");
87
88    ibase_free_result($res);
89
90    /* specify default transaction on link  */
91	$res = ibase_query($link_def, "select * from test5");
92
93    echo "one row.\n";
94    out_result($res,"test5");
95
96    ibase_free_result($res);
97
98    ibase_rollback($link_def); /* just for example */
99
100    ibase_close();
101
102/*
103three transaction on default link
104*/
105    ibase_connect($test_base);
106
107	$res = ibase_query("select * from test5");
108
109    echo "one row\n";
110    out_result($res,"test5");
111
112    ibase_free_result($res);
113
114	$tr_1 = ibase_query("SET TRANSACTION");
115	$tr_2 = ibase_query("SET TRANSACTION READ ONLY");
116	$tr_3 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_VERSION+IBASE_WAIT);
117	$tr_4 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_NO_VERSION+IBASE_NOWAIT);
118
119    /* insert in first transaction context...  */
120    /* as default */
121    ibase_query("insert into test5 (i) values (3)");
122    /* specify context */
123    ibase_query($tr_1, "insert into test5 (i) values (4)");
124
125	$res = ibase_query("select * from test5");
126
127    echo "two rows\n";
128    out_result($res,"test5");
129
130    ibase_free_result($res);
131
132	$res = ibase_query($tr_1, "select * from test5");
133
134    echo "two rows again\n";
135    out_result($res,"test5");
136
137    ibase_free_result($res);
138
139	ibase_commit();
140    ibase_commit($tr_1);
141
142	$tr_1 = ibase_trans();
143  	 ibase_query($tr_1, "insert into test5 (i) values (5)");
144
145	/* tr_2 is IBASE_READ + IBASE_CONCURRENCY + IBASE_WAIT */
146	$res = ibase_query($tr_2, "select * from test5");
147
148    echo "one row in second transaction\n";
149    out_result($res,"test5");
150
151    ibase_free_result($res);
152
153	/* tr_3 is IBASE_COMMITTED + IBASE_REC_VERSION + IBASE_WAIT */
154	$res = ibase_query($tr_3, "select * from test5");
155
156    echo "three rows in third transaction\n";
157    out_result($res,"test5");
158
159    ibase_free_result($res);
160
161 	/* tr_4 IBASE_COMMITTED + IBASE_REC_NO_VERSION + IBASE_NOWAIT */
162 	$res = ibase_query($tr_4, "select * from test5");
163
164 	 echo "three rows in fourth transaction with deadlock\n";
165    out_result_trap_error($res,"test5");
166
167    ibase_free_result($res);
168
169	 ibase_rollback($tr_1);
170    ibase_close();
171/*
172transactions on second link
173*/
174    $link_1 = ibase_pconnect($test_base);
175    $link_2 = ibase_pconnect($test_base);
176
177	$tr_1 = ibase_trans(IBASE_DEFAULT, $link_2);  /* this default transaction also */
178	$tr_2 = ibase_trans(IBASE_COMMITTED, $link_2);
179
180	$res = ibase_query($tr_1, "select * from test5");
181
182    echo "three rows\n";
183    out_result($res,"test5");
184
185    ibase_free_result($res);
186
187    ibase_query($tr_1, "insert into test5 (i) values (5)");
188
189	$res = ibase_query($tr_1, "select * from test5");
190
191    echo "four rows\n";
192    out_result($res,"test5");
193
194    ibase_free_result($res);
195
196    ibase_commit($tr_1);
197
198	$res = ibase_query($tr_2, "select * from test5");
199
200    echo "four rows again\n";
201    out_result($res,"test5");
202
203    ibase_free_result($res);
204
205    ibase_close($link_1);
206    ibase_close($link_2);
207
208    echo "end of test\n";
209?>
210--EXPECTF--
211default transaction:
212empty table
213--- test5 ---
214---
215one row
216--- test5 ---
2171
218---
219after rollback table empty again
220--- test5 ---
221---
222one row
223--- test5 ---
2242
225---
226one row
227--- test5 ---
2282
229---
230one row... again.
231--- test5 ---
2322
233---
234one row.
235--- test5 ---
2362
237---
238one row
239--- test5 ---
2402
241---
242two rows
243--- test5 ---
2442
2453
246---
247two rows again
248--- test5 ---
2492
2504
251---
252one row in second transaction
253--- test5 ---
2542
255---
256three rows in third transaction
257--- test5 ---
2582
2593
2604
261---
262three rows in fourth transaction with deadlock
263--- test5 ---
2642
2653
2664
267errmsg [lock conflict on no wait transaction deadlock %a]
268---
269three rows
270--- test5 ---
2712
2723
2734
274---
275four rows
276--- test5 ---
2772
2783
2794
2805
281---
282four rows again
283--- test5 ---
2842
2853
2864
2875
288---
289end of test
290
291