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