From: Antony Dovgal Date: Thu, 11 Jan 2007 12:01:08 +0000 (+0000) Subject: MFH: fix #39988 (type argument of oci_define_by_name() is ignored) X-Git-Tag: php-5.2.1RC3~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f361d9e4f05f935b563824121f389a7356e5b1ec;p=php MFH: fix #39988 (type argument of oci_define_by_name() is ignored) patch and tests by Chris Jones --- diff --git a/NEWS b/NEWS index 43be0c945d..5c37fde9cc 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ PHP NEWS ARRAY_AS_PROPS). (Ilia) - Fixed bug #40002 (Try/Catch performs poorly). (Dmitry) - Fixed bug #39990 (Cannot "foreach" over overloaded properties). (Dmitry) +- Fixed bug #39988 (type argument of oci_define_by_name() is ignored). + (Chris Jones, Tony) - Fixed bug #39979 (PGSQL_CONNECT_FORCE_NEW will causes next connect to establish a new connection). (Ilia) - Fixed bug #39504 (xmlwriter_write_dtd_entity() creates Attlist tag, diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 2d2adaea09..a4416b3b29 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -52,7 +52,7 @@ PHP_FUNCTION(oci_define_by_name) zval *stmt, *var; char *name; int name_len; - long type = SQLT_CHR; + long type = 0; php_oci_statement *statement; php_oci_define *define, *tmp_define; diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index e043cc9717..8dbd6af45b 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -506,7 +506,11 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC) /* find a user-setted define */ if (statement->defines) { - zend_hash_find(statement->defines,outcol->name,outcol->name_len,(void **) &outcol->define); + if (zend_hash_find(statement->defines,outcol->name,outcol->name_len,(void **) &outcol->define) == SUCCESS) { + if (outcol->define->type) { + outcol->data_type = outcol->define->type; + } + } } buf = 0; diff --git a/ext/oci8/tests/array_bind_005.phpt b/ext/oci8/tests/array_bind_005.phpt index 15278532ea..58dadc20ca 100644 --- a/ext/oci8/tests/array_bind_005.phpt +++ b/ext/oci8/tests/array_bind_005.phpt @@ -59,7 +59,6 @@ var_dump($array); echo "Done\n"; ?> --EXPECTF-- -Warning: oci_execute(): ORA-01405: fetched column value is NULL in %s on line %d array(5) { [0]=> string(0) "" diff --git a/ext/oci8/tests/coll_019.phpt b/ext/oci8/tests/coll_019.phpt new file mode 100644 index 0000000000..15a673d718 --- /dev/null +++ b/ext/oci8/tests/coll_019.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test collection Oracle error handling collections and numbers (2) +--SKIPIF-- + +--FILE-- +append('a long string')); // invalid type for append +var_dump($coll1->assignElem(1, 'a long string')); // invalid type for assignelem() +var_dump($coll1->getElem(0)); + +require dirname(__FILE__)."/drop_type.inc"; + +echo "Test 1\n"; +$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF NUMBER"; +$statement = oci_parse($c,$ora_sql); +oci_execute($statement); + +$coll1 = oci_new_collection($c, $type_name); + +var_dump($coll1->assignElem(1, null)); // invalid location for null +var_dump($coll1->getElem(0)); + +echo "Test 2\n"; +var_dump($coll1->assignElem(1, 1234)); // invalid location for number +var_dump($coll1->getElem(0)); + +require dirname(__FILE__)."/drop_type.inc"; + +echo "Test 3\n"; +$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF VARCHAR2(1)"; +$statement = oci_parse($c,$ora_sql); +oci_execute($statement); + +$coll1 = oci_new_collection($c, $type_name); + +var_dump($coll1->assignElem(1, 'abc')); // invalid location for string +var_dump($coll1->getElem(0)); + +require dirname(__FILE__)."/drop_type.inc"; + +echo "Test 4\n"; +$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF DATE"; +$statement = oci_parse($c,$ora_sql); +oci_execute($statement); + +$coll1 = oci_new_collection($c, $type_name); + +var_dump($coll1->append(1)); // invalid date format +var_dump($coll1->assignElem(1, '01-JAN-06')); // invalid location for date +var_dump($coll1->getElem(0)); + +require dirname(__FILE__)."/drop_type.inc"; + +echo "Done\n"; + +?> +--EXPECTF-- +Test 0 + +Notice: OCI-Collection::append(): Unknown or unsupported type of element: 113 in %s on line %d +bool(false) + +Notice: OCI-Collection::assignelem(): Unknown or unsupported type of element: 113 in %s on line %d +bool(false) +bool(false) +Test 1 + +Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d +bool(false) +bool(false) +Test 2 + +Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d +bool(false) +bool(false) +Test 3 + +Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d +bool(false) +bool(false) +Test 4 + +Warning: OCI-Collection::append(): OCI-01840: input value not long enough for date format in %s on line %d +bool(false) + +Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d +bool(false) +bool(false) +Done diff --git a/ext/oci8/tests/define2.phpt b/ext/oci8/tests/define2.phpt new file mode 100644 index 0000000000..e8c5f8a99a --- /dev/null +++ b/ext/oci8/tests/define2.phpt @@ -0,0 +1,87 @@ +--TEST-- +Test oci_define_by_name types +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(32) "88b274d7a257ac6f70435b83abd4e26e" +Test 1 +bool(true) +string(300) "GIF89%s" +file md5:88b274d7a257ac6f70435b83abd4e26e +Test 2 +bool(true) +string(300) "GIF89%s" +file md5:88b274d7a257ac6f70435b83abd4e26e +Test 3 - test repeatability +bool(true) +string(600) "47494638396178004300E66A007F82B839374728252ACCCDE2A1A4CBD3D5E7B2B4D44342588386B98283B35252729092C2C2C4DEAAACD04C4B635B5C83DDDEEC3B383C6E71A56A6D9D61638D7579B17B7EB5E5E6F0999CC68C8DC1B9BAD96B6B924E4E6B7174A97A7AA3888BBD7274A37473988E90C15A5B7EE2E3EF7B7DADA4A5D06D70A27276AC9596C8BBBDD97478AE8588BB9295C3D8D9EA9292C46466926B6E9FA5A8CE9496C52E2B2F535168B3B4D76C6A8C5C5B768A8DBF666896686A9A9C9FC8312E39AEB0D39C9CCD5556789EA1CA9699C58182AF6769973F3D50BCBEDA5E60899899C88C8EBF898ABA57587CB6B7D7D5D7E8221E206C6F9ECED0E4BFC0DC777BB47678A75F5E7D9999CC6E6F987377AE221E1FFFFFFF908E8F595657C7C6C7EEEEF5D5D4D5F6F6" +file md5:80bb3201e2a8bdcb8ab3e1a44a82bb8a +Test 4 - wrong type +bool(true) + +Warning: oci_fetch(): ORA-00932: inconsistent datatypes%s on line %d +Done diff --git a/ext/oci8/tests/define3.phpt b/ext/oci8/tests/define3.phpt new file mode 100644 index 0000000000..d30db637cd --- /dev/null +++ b/ext/oci8/tests/define3.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test oci_define_by_name() LOB descriptor +--SKIPIF-- + +--FILE-- +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 + diff --git a/ext/oci8/tests/define4.phpt b/ext/oci8/tests/define4.phpt new file mode 100644 index 0000000000..6fd9f5b93f --- /dev/null +++ b/ext/oci8/tests/define4.phpt @@ -0,0 +1,67 @@ +--TEST-- +oci_define_by_name() on partial number of columns +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Test 1 +bool(true) +Test 2 +string(4) "1234" +string(4) "some" +string(4) "some" +string(4) "some" +string(4) "1234" +string(4) "some" +Test 3 +bool(true) +string(4) "some" + +Warning: oci_result(): %d is not a valid oci8 statement resource in %s on line %d +bool(false) +Done + diff --git a/ext/oci8/tests/define5.phpt b/ext/oci8/tests/define5.phpt new file mode 100644 index 0000000000..c439b1d648 --- /dev/null +++ b/ext/oci8/tests/define5.phpt @@ -0,0 +1,64 @@ +--TEST-- +oci_define_by_name() for statement re-execution +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +Test 1 - must do define before execute +bool(true) +NULL +string(4) "some" +Test 2 - normal define order +bool(true) +string(4) "some" +Test 3 - no new define done +string(4) "some" +string(5) "thing" +Done +