]> granicus.if.org Git - php/commitdiff
Improve row fetch changes for PHP7. Update test SKIPIFs. Add test for 11g client...
authorChristopher Jones <christopher.jones@oracle.com>
Tue, 15 Sep 2015 00:06:29 +0000 (10:06 +1000)
committerChristopher Jones <christopher.jones@oracle.com>
Tue, 15 Sep 2015 00:06:29 +0000 (10:06 +1000)
ext/oci8/oci8.c
ext/oci8/tests/bind_sqltnum_11g.phpt [new file with mode: 0644]
ext/oci8/tests/drcp_cclass1.phpt
ext/oci8/tests/drcp_privileged.phpt
ext/oci8/tests/driver_name.phpt

index 01b2414a9e34b84508020ece60da3e2d2ab98d35..eed4a1c8f88b363b5b382662508280cecd34e969 100644 (file)
@@ -2634,7 +2634,7 @@ int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode)
 void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_args)
 {
        zval *z_statement, *array;
-       zval *placeholder;
+       zval *placeholder = (zval*) NULL;
 /*     zend_array *temp_array = (zend_array *) NULL;*/
        php_oci_statement *statement;             /* statement that will be fetched from */
 #if (OCI_MAJOR_VERSION >= 12)
@@ -2655,6 +2655,12 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg
                if (ZEND_NUM_ARGS() == 2) {
                        fetch_mode = mode;
                }
+
+               if (Z_ISREF_P(array))
+                       placeholder = Z_REFVAL_P(array);
+               else
+                       placeholder = array;
+
        } else if (expected_args == 2) {
                /* only for oci_fetch_array() */
 
@@ -2743,14 +2749,10 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg
     }
 #endif /* OCI_MAJOR_VERSION */
 
-       if (expected_args > 2) {
-               if (Z_ISREF_P(array))
-                       placeholder = Z_REFVAL_P(array);
-               else
-                       placeholder = array;
-               zval_dtor(placeholder);
-       } else {
+       if (placeholder == NULL) {
                placeholder = return_value;
+       } else {
+               zval_dtor(placeholder);
        }
 
        array_init(placeholder);
@@ -2792,20 +2794,6 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg
        }
 
        if (expected_args > 2) {
-               /* Only for ocifetchinto BC.  In all other cases we return array, not long */
-#if 0          
-               zval *temp_array;
-               if (Z_ISREF_P(array))
-                       temp_array = Z_REFVAL_P(array);
-               else /* PHP7 will pass user buffer through 'array' as reference type.
-                         * So this part of code may not be reached. */
-                       temp_array = array; 
-
-               /* copy array content in return_value into user buffer passed through
-                * reference variable 'array' */
-               ZVAL_ARR(temp_array, Z_ARRVAL_P(return_value));
-               zval_ptr_dtor(return_value);
-#endif
                RETURN_LONG(statement->ncolumns);
        }
 }
