1
0
mirror of https://github.com/danog/ext-pq.git synced 2024-11-26 20:04:44 +01:00
This commit is contained in:
Michael Wallner 2013-01-21 12:13:04 +01:00
parent d6a052266a
commit f7aeb22e11
5 changed files with 102 additions and 0 deletions

2
tests/_setup.inc Normal file
View File

@ -0,0 +1,2 @@
<?php
define("PQ_DSN", "dbname=mike");

5
tests/_skipif.inc Normal file
View File

@ -0,0 +1,5 @@
<?php
function _ext($ext) {
extension_loaded($ext) or die("skip $ext not loaded");
}
_ext("pq");

51
tests/basic001.phpt Normal file
View File

@ -0,0 +1,51 @@
--TEST--
basic functionality
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$con = new pq\Connection(PQ_DSN);
$res = $con->exec("SELECT 1 as one, 2 as two from generate_series(1,2)");
var_dump($res->status == pq\Result::TUPLES_OK);
var_dump($res->numRows);
var_dump($res->numCols);
foreach ($res as $rowNum => $rowData) {
printf("%d.0 => %d\n", $rowNum, $rowData[0]);
printf("%d.1 => %d\n", $rowNum, $rowData[1]);
}
$res->fetchType = pq\Result::FETCH_ASSOC;
foreach ($res as $rowNum => $rowData) {
printf("%d.0 => %d\n", $rowNum, $rowData["one"]);
printf("%d.1 => %d\n", $rowNum, $rowData["two"]);
}
$res->fetchType = pq\Result::FETCH_OBJECT;
foreach ($res as $rowNum => $rowData) {
printf("%d.0 => %d\n", $rowNum, $rowData->one);
printf("%d.1 => %d\n", $rowNum, $rowData->two);
}
?>
DONE
--EXPECT--
Test
bool(true)
int(2)
int(2)
0.0 => 1
0.1 => 2
1.0 => 1
1.1 => 2
0.0 => 1
0.1 => 2
1.0 => 1
1.1 => 2
0.0 => 1
0.1 => 2
1.0 => 1
1.1 => 2
DONE

22
tests/basic002.phpt Normal file
View File

@ -0,0 +1,22 @@
--TEST--
basic functionality
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN);
$s = $c->prepare("test1", "SELECT \$1",array($c->types->byName->text->oid));
$r = $s->exec(array("fooo"));
printf("%s\n", $r->errorMessage);
printf("%s\n", $r->fetchCol());
?>
DONE
--EXPECT--
Test
fooo
DONE

22
tests/stm_desc001.phpt Normal file
View File

@ -0,0 +1,22 @@
--TEST--
pq\Statment::desc()
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN);
$s = $c->prepare("test1", "SELECT NOW() - \$1");
$r = $s->exec(array("2012-12-12 12:12:12"));
$d = $s->desc();
printf("%s\n", $c->types->byOid->{$d[0]}->typname);
?>
DONE
--EXPECT--
Test
timestamptz
DONE