update doc links
[m6w6/ext-pq] / tests / copy001.phpt
1 --TEST--
2 copy
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 copy_test; CREATE TABLE copy_test (id serial, line text);");
13
14 $file = file(__FILE__);
15
16 $in = new pq\COPY($c, "copy_test (line)", pq\COPY::FROM_STDIN, "DELIMITER '\t'");
17
18 var_dump(
19 $c === $in->connection,
20 "copy_test (line)" === $in->expression,
21 pq\COPY::FROM_STDIN === $in->direction,
22 "DELIMITER '\t'" === $in->options
23 );
24
25 foreach ($file as $i => $line) {
26 $in->put(addcslashes($line, "\\\t"));
27 }
28 $in->end();
29
30 $out = new pq\COPY($c, "copy_test (line)", pq\COPY::TO_STDOUT, "DELIMITER '\t'");
31
32 var_dump(
33 $c === $out->connection,
34 "copy_test (line)" === $out->expression,
35 pq\COPY::TO_STDOUT === $out->direction,
36 "DELIMITER '\t'" === $out->options
37 );
38
39 while ($out->get($line)) {
40 $lines[] = stripcslashes($line);
41 }
42
43 var_dump($file == $lines);
44
45 if ($file != $lines) {
46 foreach (array_keys(array_diff($file, $lines)) as $idx) {
47 var_dump($idx, $file[$idx], $lines[$idx], "##############");
48 }
49 }
50
51 $c->exec("DROP TABLE copy_test");
52
53 ?>
54 DONE
55 --EXPECT--
56 Test
57 bool(true)
58 bool(true)
59 bool(true)
60 bool(true)
61 bool(true)
62 bool(true)
63 bool(true)
64 bool(true)
65 bool(true)
66 DONE
67