xref: /PHP-8.4/ext/pgsql/tests/pg_put_copy.phpt (revision 162a311c)
1--TEST--
2PostgreSQL pg_put_copy_data/pg_end_copy_end
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php include("inc/skipif.inc"); ?>
7--FILE--
8<?php
9
10include('inc/config.inc');
11$db = pg_connect($conn_str);
12
13pg_query($db, "CREATE TABLE copystdin(id int, val text)");
14pg_query($db, "COPY copystdin(id, val) FROM STDIN");
15
16var_dump(pg_put_copy_data($db, "0\tFooBar\n"));
17var_dump(pg_put_copy_data($db, "1\tBarFoo\n"));
18var_dump(pg_put_copy_data($db, ""));
19var_dump(pg_put_copy_end($db));
20
21var_dump(pg_get_result($db));
22
23var_dump(pg_fetch_all(pg_query($db, "SELECT * FROM copystdin ORDER BY id")));
24var_dump(pg_put_copy_data($db, "Error\t1"));
25var_dump(pg_put_copy_end($db));
26var_dump(pg_last_error($db));
27
28pg_query($db, "COPY copystdin(id, val) FROM STDIN");
29var_dump(pg_put_copy_data($db, "Error\t1"));
30var_dump(pg_put_copy_end($db));
31
32var_dump(pg_get_result($db));
33
34var_dump(pg_fetch_all(pg_query($db, "SELECT * FROM copystdin ORDER BY id")));
35?>
36--CLEAN--
37<?php
38include('inc/config.inc');
39
40$db = pg_connect($conn_str);
41pg_query($db, "DROP TABLE IF EXISTS copystdin");
42?>
43--EXPECT--
44int(1)
45int(1)
46int(1)
47int(1)
48object(PgSql\Result)#2 (0) {
49}
50array(2) {
51  [0]=>
52  array(2) {
53    ["id"]=>
54    string(1) "0"
55    ["val"]=>
56    string(6) "FooBar"
57  }
58  [1]=>
59  array(2) {
60    ["id"]=>
61    string(1) "1"
62    ["val"]=>
63    string(6) "BarFoo"
64  }
65}
66int(-1)
67int(-1)
68string(39) "no COPY in progress
69no COPY in progress"
70int(1)
71int(1)
72object(PgSql\Result)#2 (0) {
73}
74array(2) {
75  [0]=>
76  array(2) {
77    ["id"]=>
78    string(1) "0"
79    ["val"]=>
80    string(6) "FooBar"
81  }
82  [1]=>
83  array(2) {
84    ["id"]=>
85    string(1) "1"
86    ["val"]=>
87    string(6) "BarFoo"
88  }
89}
90