1
0
mirror of https://github.com/danog/ext-pq.git synced 2024-12-02 09:18:02 +01:00
ext-pq/tests/trans001.phpt

45 lines
1.1 KiB
Plaintext
Raw Normal View History

2013-01-25 21:08:56 +01:00
--TEST--
transaction
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN);
2014-09-30 20:44:46 +02:00
$c->exec("DROP TABLE IF EXISTS test CASCADE");
$c->exec("SET client_min_messages TO NOTICE");
2013-02-21 13:18:06 +01:00
$c->on(pq\Connection::EVENT_NOTICE, function($c, $notice) {
2014-07-14 18:21:46 +02:00
echo "Got notice: $notice\n";
2013-01-26 19:57:07 +01:00
});
2013-02-14 14:54:22 +01:00
var_dump($c->transactionStatus == pq\Connection::TRANS_IDLE);
2013-01-25 21:08:56 +01:00
$t = new pq\Transaction($c);
2013-02-14 14:54:22 +01:00
var_dump($t->connection->transactionStatus == pq\Connection::TRANS_INTRANS);
$c->exec("DROP TABLE IF EXISTS test");
2014-07-14 18:21:46 +02:00
$c->off(pq\Connection::EVENT_NOTICE);
$c->exec("CREATE TABLE test (id serial, data text)");
$s = $c->prepare("test_insert", "INSERT INTO test (data) VALUES (\$1)", array((new pq\Types($c))["text"]->oid));
2013-01-25 21:08:56 +01:00
$s->exec(array("a"));
$s->exec(array("b"));
$s->exec(array("c"));
$r = $c->exec("SELECT * FROM test");
while ($row = $r->fetchRow(pq\Result::FETCH_OBJECT)) {
printf("%d => %s\n", $row->id, $row->data);
}
$t->rollback();
2013-02-14 14:54:22 +01:00
var_dump($c->transactionStatus == pq\Connection::TRANS_IDLE);
2013-01-25 21:08:56 +01:00
?>
DONE
--EXPECT--
Test
2013-02-14 14:54:22 +01:00
bool(true)
bool(true)
2013-01-26 19:57:07 +01:00
Got notice: NOTICE: table "test" does not exist, skipping
2013-01-25 21:08:56 +01:00
1 => a
2 => b
3 => c
2013-02-14 14:54:22 +01:00
bool(true)
2013-01-25 21:08:56 +01:00
DONE