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 = __DIR__ . '/'; 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($db, $oid, $path . 'php.gif.exported'); 65if (!file_exists($path . 'php.gif.exported')) { 66 echo "Export failed\n"; 67} 68@unlink($path . 'php.gif.exported'); 69pg_query($db, 'commit'); 70 71/* invalid OID values */ 72try { 73 pg_lo_create(-15); 74} catch (\ValueError $e) { 75 echo $e->getMessage(), \PHP_EOL; 76} 77try { 78 pg_lo_create($db, -15); 79} catch (\ValueError $e) { 80 echo $e->getMessage(), \PHP_EOL; 81} 82try { 83 pg_lo_create('giberrish'); 84} catch (\ValueError $e) { 85 echo $e->getMessage(), \PHP_EOL; 86} 87try { 88 pg_lo_create($db, 'giberrish'); 89} catch (\ValueError $e) { 90 echo $e->getMessage(), \PHP_EOL; 91} 92 93echo "OK"; 94?> 95--EXPECT-- 96create/write/close LO 97open/read/tell/seek/close LO 98open/read_all/close LO 99large object data 100unlink LO 101Test without connection 102Test with string oid value 103import/export LO 104Invalid OID value passed 105Invalid OID value passed 106Invalid OID value passed 107Invalid OID value passed 108OK 109