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