mirror of
https://github.com/php/php-src.git
synced 2024-10-21 16:33:44 +00:00
f361d9e4f0
patch and tests by Chris Jones
106 lines
2.6 KiB
PHP
106 lines
2.6 KiB
PHP
--TEST--
|
|
Test oci_define_by_name() LOB descriptor
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
require dirname(__FILE__)."/connect.inc";
|
|
|
|
$stmt = oci_parse($c, "create table phpdefblobtable( id number(10), fileimage blob)");
|
|
oci_execute($stmt);
|
|
|
|
// Load data
|
|
$stmt = oci_parse ($c, "insert into phpdefblobtable (id, fileimage) values (:id, empty_blob()) returning fileimage into :fileimage");
|
|
$fileimage = oci_new_descriptor($c,OCI_D_LOB);
|
|
oci_bind_by_name($stmt,":id",$id);
|
|
oci_bind_by_name($stmt,":fileimage",$fileimage,-1,OCI_B_BLOB);
|
|
$id = 1;
|
|
oci_execute($stmt, OCI_DEFAULT);
|
|
$fileimage->savefile(dirname(__FILE__)."/test.gif");
|
|
$data = $fileimage->load();
|
|
var_dump(md5($data)); // original md5
|
|
oci_commit($c);
|
|
|
|
// New row with different data
|
|
$id = 2;
|
|
$data = strrev($data);
|
|
var_dump(md5($data));
|
|
oci_execute($stmt, OCI_DEFAULT);
|
|
$fileimage->save($data);
|
|
oci_commit($c);
|
|
|
|
echo "Test 1\n";
|
|
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
|
|
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $f));
|
|
oci_execute($stmt);
|
|
|
|
while (oci_fetch($stmt)) {
|
|
var_dump($f);
|
|
echo "file md5:" . md5($f->load()) . "\n";
|
|
}
|
|
|
|
echo "Test 2\n";
|
|
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
|
|
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_STR));
|
|
oci_execute($stmt);
|
|
|
|
while (oci_fetch($stmt)) {
|
|
echo "file md5:" . md5($outdata) . "\n";
|
|
}
|
|
|
|
echo "Test 3\n";
|
|
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
|
|
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_BIN));
|
|
oci_execute($stmt);
|
|
|
|
while (oci_fetch($stmt)) {
|
|
echo "file md5:" . md5($outdata) . "\n";
|
|
}
|
|
|
|
echo "Test 4\n";
|
|
$fid = oci_new_descriptor($c,OCI_D_LOB);
|
|
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
|
|
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fid));
|
|
oci_execute($stmt);
|
|
|
|
while (oci_fetch($stmt)) {
|
|
echo "file md5:" . md5($fid->load()) . "\n";
|
|
}
|
|
|
|
$stmt = oci_parse($c, "drop table phpdefblobtable");
|
|
oci_execute($stmt);
|
|
|
|
echo "Done\n";
|
|
|
|
?>
|
|
--EXPECTF--
|
|
string(32) "614fcbba1effb7caa27ef0ef25c27fcf"
|
|
string(32) "06d4f219d946c74d748d43932cd9dcb2"
|
|
Test 1
|
|
bool(true)
|
|
object(OCI-Lob)#%d (1) {
|
|
["descriptor"]=>
|
|
resource(%d) of type (oci8 descriptor)
|
|
}
|
|
file md5:614fcbba1effb7caa27ef0ef25c27fcf
|
|
object(OCI-Lob)#%d (1) {
|
|
["descriptor"]=>
|
|
resource(%d) of type (oci8 descriptor)
|
|
}
|
|
file md5:06d4f219d946c74d748d43932cd9dcb2
|
|
Test 2
|
|
bool(true)
|
|
|
|
Warning: oci_fetch(): ORA-00932: %s on line %d
|
|
Test 3
|
|
bool(true)
|
|
file md5:614fcbba1effb7caa27ef0ef25c27fcf
|
|
file md5:06d4f219d946c74d748d43932cd9dcb2
|
|
Test 4
|
|
bool(true)
|
|
file md5:614fcbba1effb7caa27ef0ef25c27fcf
|
|
file md5:06d4f219d946c74d748d43932cd9dcb2
|
|
Done
|
|
|