1
0
mirror of https://github.com/danog/ext-pq.git synced 2024-12-11 17:09:39 +01:00
ext-pq/tests/copy001.phpt

68 lines
1.2 KiB
Plaintext
Raw Normal View History

2013-01-30 17:21:38 +01:00
--TEST--
copy
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN);
$c->exec("DROP TABLE IF EXISTS copy_test; CREATE TABLE copy_test (id serial, line text);");
$file = file(__FILE__);
$in = new pq\COPY($c, "copy_test (line)", pq\COPY::FROM_STDIN, "DELIMITER '\t'");
2013-05-14 13:09:23 +02:00
var_dump(
$c === $in->connection,
"copy_test (line)" === $in->expression,
pq\COPY::FROM_STDIN === $in->direction,
"DELIMITER '\t'" === $in->options
);
2013-01-30 17:21:38 +01:00
foreach ($file as $i => $line) {
$in->put(addcslashes($line, "\\\t"));
}
$in->end();
$out = new pq\COPY($c, "copy_test (line)", pq\COPY::TO_STDOUT, "DELIMITER '\t'");
2013-05-14 13:09:23 +02:00
var_dump(
$c === $out->connection,
"copy_test (line)" === $out->expression,
pq\COPY::TO_STDOUT === $out->direction,
"DELIMITER '\t'" === $out->options
);
2013-01-30 17:21:38 +01:00
while ($out->get($line)) {
$lines[] = stripcslashes($line);
}
var_dump($file == $lines);
if ($file != $lines) {
foreach (array_keys(array_diff($file, $lines)) as $idx) {
var_dump($idx, $file[$idx], $lines[$idx], "##############");
}
}
$c->exec("DROP TABLE copy_test");
?>
DONE
--EXPECT--
Test
bool(true)
2013-05-14 13:09:23 +02:00
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
2013-01-30 17:21:38 +01:00
DONE