From 1494f6f9df12efba279f01fba42f783fc0f524fc Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Thu, 11 Jan 2007 11:58:34 +0000 Subject: [PATCH] fix #39988 (type argument of oci_define_by_name() is ignored) patch and tests by Chris Jones --- ext/oci8/oci8_interface.c | 2 +- ext/oci8/oci8_statement.c | 6 +- ext/oci8/tests/coll_019.phpt | 104 +++++++++++++++++++++++++++ ext/oci8/tests/define2.phpt | 106 +++++++++++++++++++++++++++ ext/oci8/tests/define3.phpt | 136 +++++++++++++++++++++++++++++++++++ ext/oci8/tests/define4.phpt | 83 +++++++++++++++++++++ ext/oci8/tests/define5.phpt | 77 ++++++++++++++++++++ 7 files changed, 512 insertions(+), 2 deletions(-) create mode 100644 ext/oci8/tests/coll_019.phpt create mode 100644 ext/oci8/tests/define2.phpt create mode 100644 ext/oci8/tests/define3.phpt create mode 100644 ext/oci8/tests/define4.phpt create mode 100644 ext/oci8/tests/define5.phpt diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 3753b2301d..87017b3e4f 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -53,7 +53,7 @@ PHP_FUNCTION(oci_define_by_name) zstr name; int name_len; zend_uchar name_type; - 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 36b8cb1ca4..f0a6d5e3da 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -519,7 +519,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.s, TEXT_BYTES(outcol->name_len+1), (void **) &outcol->define); + if (zend_hash_find(statement->defines, outcol->name.s, TEXT_BYTES(outcol->name_len + 1),(void **) &outcol->define) == SUCCESS) { + if (outcol->define->type) { + outcol->data_type = outcol->define->type; + } + } } buf = 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..2a6fa9f49d --- /dev/null +++ b/ext/oci8/tests/define2.phpt @@ -0,0 +1,106 @@ +--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 +--UEXPECTF-- +unicode(32) "88b274d7a257ac6f70435b83abd4e26e" +Test 1 +bool(true) +unicode(300) "GIF89%s" +file md5:88b274d7a257ac6f70435b83abd4e26e +Test 2 +bool(true) +unicode(300) "GIF89%s" +file md5:88b274d7a257ac6f70435b83abd4e26e +Test 3 - test repeatability +bool(true) +unicode(1200) "4700490046003800390061007800000043000000E6006A0000007F008200B800390037004700280025002A00CC00CD00E200A100A400CB00D300D500E700B200B400D40043004200580083008600B90082008300B30052005200720090009200C200C200C400DE00AA00AC00D0004C004B0063005B005C008300DD00DE00EC003B0038003C006E007100A5006A006D009D00610063008D0075007900B1007B007E00B500E500E600F00099009C00C6008C008D00C100B900BA00D9006B006B0092004E004E006B0071007400A9007A007A00A30088008B00BD0072007400A3007400730098008E009000C1005A005B007E00E200E300EF007B007D00AD00A400A500D0006D007000A20072007600AC0095009600C800BB00BD00D90074007800AE0085008800BB0092009500C300D800D900EA0092009200C4006400660092006B006E009F00A500A800CE0094009600C5002E002B002F00530051006800B300B400D7006C006A008C005C005B0076008A008D00BF0066006800960068006A009A009C009F00C80031002E003900AE00B000D3009C009C00CD005500560078009E00A100CA0096009900C50081008200AF006700690097003F003D005000BC00BE00DA005E006000890098009900C8008C008E00BF0089008A00BA00570058007C00B600B700D700D500D700E80022001E0020006C006F009E00CE00D000E400BF00C000DC0077007B00B40076007800A7005F005E007D0099009900CC006E006F00980073007700AE0022001E001F00FF00FF00FF0090008E008F00590056005700C700C600C700EE00EE00F500D500D400D500F600F600" +file md5:d60f46611ba231f0052a9ceca1346ff1 +Test 4 - wrong type +bool(true) + +Warning: oci_fetch(): ORA-00932: inconsistent datatypes%s in %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..71225b27bc --- /dev/null +++ b/ext/oci8/tests/define3.phpt @@ -0,0 +1,136 @@ +--TEST-- +Test oci_define_by_name() LOB descriptor +--SKIPIF-- + +--FILE-- +savefile(dirname(__FILE__)."/test.gif"); +$data = $fileimage->load(); +var_dump(md5((binary)$data)); // original md5 +oci_commit($c); + +// New row with different data +$id = 2; +$data = strrev($data); +var_dump(md5((binary)$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 +--UEXPECTF-- +unicode(32) "614fcbba1effb7caa27ef0ef25c27fcf" +unicode(32) "06d4f219d946c74d748d43932cd9dcb2" +Test 1 +bool(true) +object(OCI-Lob)#%d (1) { + [u"descriptor"]=> + resource(%d) of type (oci8 descriptor) +} +file md5:614fcbba1effb7caa27ef0ef25c27fcf +object(OCI-Lob)#%d (1) { + [u"descriptor"]=> + resource(%d) of type (oci8 descriptor) +} +file md5:06d4f219d946c74d748d43932cd9dcb2 +Test 2 +bool(true) + +Warning: oci_fetch(): ORA-00932: inconsistent datatypes%s in %s on line %d +Test 3 +bool(true) + +Warning: md5(): Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received in %s on line %d +file md5: + +Warning: md5(): Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received in %s on line %d +file md5: +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..27d7a0c672 --- /dev/null +++ b/ext/oci8/tests/define4.phpt @@ -0,0 +1,83 @@ +--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 +--UEXPECTF-- +Test 1 +bool(true) +Test 2 +unicode(4) "1234" +unicode(4) "some" +unicode(4) "some" +unicode(4) "some" +unicode(4) "1234" +unicode(4) "some" +Test 3 +bool(true) +unicode(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..d6b1414082 --- /dev/null +++ b/ext/oci8/tests/define5.phpt @@ -0,0 +1,77 @@ +--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 +--UEXPECT-- +bool(true) +bool(true) +Test 1 - must do define before execute +bool(true) +NULL +unicode(4) "some" +Test 2 - normal define order +bool(true) +unicode(4) "some" +Test 3 - no new define done +unicode(4) "some" +unicode(5) "thing" +Done -- 2.50.1