diff --git a/ext/oci8/tests/bind_sqltnum_11g.phpt b/ext/oci8/tests/bind_sqltnum_11g.phpt
new file mode 100644 (file)
index 0000000..1969893
--- /dev/null
@@ -0,0 +1,279 @@
+--TEST--
+Bind with SQLT_NUM
+--SKIPIF--
+<?php
+if (!extension_loaded('oci8')) die("skip no oci8 extension");
+preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
+if (!(isset($matches[0]) && $matches[0] <= 11)) { 
+    die("skip works only with Oracle 11 or earlier version of Oracle client libraries");
+}
+?>
+--FILE--
+<?php
+
+require(dirname(__FILE__).'/connect.inc');
+
+// Initialization
+
+$stmtarray = array(
+       "drop table bind_sqltnum_tab",
+
+    "create table bind_sqltnum_tab (
+        id                number,
+        varchar2_t10      varchar2(10),
+        number_t          number,
+        number_t92        number(9,2))"
+);
+
+oci8_test_sql_execute($c, $stmtarray);
+
+function check_col($c, $colname, $id)
+{
+    $s = oci_parse($c, "select $colname from bind_sqltnum_tab where id = :id");
+    oci_bind_by_name($s, ":id", $id);
+    oci_execute($s);
+    oci_fetch_all($s, $r);
+    var_dump($r);
+}
+
+
+// Run Test
+
+echo "Test 1 - baseline test\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (100, :c2)");
+$c2 = "Hood";
+$r = oci_bind_by_name($s, ":c2", $c2, -1);
+if (!$r) {
+    $e = oci_error($s);
+    var_dump($e);
+}
+$r = oci_execute($s, OCI_DEFAULT);
+if (!$r) {
+    $e = oci_error($s);
+    var_dump($e);
+}
+
+$s = oci_parse($c, "select id, varchar2_t10 from bind_sqltnum_tab");
+oci_execute($s);
+oci_fetch_all($s, $data);
+var_dump($data);
+
+echo "Test 2 - SQLT_NUM to a VARCHAR2 column\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (100, :c2)");
+$c2 = "Hood";
+$r = oci_bind_by_name($s, ":c2", $c2, -1, SQLT_NUM);
+if (!$r) {
+    $e = oci_error($s);
+    var_dump($e['message']);
+}
+$r = oci_execute($s, OCI_DEFAULT);
+if (!$r) {
+    $e = oci_error($s);
+    var_dump($e['message']);
+}
+
+echo "\nTEST41 wrong bind type SQLT_NUM\n";
+
+$c2 = "Hood41";
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (41, :c2)");
+oci_bind_by_name($s, ":c2", $c2, -1, SQLT_NUM);
+oci_execute($s);
+
+echo "\nTEST42 insert numbers SQLT_NUM\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (42, :n1)");
+$n1 = 42;
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t', 42);
+
+echo "\nTEST43 insert numbers SQLT_NUM\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (43, :n1)");
+$n1 = 42.69;
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t', 43);
+
+echo "\nTEST44\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (44, :n1)");
+$n1 = 0;
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t', 44);
+
+echo "\nTEST45\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (45, :n1)");
+$n1 = -23;
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t', 45);
+
+echo "\nTEST46 insert numbers\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (46, :n1)");
+$n1 = "-23";
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t', 46);
+
+echo "\nTEST47\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (47, :n1)");
+$n1 = "23";
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t', 47);
+
+echo "\nTEST48\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (48, :n1)");
+$n1 = 123.56;
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t92', 48);
+
+echo "\nTEST49\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (49, :n1)");
+$n1 = "123.56";
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t92', 49);
+
+echo "\nTEST50\n";
+
+$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (50, :n1)");
+$n1 = "";
+oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
+oci_execute($s);
+
+check_col($c, 'number_t92', 50);
+
+// Clean up
+
+$stmtarray = array(
+       "drop table bind_sqltnum_tab"
+);
+
+oci8_test_sql_execute($c, $stmtarray);
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+Test 1 - baseline test
+array(2) {
+  ["ID"]=>
+  array(1) {
+    [0]=>
+    string(3) "100"
+  }
+  ["VARCHAR2_T10"]=>
+  array(1) {
+    [0]=>
+    string(4) "Hood"
+  }
+}
+Test 2 - SQLT_NUM to a VARCHAR2 column
+
+Warning: oci_execute(): ORA-12899: %s (%s: 40, %s: 10) in %sbind_sqltnum_11g.php on line %d
+string(%d) "ORA-12899: %s"
+
+TEST41 wrong bind type SQLT_NUM
+
+Warning: oci_execute(): ORA-12899: %s "%s"."BIND_SQLTNUM_TAB"."VARCHAR2_T10" (%s: 40, %s: 10) in %sbind_sqltnum_11g.php on line %d
+
+TEST42 insert numbers SQLT_NUM
+array(1) {
+  ["NUMBER_T"]=>
+  array(1) {
+    [0]=>
+    NULL
+  }
+}
+
+TEST43 insert numbers SQLT_NUM
+array(1) {
+  ["NUMBER_T"]=>
+  array(1) {
+    [0]=>
+    NULL
+  }
+}
+
+TEST44
+array(1) {
+  ["NUMBER_T"]=>
+  array(1) {
+    [0]=>
+    string(127) "-000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
+  }
+}
+
+TEST45
+array(1) {
+  ["NUMBER_T"]=>
+  array(1) {
+    [0]=>
+    NULL
+  }
+}
+
+TEST46 insert numbers
+array(1) {
+  ["NUMBER_T"]=>
+  array(1) {
+    [0]=>
+    NULL
+  }
+}
+
+TEST47
+array(1) {
+  ["NUMBER_T"]=>
+  array(1) {
+    [0]=>
+    NULL
+  }
+}
+
+TEST48
+array(1) {
+  ["NUMBER_T92"]=>
+  array(1) {
+    [0]=>
+    string(1) "0"
+  }
+}
+
+TEST49
+array(1) {
+  ["NUMBER_T92"]=>
+  array(1) {
+    [0]=>
+    string(1) "0"
+  }
+}
+
+TEST50
+
+Warning: oci_execute(): ORA-01438: %s in %sbind_sqltnum_11g.php on line %d
+array(1) {
+  ["NUMBER_T92"]=>
+  array(0) {
+  }
+}
+===DONE===
index 5c78a2943e94ec3bcf1ecf9bef9e0708dd5dc884..0a929317bb2608f30f9a55f5724d2bd7778ababe 100644 (file)
@@ -5,6 +5,9 @@ DRCP: Test setting connection class inline
 if (!extension_loaded('oci8')) die ("skip no oci8 extension"); 
 require(dirname(__FILE__).'/connect.inc');
 if (!$test_drcp) die("skip testing DRCP connection class only works in DRCP mode");
+// Looked for :pooled in EZ connect string
+if (strpos($dbase, "/") !== false && stripos($dbase, ":pooled") === false)
+    die('skip DRCP test requires a DRCP pooled server connection');
 if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user"); 
 
 preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches_sv);
index 3871341bc50cc938774a8cf4e3d30699ee1770a4..c57216672f46bc2879bbeb591b58ab4fd28b2eba 100644 (file)
@@ -5,6 +5,9 @@ DRCP: privileged connect
 if (!extension_loaded('oci8')) die("skip no oci8 extension");
 require(dirname(__FILE__)."/connect.inc");
 if (!$test_drcp) die("skip requires DRCP connection");
+// Looked for :pooled in EZ connect string
+if (strpos($dbase, "/") !== false && stripos($dbase, ":pooled") === false)
+    die('skip DRCP test requires a DRCP pooled server connection');
 if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
 ob_start();
 phpinfo(INFO_MODULES);
index ffef0328d940b796b35f572aab55514942cce477..758e3979a760cf9f52621058f35387ec1259c563 100644 (file)
@@ -8,8 +8,9 @@ if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to
 if ($test_drcp) die("skip as Output might vary with DRCP");
 
 preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
-if (!(isset($matches[0]) && ($matches[1] == 12 && $matches[2] == 1 && $matches[3] >= 0
-       && $matches[4] >= 2) || ($matches[1] == 12 && $matches[2] > 1)))
+if (!(isset($matches[0]) &&
+     ($matches[1] == 12 && $matches[2] == 1 && $matches[3] >= 0
+     && $matches[4] >= 2) || ($matches[1] == 12 && $matches[2] > 1))) {
     die("skip test expected to work only with Oracle 12.1.0.2 database or its later patchsets");
 }