cvs: php-src /ext/oci8 oci8_statement.c php_oci8_int.h /ext/oci8/tests bug37581.phpt bug38161.phpt
| From: | Antony Dovgal | Date: | Wed, 09 Aug 2006 12:13:30 +0000 |
| Subject: | cvs: php-src /ext/oci8 oci8_statement.c php_oci8_int.h /ext/oci8/tests bug37581.phpt bug38161.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-39870@lists.php.net to get a copy of this message | ||
tony2001 Wed Aug 9 12:13:30 2006 UTC
Added files:
/php-src/ext/oci8/tests bug38161.phpt
Modified files:
/php-src/ext/oci8 oci8_statement.c php_oci8_int.h
/php-src/ext/oci8/tests bug37581.phpt
Log:
fix #38161 (oci_bind_by_name() returns garbage when Oracle didn't set the variable)
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/oci8_statement.c?r1=1.22&r2=1.23&diff_format=u
Index: php-src/ext/oci8/oci8_statement.c
diff -u php-src/ext/oci8/oci8_statement.c:1.22 php-src/ext/oci8/oci8_statement.c:1.23
--- php-src/ext/oci8/oci8_statement.c:1.22 Wed Aug 9 11:48:50 2006
+++ php-src/ext/oci8/oci8_statement.c Wed Aug 9 12:13:30 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: oci8_statement.c,v 1.22 2006/08/09 11:48:50 tony2001 Exp $ */
+/* $Id: oci8_statement.c,v 1.23 2006/08/09 12:13:30 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
@@ -826,9 +826,11 @@
case SQLT_LNG:
case SQLT_CHR:
/* this is the default case when type was not specified */
- convert_to_string(var);
+ if (Z_TYPE_P(var) != IS_NULL) {
+ convert_to_string(var);
+ }
if (maxlength == -1) {
- value_sz = Z_STRLEN_P(var);
+ value_sz = (Z_TYPE_P(var) == IS_STRING) ? Z_STRLEN_P(var) : 0;
}
else {
value_sz = maxlength;
@@ -1003,7 +1005,7 @@
zval_dtor(val);
Z_STRLEN_P(val) = PHP_OCI_PIECE_SIZE; /* 64K-1 is max XXX */
- Z_STRVAL_P(val) = emalloc(Z_STRLEN_P(phpbind->zval));
+ Z_STRVAL_P(val) = ecalloc(1, Z_STRLEN_P(phpbind->zval) + 1);
/* XXX we assume that zend-zval len has 4 bytes */
*alenpp = (ub4*) &Z_STRLEN_P(phpbind->zval);
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/php_oci8_int.h?r1=1.18&r2=1.19&diff_format=u
Index: php-src/ext/oci8/php_oci8_int.h
diff -u php-src/ext/oci8/php_oci8_int.h:1.18 php-src/ext/oci8/php_oci8_int.h:1.19
--- php-src/ext/oci8/php_oci8_int.h:1.18 Mon Jul 31 10:28:46 2006
+++ php-src/ext/oci8/php_oci8_int.h Wed Aug 9 12:13:30 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_oci8_int.h,v 1.18 2006/07/31 10:28:46 tony2001 Exp $ */
+/* $Id: php_oci8_int.h,v 1.19 2006/08/09 12:13:30 tony2001 Exp $ */
#if HAVE_OCI8
# ifndef PHP_OCI8_INT_H
@@ -186,7 +186,7 @@
long max_length;
long type;
} array;
- sb2 indicator; /* */
+ sb2 indicator; /* -1 means NULL */
ub2 retcode; /* */
} php_oci_bind; /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/tests/bug37581.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/oci8/tests/bug37581.phpt
diff -u /dev/null php-src/ext/oci8/tests/bug37581.phpt:1.2
--- /dev/null Wed Aug 9 12:13:30 2006
+++ php-src/ext/oci8/tests/bug37581.phpt Wed Aug 9 12:13:30 2006
@@ -0,0 +1,69 @@
+--TEST--
+Bug #37581 (oci_bind_array_by_name clobbers input array when using SQLT_AFC, AVC)
+--SKIPIF--
+<?php if (!extension_loaded("oci8")) print "skip"; ?>
+--FILE--
+<?php
+
+require dirname(__FILE__)."/connect.inc";
+
+$p1 = "create or replace package ARRAYBINDPKG1 as
+type str_array is table of char(2) index by binary_integer;
+procedure array_bind(in_str in str_array, out_str out string);
+end ARRAYBINDPKG1;";
+
+$p2 = "create or replace package body ARRAYBINDPKG1 as
+ procedure array_bind(in_str in str_array, out_str out string) is
+ begin
+ for i in 1 .. in_str.count loop
+ out_str := in_str(i);
+ end loop;
+ end array_bind;
+end ARRAYBINDPKG1;";
+
+$s1 = oci_parse($c, $p1);
+$s2 = oci_parse($c, $p2);
+oci_execute($s1);
+oci_execute($s2);
+
+
+$stmt = oci_parse($c,'begin ARRAYBINDPKG1.array_bind(:in_arr, :out_str);
end;');
+$strings = array('A','B','C','D','E');
+
+oci_bind_array_by_name($stmt,':in_arr',$strings,5,1,SQLT_AFC);
+oci_bind_by_name($stmt,':out_str',$result,10);
+
+oci_execute($stmt);
+var_dump($strings);
+
+oci_execute($stmt);
+var_dump($strings);
+
+echo "Done\n";
+?>
+--EXPECTF--
+array(5) {
+ [0]=>
+ string(1) "A"
+ [1]=>
+ string(1) "B"
+ [2]=>
+ string(1) "C"
+ [3]=>
+ string(1) "D"
+ [4]=>
+ string(1) "E"
+}
+array(5) {
+ [0]=>
+ string(1) "A"
+ [1]=>
+ string(1) "B"
+ [2]=>
+ string(1) "C"
+ [3]=>
+ string(1) "D"
+ [4]=>
+ string(1) "E"
+}
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/tests/bug38161.phpt?view=markup&rev=1.1
Index: php-src/ext/oci8/tests/bug38161.phpt
+++ php-src/ext/oci8/tests/bug38161.phpt
--TEST--
bug #38161 (oci_bind_by_name() returns garbage when Oracle didn't set the variable)
--SKIPIF--
<?php if (!extension_loaded("oci8")) print "skip"; ?>
--FILE--
<?php
require dirname(__FILE__).'/connect.inc';
$query = "begin if false then :bv := 1; end if; end;";
$stid = oci_parse($c, $query);
oci_bind_by_name($stid, ":bv", $bv, 22);
oci_execute($stid, OCI_DEFAULT);
var_dump($bv);
unset($bv);
$query = "begin if false then :bv := 1; end if; end;";
$stid = oci_parse($c, $query);
oci_bind_by_name($stid, ":bv", $bv, 22, SQLT_INT);
oci_execute($stid, OCI_DEFAULT);
var_dump($bv);
echo "Done\n";
?>
--EXPECTF--
NULL
int(0)
Done