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

NEWS
ext/oci8/oci8_interface.c
ext/oci8/oci8_statement.c
ext/oci8/tests/array_bind_005.phpt
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]

diff --git a/NEWS b/NEWS
index 43be0c945d82df1c8fad9ea14cff628e59ef4159..5c37fde9ccdf23342a46b4dcaf970e3a4ae75912 100644 (file)
--- 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,
index 2d2adaea09bb0000cc10a4ee2ade8123f512c20a..a4416b3b295b43067ae2061d14d607db578931ad 100644 (file)
@@ -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;
 
index e043cc9717e24f2b3477884d97fcfd9ae3c15909..8dbd6af45b1ddfc1918fbd88b58774b8740e87f4 100644 (file)
@@ -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;
index 15278532eac41c5a253c043b8e083fcb78ed15ea..58dadc20ca690f8ad1030a5f7fe84fa9943ddbc4 100644 (file)
@@ -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 (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..e8c5f8a
--- /dev/null
@@ -0,0 +1,87 @@
+--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($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($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($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($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
diff --git a/ext/oci8/tests/define3.phpt b/ext/oci8/tests/define3.phpt
new file mode 100644 (file)
index 0000000..d30db63
--- /dev/null
@@ -0,0 +1,105 @@
+--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($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 (file)
index 0000000..6fd9f5b
--- /dev/null
@@ -0,0 +1,67 @@
+--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
+
diff --git a/ext/oci8/tests/define5.phpt b/ext/oci8/tests/define5.phpt
new file mode 100644 (file)
index 0000000..c439b1d
--- /dev/null
@@ -0,0 +1,64 @@
+--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
+