Annotation of embedaddon/php/ext/interbase/tests/005.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: InterBase: transactions
3: --SKIPIF--
4: <?php include("skipif.inc"); ?>
5: --FILE--
6: <?php /* $Id: 005.phpt 158958 2004-05-19 08:56:50Z helly $ */
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: /*
20: Difference between default and other transactions:
21: default commited when you call ibase_close().
22: Other transaction doing rollback.
23:
24: If you not open default transaction with
25: ibase_trans, default transaction open
26: when you call ibase_query(), ibase_prepare(),
27: ibase_blob_create(), ibase_blob_import() first time.
28: */
29:
30: /*
31: simple 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: /*
64: default transaction on default link
65: First open transaction on link will be default.
66: $tr_def_l1 may be ommited. All queryes without link and trans
67: parameters 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: /*
103: three 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_COMMITED + 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: /*
172: transactions 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: --EXPECT--
211: default transaction:
212: empty table
213: --- test5 ---
214: ---
215: one row
216: --- test5 ---
217: 1
218: ---
219: after rollback table empty again
220: --- test5 ---
221: ---
222: one row
223: --- test5 ---
224: 2
225: ---
226: one row
227: --- test5 ---
228: 2
229: ---
230: one row... again.
231: --- test5 ---
232: 2
233: ---
234: one row.
235: --- test5 ---
236: 2
237: ---
238: one row
239: --- test5 ---
240: 2
241: ---
242: two rows
243: --- test5 ---
244: 2
245: 3
246: ---
247: two rows again
248: --- test5 ---
249: 2
250: 4
251: ---
252: one row in second transaction
253: --- test5 ---
254: 2
255: ---
256: three rows in third transaction
257: --- test5 ---
258: 2
259: 3
260: 4
261: ---
262: three rows in fourth transaction with deadlock
263: --- test5 ---
264: 2
265: 3
266: 4
267: errmsg [lock conflict on no wait transaction deadlock ]
268: ---
269: three rows
270: --- test5 ---
271: 2
272: 3
273: 4
274: ---
275: four rows
276: --- test5 ---
277: 2
278: 3
279: 4
280: 5
281: ---
282: four rows again
283: --- test5 ---
284: 2
285: 3
286: 4
287: 5
288: ---
289: end of test
290:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>