tony2001 Mon Jul 31 10:28:46 2006 UTC Added files: /php-src/ext/oci8 bug37581.phpt
Modified files: /php-src/ext/oci8 oci8.c oci8_statement.c php_oci8_int.h /php-src/ext/oci8/tests array_bind_005.phpt Log: fix #37581 (oci_bind_array_by_name clobbers input array when using SQLT_AFC, AVC)
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/oci8.c?r1=1.307&r2=1.308&diff_format=u Index: php-src/ext/oci8/oci8.c diff -u php-src/ext/oci8/oci8.c:1.307 php-src/ext/oci8/oci8.c:1.308 --- php-src/ext/oci8/oci8.c:1.307 Wed Jul 26 07:00:42 2006 +++ php-src/ext/oci8/oci8.c Mon Jul 31 10:28:46 2006 @@ -26,7 +26,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8.c,v 1.307 2006/07/26 07:00:42 tony2001 Exp $ */ +/* $Id: oci8.c,v 1.308 2006/07/31 10:28:46 tony2001 Exp $ */ /* TODO * * file://localhost/www/docs/oci10/ociaahan.htm#423823 - implement lob_empty() with OCI_ATTR_LOBEMPTY @@ -667,7 +667,7 @@ php_info_print_table_start(); php_info_print_table_row(2, "OCI8 Support", "enabled"); php_info_print_table_row(2, "Version", "1.2.1"); - php_info_print_table_row(2, "Revision", "$Revision: 1.307 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.308 $"); sprintf(buf, "%ld", OCI_G(num_persistent)); php_info_print_table_row(2, "Active Persistent Connections", buf); @@ -775,9 +775,10 @@ if (bind->array.elements) { efree(bind->array.elements); } -/* if (bind->array.element_lengths) { + if (bind->array.element_lengths) { efree(bind->array.element_lengths); } +/* if (bind->array.indicators) { efree(bind->array.indicators); } http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/oci8_statement.c?r1=1.20&r2=1.21&diff_format=u Index: php-src/ext/oci8/oci8_statement.c diff -u php-src/ext/oci8/oci8_statement.c:1.20 php-src/ext/oci8/oci8_statement.c:1.21 --- php-src/ext/oci8/oci8_statement.c:1.20 Sun Jul 30 20:50:53 2006 +++ php-src/ext/oci8/oci8_statement.c Mon Jul 31 10:28:46 2006 @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8_statement.c,v 1.20 2006/07/30 20:50:53 tony2001 Exp $ */ +/* $Id: oci8_statement.c,v 1.21 2006/07/31 10:28:46 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H @@ -664,6 +664,8 @@ zval **entry; HashTable *hash = HASH_OF(bind->zval); + zend_hash_internal_pointer_reset(hash); + switch (bind->array.type) { case SQLT_NUM: case SQLT_INT: @@ -731,7 +733,8 @@ case SQLT_STR: case SQLT_LVC: for (i = 0; i < bind->array.current_length; i++) { - int curr_element_length = strlen(((text *)bind->array.elements)+i*bind->array.max_length); + /* int curr_element_length = strlen(((text *)bind->array.elements)+i*bind->array.max_length); */ + int curr_element_length = bind->array.element_lengths[i]; if ((i < bind->array.old_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { zval_dtor(*entry); ZVAL_STRINGL(*entry, ((text *)bind->array.elements)+i*bind->array.max_length, curr_element_length, 1); @@ -1174,7 +1177,7 @@ (sb4) bind->array.max_length, type, (dvoid *)0, /* bindp->array.indicators, */ - (ub2 *)0, /* bindp->array.element_lengths, */ + (ub2 *)bind->array.element_lengths, (ub2 *)0, /* bindp->array.retcodes, */ (ub4) max_table_length, (ub4 *) &(bindp->array.current_length), @@ -1220,6 +1223,19 @@ bind->array.current_length = zend_hash_num_elements(Z_ARRVAL_P(var)); bind->array.old_length = bind->array.current_length; bind->array.max_length = maxlength; + bind->array.element_lengths = ecalloc(1, max_table_length * sizeof(ub2)); + + zend_hash_internal_pointer_reset(hash); + + for (i = 0; i < bind->array.current_length; i++) { + if (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE) { + convert_to_string_ex(entry); + bind->array.element_lengths[i] = Z_STRLEN_PP(entry); + zend_hash_move_forward(hash); + } else { + break; + } + } zend_hash_internal_pointer_reset(hash); for (i = 0; i < max_table_length; i++) { @@ -1259,9 +1275,13 @@ bind->array.current_length = zend_hash_num_elements(Z_ARRVAL_P(var)); bind->array.old_length = bind->array.current_length; bind->array.max_length = sizeof(ub4); + bind->array.element_lengths = ecalloc(1, max_table_length * sizeof(ub2)); zend_hash_internal_pointer_reset(hash); for (i = 0; i < max_table_length; i++) { + if (i < bind->array.current_length) { + bind->array.element_lengths[i] = sizeof(ub4); + } if ((i < bind->array.current_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { convert_to_long_ex(entry); ((ub4 *)bind->array.elements)[i] = (ub4) Z_LVAL_PP(entry); @@ -1292,9 +1312,13 @@ bind->array.current_length = zend_hash_num_elements(Z_ARRVAL_P(var)); bind->array.old_length = bind->array.current_length; bind->array.max_length = sizeof(double); + bind->array.element_lengths = ecalloc(1, max_table_length * sizeof(ub2)); zend_hash_internal_pointer_reset(hash); for (i = 0; i < max_table_length; i++) { + if (i < bind->array.current_length) { + bind->array.element_lengths[i] = sizeof(double); + } if ((i < bind->array.current_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { convert_to_double_ex(entry); ((double *)bind->array.elements)[i] = (double) Z_DVAL_PP(entry); @@ -1325,10 +1349,14 @@ bind->array.current_length = zend_hash_num_elements(Z_ARRVAL_P(var)); bind->array.old_length = bind->array.current_length; bind->array.max_length = sizeof(OCIDate); + bind->array.element_lengths = ecalloc(1, max_table_length * sizeof(ub2)); zend_hash_internal_pointer_reset(hash); for (i = 0; i < max_table_length; i++) { OCIDate oci_date; + if (i < bind->array.current_length) { + bind->array.element_lengths[i] = sizeof(OCIDate); + } if ((i < bind->array.current_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { convert_to_string_ex(entry); http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/php_oci8_int.h?r1=1.17&r2=1.18&diff_format=u Index: php-src/ext/oci8/php_oci8_int.h diff -u php-src/ext/oci8/php_oci8_int.h:1.17 php-src/ext/oci8/php_oci8_int.h:1.18 --- php-src/ext/oci8/php_oci8_int.h:1.17 Sun Jul 30 20:50:53 2006 +++ php-src/ext/oci8/php_oci8_int.h Mon Jul 31 10:28:46 2006 @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_oci8_int.h,v 1.17 2006/07/30 20:50:53 tony2001 Exp $ */ +/* $Id: php_oci8_int.h,v 1.18 2006/07/31 10:28:46 tony2001 Exp $ */ #if HAVE_OCI8 # ifndef PHP_OCI8_INT_H @@ -178,9 +178,9 @@ php_oci_statement *parent_statement; /* pointer to the parent statement */ struct { void *elements; -/* ub2 *indicators; +/* ub2 *indicators; */ ub2 *element_lengths; - ub2 *retcodes; */ +/* ub2 *retcodes; */ long current_length; long old_length; long max_length; http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/tests/array_bind_005.phpt?r1=1.2&r2=1.3&diff_format=u Index: php-src/ext/oci8/tests/array_bind_005.phpt diff -u php-src/ext/oci8/tests/array_bind_005.phpt:1.2 php-src/ext/oci8/tests/array_bind_005.phpt:1.3 --- php-src/ext/oci8/tests/array_bind_005.phpt:1.2 Thu Dec 8 22:31:55 2005 +++ php-src/ext/oci8/tests/array_bind_005.phpt Mon Jul 31 10:28:46 2006 @@ -58,7 +58,8 @@ echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- +Warning: oci_execute(): ORA-01405: fetched column value is NULL in %s on line %d array(5) { [0]=> string(0) "" http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/bug37581.phpt?view=markup&rev=1.1 Index: php-src/ext/oci8/bug37581.phpt +++ php-src/ext/oci8/bug37581.phpt --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
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php