Permalink
Browse files

MFH: fix #41711 (Null temporary lobs not supported)

  • Loading branch information...
1 parent 386cf78 commit fa8a77a46632acea0e7b0587185425bd5b595d1f @tony2001 tony2001 committed Jun 25, 2007
Showing with 268 additions and 2 deletions.
  1. +2 −0 NEWS
  2. +1 −2 ext/oci8/oci8_lob.c
  3. +265 −0 ext/oci8/tests/lob_null.phpt
View
@@ -41,6 +41,8 @@ PHP NEWS
- Fixed bug #41724 (libxml_get_last_error() - errors service request scope).
(thekid at php dot net, Ilia)
- Fixed bug #41717 (imagepolygon does not respect thickness). (Pierre)
+- Fixed bug #41711 (NULL temporary lobs not supported in OCI8).
+ (Chris Jones, Tony)
- Fixed bug #41686 (Omitting length param in array_slice not possible).
(Ilia)
- Fixed bug #41685 (array_push() fails to warn when next index is already
View
@@ -859,8 +859,7 @@ int php_oci_lob_write_tmp (php_oci_descriptor *descriptor, ub1 type, char *data,
break;
}
- if (!data || data_len <= 0) {
- /* nothing to write, silently fail */
+ if (data_len < 0) {
return 1;
}
@@ -0,0 +1,265 @@
+--TEST--
+Test null data for CLOBs
+--SKIPIF--
+<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
+--FILE--
+<?php
+
+require dirname(__FILE__).'/connect.inc';
+
+// Initialization
+
+$s = oci_parse($c, 'drop table lob_null_tab');
+@oci_execute($s);
+
+$s = oci_parse($c, 'create table lob_null_tab (id number, data clob)');
+oci_execute($s);
+
+$s = oci_parse($c,
+'create or replace procedure lob_null_proc_in (pid in number, pdata in CLOB)
+ as begin
+ insert into lob_null_tab (id, data) values (pid, pdata);
+ end;');
+oci_execute($s);
+
+$s = oci_parse($c,
+'create or replace procedure lob_null_proc_out (pid in number, pdata out clob)
+ as begin
+ select data into pdata from lob_null_tab where id = pid;
+ end;');
+oci_execute($s);
+
+// TEMPORARY CLOB
+
+echo "Temporary CLOB: NULL\n";
+$s = oci_parse($c, "insert into lob_null_tab values (1, :b)");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+$lob->writeTemporary(null);
+$r = @oci_execute($s);
+if (!$r) {
+ $m = oci_error($s);
+ echo $m['message'], "\n";
+}
+else {
+ $lob->close();
+}
+
+echo "Temporary CLOB: ''\n";
+$s = oci_parse($c, "insert into lob_null_tab values (2, :b)");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+$lob->writeTemporary('');
+$r = @oci_execute($s);
+if (!$r) {
+ $m = oci_error($s);
+ echo $m['message'], "\n";
+}
+else {
+ $lob->close();
+}
+
+echo "Temporary CLOB: text\n";
+$s = oci_parse($c, "insert into lob_null_tab values (3, :b)");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+$lob->writeTemporary('Inserted via SQL statement');
+$r = @oci_execute($s);
+if (!$r) {
+ $m = oci_error($s);
+ echo $m['message'], "\n";
+}
+else {
+ $lob->close();
+}
+
+// PROCEDURE PARAMETER
+
+echo "Procedure parameter: NULL\n";
+$s = oci_parse($c, "call lob_null_proc_in(4, :b)");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+$lob->writeTemporary(null);
+$r = @oci_execute($s);
+if (!$r) {
+ $m = oci_error($s);
+ echo $m['message'], "\n";
+}
+else {
+ $lob->close();
+}
+
+echo "Procedure parameter: ''\n";
+$s = oci_parse($c, "call lob_null_proc_in(5, :b)");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+$lob->writeTemporary('');
+$r = @oci_execute($s);
+if (!$r) {
+ $m = oci_error($s);
+ echo $m['message'], "\n";
+}
+else {
+ $lob->close();
+}
+
+echo "Procedure parameter: text\n";
+$s = oci_parse($c, "call lob_null_proc_in(6, :b)");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+$lob->writeTemporary('Inserted via procedure parameter');
+$r = @oci_execute($s);
+if (!$r) {
+ $m = oci_error($s);
+ echo $m['message'], "\n";
+}
+else {
+ $lob->close();
+}
+
+// RETURNING INTO
+
+echo "RETURNING INTO: null\n";
+$s = oci_parse($c, "insert into lob_null_tab values (7, empty_clob()) returning data into :b");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+oci_execute($s, OCI_DEFAULT); // Must have OCI_DEFAULT here so locator is still valid
+$lob->save(null);
+
+echo "RETURNING INTO: ''\n";
+$s = oci_parse($c, "insert into lob_null_tab values (8, empty_clob()) returning data into :b");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+oci_execute($s, OCI_DEFAULT); // Must have OCI_DEFAULT here so locator is still valid
+$lob->save('');
+
+echo "RETURNING INTO: text\n";
+$s = oci_parse($c, "insert into lob_null_tab values (9, empty_clob()) returning data into :b");
+$lob = oci_new_descriptor($c, OCI_D_LOB);
+oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+oci_execute($s, OCI_DEFAULT); // Must have OCI_DEFAULT here so locator is still valid
+$lob->save('Inserted with RETURNING INTO');
+
+echo "Fetch as string\n";
+$s = oci_parse ($c, 'select id, data from lob_null_tab order by id');
+oci_execute($s);
+oci_fetch_all($s, $res);
+var_dump($res);
+
+echo "\nFetch as a descriptor\n";
+$s = oci_parse ($c, 'select id, data from lob_null_tab order by id');
+oci_execute($s);
+while ($arr = oci_fetch_assoc($s)) {
+ if (is_object($arr['DATA'])) {
+ echo $arr['ID'] . " is an object: ";
+ $r = $arr['DATA']->load();
+ var_dump($r);
+ }
+ else {
+ echo $arr['ID'] . " is not an object\n";
+ }
+}
+
+echo "\nFetch via the procedure parameter\n";
+for ($i = 1; $i <= 9; $i++)
+{
+ $s = oci_parse ($c, "call lob_null_proc_out($i, :b)");
+ $lob = oci_new_descriptor($c, OCI_D_LOB);
+ oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
+ oci_execute($s);
+ if (is_object($lob)) {
+ echo $i . " is an object: ";
+ $r = $lob->load();
+ var_dump($r);
+ }
+ else {
+ echo $i . " is not an object\n";
+ }
+}
+
+// Cleanup
+
+$s = oci_parse($c, 'drop table lob_null_tab');
+@oci_execute($s);
+
+echo "Done\n";
+
+?>
+--EXPECTF--
+Temporary CLOB: NULL
+Temporary CLOB: ''
+Temporary CLOB: text
+Procedure parameter: NULL
+Procedure parameter: ''
+Procedure parameter: text
+RETURNING INTO: null
+RETURNING INTO: ''
+RETURNING INTO: text
+Fetch as string
+array(2) {
+ ["ID"]=>
+ array(9) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+ [2]=>
+ string(1) "3"
+ [3]=>
+ string(1) "4"
+ [4]=>
+ string(1) "5"
+ [5]=>
+ string(1) "6"
+ [6]=>
+ string(1) "7"
+ [7]=>
+ string(1) "8"
+ [8]=>
+ string(1) "9"
+ }
+ ["DATA"]=>
+ array(9) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(0) ""
+ [2]=>
+ string(26) "Inserted via SQL statement"
+ [3]=>
+ string(0) ""
+ [4]=>
+ string(0) ""
+ [5]=>
+ string(32) "Inserted via procedure parameter"
+ [6]=>
+ string(0) ""
+ [7]=>
+ string(0) ""
+ [8]=>
+ string(28) "Inserted with RETURNING INTO"
+ }
+}
+
+Fetch as a descriptor
+1 is an object: string(0) ""
+2 is an object: string(0) ""
+3 is an object: string(26) "Inserted via SQL statement"
+4 is an object: string(0) ""
+5 is an object: string(0) ""
+6 is an object: string(32) "Inserted via procedure parameter"
+7 is an object: string(0) ""
+8 is an object: string(0) ""
+9 is an object: string(28) "Inserted with RETURNING INTO"
+
+Fetch via the procedure parameter
+1 is an object: string(0) ""
+2 is an object: string(0) ""
+3 is an object: string(26) "Inserted via SQL statement"
+4 is an object: string(0) ""
+5 is an object: string(0) ""
+6 is an object: string(32) "Inserted via procedure parameter"
+7 is an object: string(0) ""
+8 is an object: string(0) ""
+9 is an object: string(28) "Inserted with RETURNING INTO"
+Done

0 comments on commit fa8a77a

Please sign in to comment.