xref: /PHP-5.3/ext/pgsql/tests/05large_object.phpt (revision e5879a50)
1--TEST--
2PostgreSQL large object
3--SKIPIF--
4<?php include("skipif.inc"); ?>
5--FILE--
6<?php
7
8include('config.inc');
9
10$db = pg_connect($conn_str);
11
12echo "create/write/close LO\n";
13pg_exec ($db, "begin");
14$oid = pg_lo_create ($db);
15if (!$oid) echo ("pg_lo_create() error\n");
16$handle = pg_lo_open ($db, $oid, "w");
17if (!$handle) echo ("pg_lo_open() error\n");
18pg_lo_write ($handle, "large object data\n");
19pg_lo_close ($handle);
20pg_exec ($db, "commit");
21
22echo "open/read/tell/seek/close LO\n";
23pg_exec ($db, "begin");
24$handle = pg_lo_open ($db, $oid, "w");
25pg_lo_read($handle, 100);
26pg_lo_tell($handle);
27pg_lo_seek($handle, 2);
28pg_lo_close($handle);
29pg_exec ($db, "commit");
30
31echo "open/read_all/close LO\n";
32pg_exec ($db, "begin");
33$handle = pg_lo_open ($db, $oid, "w");
34pg_lo_read_all($handle);
35if (pg_last_error()) echo "pg_lo_read_all() error\n".pg_last_error();
36pg_lo_close($handle);
37pg_exec ($db, "commit");
38
39echo "unlink LO\n";
40pg_exec ($db, "begin");
41pg_lo_unlink($db, $oid) or print("pg_lo_unlink() error 1\n");
42pg_exec ($db, "commit");
43
44// more pg_lo_unlink() tests
45echo "Test without connection\n";
46pg_exec ($db, "begin");
47$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
48pg_lo_unlink($oid) or print("pg_lo_unlink() error 2\n");
49pg_exec ($db, "commit");
50
51echo "Test with string oid value\n";
52pg_exec ($db, "begin");
53$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
54pg_lo_unlink($db, (string)$oid) or print("pg_lo_unlink() error 3\n");
55pg_exec ($db, "commit");
56
57echo "import/export LO\n";
58$path = dirname(__FILE__) . '/';
59pg_query($db, 'begin');
60$oid = pg_lo_import($db, $path . 'php.gif');
61pg_query($db, 'commit');
62pg_query($db, 'begin');
63@unlink($path . 'php.gif.exported');
64pg_lo_export($oid, $path . 'php.gif.exported', $db);
65if (!file_exists($path . 'php.gif.exported')) {
66	echo "Export failed\n";
67}
68@unlink($path . 'php.gif.exported');
69pg_query($db, 'commit');
70
71echo "OK";
72?>
73--EXPECT--
74create/write/close LO
75open/read/tell/seek/close LO
76open/read_all/close LO
77large object data
78unlink LO
79Test without connection
80Test with string oid value
81import/export LO
82OK
83