1--TEST--
2PostgreSQL import large object with given oid
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("skipif.inc");
8$v = pg_version($conn);
9if (version_compare("8.4devel", $v["client"]) > 0) die("skip - requires pg client >= 8.4\n");
10if (version_compare("8.4devel", $v["server"]) > 0) die("skip - requires pg server >= 8.4\n");
11?>
12--FILE--
13<?php
14
15include('config.inc');
16
17$db = pg_connect($conn_str);
18
19echo "import LO from int\n";
20pg_exec($db, 'begin');
21$oid = pg_lo_import($db, __FILE__, 21003);
22if (!$oid) echo ("pg_lo_import() error\n");
23if ($oid != 21003) echo ("pg_lo_import() wrong id\n");
24pg_lo_unlink ($db, $oid);
25pg_exec($db, 'commit');
26
27echo "import LO from string\n";
28pg_exec($db, 'begin');
29$oid = pg_lo_import($db, __FILE__, "21004");
30if (!$oid) echo ("pg_lo_import() error\n");
31if ($oid != 21004) echo ("pg_lo_import() wrong id\n");
32pg_lo_unlink ($db, $oid);
33pg_exec($db, 'commit');
34
35echo "import LO using default connection\n";
36pg_exec('begin');
37$oid = pg_lo_import($db, __FILE__, 21005);
38if (!$oid) echo ("pg_lo_import() error\n");
39if ($oid != 21005) echo ("pg_lo_import() wrong id\n");
40pg_lo_unlink ($oid);
41pg_exec('commit');
42
43/* Invalide OID */
44try {
45    pg_lo_import(__FILE__, -15);
46} catch (\ValueError $e) {
47    echo $e->getMessage(), \PHP_EOL;
48}
49try {
50    pg_lo_import($db, __FILE__, -15);
51} catch (\ValueError $e) {
52    echo $e->getMessage(), \PHP_EOL;
53}
54try {
55    pg_lo_import(__FILE__, 'giberrish');
56} catch (\ValueError $e) {
57    echo $e->getMessage(), \PHP_EOL;
58}
59try {
60    pg_lo_import($db, __FILE__, 'giberrish');
61} catch (\ValueError $e) {
62    echo $e->getMessage(), \PHP_EOL;
63}
64try {
65    pg_lo_import(__FILE__, true);
66} catch (\TypeError $e) {
67    echo $e->getMessage(), \PHP_EOL;
68}
69try {
70    pg_lo_import($db, __FILE__, []);
71} catch (\TypeError $e) {
72    echo $e->getMessage(), \PHP_EOL;
73}
74try {
75    pg_lo_import($db, __FILE__, new stdClass());
76} catch (\TypeError $e) {
77    echo $e->getMessage(), \PHP_EOL;
78}
79try {
80    pg_lo_import($db, __FILE__, $db);
81} catch (\TypeError $e) {
82    echo $e->getMessage(), \PHP_EOL;
83}
84
85echo "OK";
86?>
87--EXPECTF--
88import LO from int
89import LO from string
90import LO using default connection
91
92Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
93
94Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
95
96Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
97
98Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
99Invalid OID value passed
100Invalid OID value passed
101
102Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
103Invalid OID value passed
104Invalid OID value passed
105
106Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
107OID value must be of type string|int, bool given
108OID value must be of type string|int, array given
109OID value must be of type string|int, stdClass given
110OID value must be of type string|int, PgSql\Connection given
111OK
112