typo
[m6w6/ext-pq] / tests / trans001.phpt
1 --TEST--
2 transaction
3 --SKIPIF--
4 <?php include "_skipif.inc"; ?>
5 --FILE--
6 <?php
7 echo "Test\n";
8
9 include "_setup.inc";
10
11 $c = new pq\Connection(PQ_DSN);
12 $c->exec("DROP TABLE IF EXISTS test");
13 $c->on(pq\Connection::EVENT_NOTICE, function($c, $notice) {
14 echo "Got notice: $notice\n";
15 });
16 var_dump($c->transactionStatus == pq\Connection::TRANS_IDLE);
17 $t = new pq\Transaction($c);
18 var_dump($t->connection->transactionStatus == pq\Connection::TRANS_INTRANS);
19 $c->exec("DROP TABLE IF EXISTS test");
20 $c->exec("CREATE TABLE test (id serial, data text)");
21 $s = $c->prepare("test_insert", "INSERT INTO test (data) VALUES (\$1)", array((new pq\Types($c))["text"]->oid));
22 $s->exec(array("a"));
23 $s->exec(array("b"));
24 $s->exec(array("c"));
25 $r = $c->exec("SELECT * FROM test");
26 while ($row = $r->fetchRow(pq\Result::FETCH_OBJECT)) {
27 printf("%d => %s\n", $row->id, $row->data);
28 }
29 $t->rollback();
30 var_dump($c->transactionStatus == pq\Connection::TRANS_IDLE);
31 ?>
32 DONE
33 --EXPECT--
34 Test
35 bool(true)
36 bool(true)
37 Got notice: NOTICE: table "test" does not exist, skipping
38 Got notice: NOTICE: CREATE TABLE will create implicit sequence "test_id_seq" for serial column "test.id"
39 1 => a
40 2 => b
41 3 => c
42 bool(true)
43 DONE