]> granicus.if.org Git - php/commitdiff
fix #39988 (type argument of oci_define_by_name() is ignored)
authorAntony Dovgal <tony2001@php.net>
Thu, 11 Jan 2007 11:58:34 +0000 (11:58 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 11 Jan 2007 11:58:34 +0000 (11:58 +0000)
patch and tests by Chris Jones

ext/oci8/oci8_interface.c
ext/oci8/oci8_statement.c
ext/oci8/tests/coll_019.phpt [new file with mode: 0644]
ext/oci8/tests/define2.phpt [new file with mode: 0644]
ext/oci8/tests/define3.phpt [new file with mode: 0644]
ext/oci8/tests/define4.phpt [new file with mode: 0644]
ext/oci8/tests/define5.phpt [new file with mode: 0644]

index 3753b2301d421ce6269db4775e723c6cd3111871..87017b3e4f7f30c5d6f013e42e386654f81c98e8 100644 (file)
@@ -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;
 
index 36b8cb1ca45cd2958e791842bc61eab5f06a0d00..f0a6d5e3da34bb00eb5358a4bf8bae9d28a962b8 100644 (file)
@@ -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 (file)
index 0000000..15a673d
--- /dev/null
@@ -0,0 +1,104 @@
+--TEST--
+Test collection Oracle error handling collections and numbers (2)
+--SKIPIF--
+<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
+--FILE--
+<?php
+
+require dirname(__FILE__)."/connect.inc";
+
+$ora_sql = "DROP TYPE ".$type_name;;
+$statement = oci_parse($c,$ora_sql);
+@oci_execute($statement);
+
+
+echo "Test 0\n";
+$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF BLOB";
+$statement = oci_parse($c,$ora_sql);
+oci_execute($statement);
+
+$coll1 = oci_new_collection($c, $type_name);
+
+var_dump($coll1->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 (file)
index 0000000..2a6fa9f
--- /dev/null
@@ -0,0 +1,106 @@
+--TEST--
+Test oci_define_by_name types
+--SKIPIF--
+<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
+--FILE--
+<?php
+
+require dirname(__FILE__)."/connect.inc";
+
+$stmt = oci_parse($c, "create table phptestrawtable( id number(10), fileimage raw(1000))");
+oci_execute($stmt);
+
+$stmt = oci_parse ($c, "insert into phptestrawtable (id, fileimage) values (:id, :fileimage)");
+$i=1;
+$fileimage = file_get_contents( dirname(__FILE__)."/test.gif");
+$fileimage = substr($fileimage, 0, 300);
+var_dump(md5($fileimage));
+
+oci_bind_by_name( $stmt, ":id", $i, -1);
+oci_bind_by_name( $stmt, ":fileimage", $fileimage, -1, SQLT_BIN);
+oci_execute($stmt, OCI_DEFAULT);
+oci_commit($c);
+
+echo "Test 1\n";
+$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
+var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
+oci_execute($stmt);
+
+while (oci_fetch($stmt)) {
+       var_dump($fi);
+       echo "file md5:" . md5((binary)$fi) . "\n";
+}
+
+echo "Test 2\n";
+$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
+var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
+oci_execute($stmt);
+
+while (oci_fetch($stmt)) {
+       var_dump($fi);
+       echo "file md5:" . md5((binary)$fi) . "\n";
+}
+
+echo "Test 3 - test repeatability\n";
+$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
+var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_STR));
+oci_execute($stmt);
+
+while (oci_fetch($stmt)) {
+       var_dump($fi);
+       echo "file md5:" . md5((binary)$fi) . "\n";
+}
+
+echo "Test 4 - wrong type\n";
+$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
+var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_RSET));
+oci_execute($stmt);
+
+while (oci_fetch($stmt)) {
+       var_dump($fi);
+       echo "file md5:" . md5((binary)$fi) . "\n";
+}
+
+$stmt = oci_parse($c, "drop table phptestrawtable");
+oci_execute($stmt);
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..71225b2
--- /dev/null
@@ -0,0 +1,136 @@
+--TEST--
+Test oci_define_by_name() LOB descriptor
+--SKIPIF--
+<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
+--FILE--
+<?php
+
+require dirname(__FILE__)."/connect.inc";
+
+$stmt = oci_parse($c, "create table phpdefblobtable( id number(10), fileimage blob)");
+oci_execute($stmt);
+
+// Load data
+$stmt = oci_parse ($c, "insert into phpdefblobtable (id, fileimage) values (:id, empty_blob()) returning fileimage into :fileimage");
+$fileimage = oci_new_descriptor($c,OCI_D_LOB);
+oci_bind_by_name($stmt,":id",$id);
+oci_bind_by_name($stmt,":fileimage",$fileimage,-1,OCI_B_BLOB);
+$id = 1;
+oci_execute($stmt, OCI_DEFAULT);
+$fileimage->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 (file)
index 0000000..27d7a0c
--- /dev/null
@@ -0,0 +1,83 @@
+--TEST--
+oci_define_by_name() on partial number of columns
+--SKIPIF--
+<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
+--FILE--
+<?php
+
+require dirname(__FILE__)."/connect.inc";
+require dirname(__FILE__)."/create_table.inc";
+
+$insert_sql = "INSERT INTO ".$schema.$table_name." (value, string) VALUES (1234, 'some')";
+
+if (!($s = oci_parse($c, $insert_sql))) {
+        die("oci_parse(insert) failed!\n");
+}
+
+if (!oci_execute($s)) {
+        die("oci_execute(insert) failed!\n");
+}
+
+$stmt = oci_parse($c, "SELECT value, string FROM ".$table_name."");
+
+echo "Test 1\n";
+// Only one of the two columns is defined
+var_dump(oci_define_by_name($stmt, "STRING", $string));
+
+oci_execute($stmt);
+
+echo "Test 2\n";
+
+while (oci_fetch($stmt)) {
+       var_dump(oci_result($stmt, 'VALUE'));
+       var_dump($string);
+       var_dump(oci_result($stmt, 'STRING'));
+       var_dump($string);
+       var_dump(oci_result($stmt, 'VALUE'));
+       var_dump(oci_result($stmt, 'STRING'));
+}
+
+echo "Test 3\n";
+var_dump(oci_free_statement($stmt));
+var_dump($string);
+var_dump(oci_result($stmt, 'STRING'));
+
+require dirname(__FILE__)."/drop_table.inc";
+
+echo "Done\n";
+
+?>
+--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 (file)
index 0000000..d6b1414
--- /dev/null
@@ -0,0 +1,77 @@
+--TEST--
+oci_define_by_name() for statement re-execution
+--SKIPIF--
+<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
+--FILE--
+<?php
+
+require dirname(__FILE__)."/connect.inc";
+require dirname(__FILE__)."/create_table.inc";
+
+$insert_sql = "INSERT INTO ".$schema.$table_name." (id, string) VALUES (1, 'some')";
+$s = oci_parse($c, $insert_sql);
+var_dump(oci_execute($s));
+
+$insert_sql = "INSERT INTO ".$schema.$table_name." (id, string) VALUES (2, 'thing')";
+$s = oci_parse($c, $insert_sql);
+var_dump(oci_execute($s));
+
+echo "Test 1 - must do define before execute\n";
+$stmt = oci_parse($c, "SELECT string FROM ".$table_name." where id = 1");
+oci_execute($stmt);
+var_dump(oci_define_by_name($stmt, "STRING", $string));
+while (oci_fetch($stmt)) {
+       var_dump($string);  // gives NULL
+       var_dump(oci_result($stmt, 'STRING'));
+}
+
+echo "Test 2 - normal define order\n";
+$stmt = oci_parse($c, "SELECT string FROM ".$table_name." where id = 1");
+var_dump(oci_define_by_name($stmt, "STRING", $string));
+oci_execute($stmt);
+
+while (oci_fetch($stmt)) {
+       var_dump($string);
+}
+
+echo "Test 3 - no new define done\n";
+$stmt = oci_parse($c, "SELECT string FROM ".$table_name." where id = 2");
+oci_execute($stmt);
+while (oci_fetch($stmt)) {
+       var_dump($string); // not updated with new value
+       var_dump(oci_result($stmt, 'STRING'));
+}
+
+require dirname(__FILE__)."/drop_table.inc";
+
+echo "Done\n";
+
+?>
+--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