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