]> granicus.if.org Git - php/commitdiff
Promote some warnings to ValueError in OCI8
authorGeorge Peter Banyard <girgias@php.net>
Sat, 12 Sep 2020 15:38:02 +0000 (17:38 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Tue, 15 Sep 2020 00:54:12 +0000 (02:54 +0200)
Closes GH-6116

Co-authored-by: Christopher Jones <sixd@php.net>
13 files changed:
ext/oci8/oci8.stub.php
ext/oci8/oci8_arginfo.h
ext/oci8/oci8_interface.c
ext/oci8/tests/array_bind_002.phpt
ext/oci8/tests/define1.phpt
ext/oci8/tests/lob_003.phpt
ext/oci8/tests/lob_020.phpt
ext/oci8/tests/lob_022.phpt
ext/oci8/tests/lob_027.phpt
ext/oci8/tests/lob_035.phpt
ext/oci8/tests/lob_042.phpt
ext/oci8/tests/null_byte_1.phpt
ext/oci8/tests/refcur_prefetch_1.phpt

index 8e8537274a58ad6ff8e3462d843499f012677b12..917225f562655fad96a2e3796b77e56cdd1288cb 100644 (file)
@@ -87,13 +87,13 @@ function oci_lob_copy(OCILob $lob_descriptor_to, OCILob $lob_descriptor_from, ?i
 
 function oci_lob_is_equal(OCILob $lob_descriptor_first, OCILob $lob_descriptor_second): bool {}
 
-function oci_lob_export(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {}
+function oci_lob_export(OCILob $lob_descriptor, string $filename, ?int $start = null, ?int $length = null): bool {}
 
 /**
  * @alias oci_lob_export
  * @deprecated
  */
-function ociwritelobtofile(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {}
+function ociwritelobtofile(OCILob $lob_descriptor, string $filename, ?int $start = null, ?int $length = null): bool {}
 
 /**
  * @param resource $connection_resource
@@ -412,14 +412,14 @@ function oci_get_implicit_resultset($statement_resource) {}
 /**
  * @param resource $statement_resource
  */
-function oci_set_prefetch($statement_resource, int $number_of_rows): ?bool {}
+function oci_set_prefetch($statement_resource, int $number_of_rows): bool {}
 
 /**
  * @param resource $statement_resource
  * @alias oci_set_prefetch
  * @deprecated
  */
-function ocisetprefetch($statement_resource, int $number_of_rows): ?bool {}
+function ocisetprefetch($statement_resource, int $number_of_rows): bool {}
 
 /**
  * @param resource $connection_resource
@@ -718,13 +718,13 @@ class OCILob {
      * @alias oci_lob_export
      * @return bool
      */
-    public function writetofile(string $path, ?int $start = null, ?int $length = null) {}
+    public function writetofile(string $filename, ?int $start = null, ?int $length = null) {}
 
     /**
      * @alias oci_lob_export
      * @return bool
      */
-    public function export(string $path, ?int $start = null, ?int $length = null) {}
+    public function export(string $filename, ?int $start = null, ?int $length = null) {}
 
     /**
      * @alias oci_lob_write_temporary
index 32852789996dc969f67128c22b6e59399b1eeabd..0bcc18f06a1fc589717f89212183f645ea3d9d30 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 2d553815c21edd58bc29b1ca8d294d5750fd7312 */
+ * Stub hash: 6cdc7c967ce80c39eaef1c860ba8f8aa2cb3c979 */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_define_by_name, 0, 3, _IS_BOOL, 0)
        ZEND_ARG_INFO(0, statement_resource)
@@ -124,7 +124,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_export, 0, 2, _IS_BOOL, 0)
        ZEND_ARG_OBJ_INFO(0, lob_descriptor, OCILob, 0)
-       ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
 ZEND_END_ARG_INFO()
@@ -292,7 +292,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_get_implicit_resultset, 0, 0, 1)
        ZEND_ARG_INFO(0, statement_resource)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 0)
        ZEND_ARG_INFO(0, statement_resource)
        ZEND_ARG_TYPE_INFO(0, number_of_rows, IS_LONG, 0)
 ZEND_END_ARG_INFO()
@@ -498,7 +498,7 @@ ZEND_END_ARG_INFO()
 #define arginfo_class_OCILob_getbuffering arginfo_class_OCILob_load
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_writetofile, 0, 0, 1)
-       ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
 ZEND_END_ARG_INFO()
index 26f8dfdc401bfe41ced52518ee099de75bf96d90..91db3f4815fc37d88f9ff76d1b7268e2cebeac3a 100644 (file)
@@ -40,6 +40,8 @@
 #define OCI_STMT_CALL 10
 #endif
 
+#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
+
 /* {{{ Register a callback function for Oracle Transparent Application Failover (TAF) */
 PHP_FUNCTION(oci_register_taf_callback)
 {
@@ -109,8 +111,8 @@ PHP_FUNCTION(oci_define_by_name)
        ZEND_PARSE_PARAMETERS_END();
 
        if (!name_len) {
-               php_error_docref(NULL, E_WARNING, "Column name cannot be empty");
-               RETURN_FALSE;
+               zend_argument_value_error(2, "cannot be empty");
+               RETURN_THROWS();
        }
 
        PHP_OCI_ZVAL_TO_STATEMENT(stmt, statement);
@@ -210,8 +212,8 @@ PHP_FUNCTION(oci_bind_array_by_name)
        }
 
        if (max_array_len <= 0) {
-               php_error_docref(NULL, E_WARNING, "Maximum array length must be greater than zero");
-               RETURN_FALSE;
+               zend_argument_value_error(4, "must be greater than 0");
+               RETURN_THROWS();
        }
 
        if (php_oci_bind_array_by_name(statement, name, (sb4) name_len, bind_var, max_array_len, max_item_len, type)) {
@@ -257,6 +259,11 @@ PHP_FUNCTION(oci_lob_save)
                RETURN_THROWS();
        }
 
+       if (offset < 0) {
+               zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
+               RETURN_THROWS();
+       }
+
        if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
                php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
                RETURN_FALSE;
@@ -264,11 +271,6 @@ PHP_FUNCTION(oci_lob_save)
 
        PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
 
-       if (offset < 0) {
-               php_error_docref(NULL, E_WARNING, "Offset parameter must be greater than or equal to 0");
-               RETURN_FALSE;
-       }
-
        if (php_oci_lob_write(descriptor, (ub4) offset, data, (ub4) data_len, &bytes_written)) {
                RETURN_FALSE;
        }
@@ -284,7 +286,7 @@ PHP_FUNCTION(oci_lob_import)
        char *filename;
        size_t filename_len;
 
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
                RETURN_THROWS();
        }
 
@@ -293,11 +295,6 @@ PHP_FUNCTION(oci_lob_import)
                RETURN_FALSE;
        }
 
-       if (CHECK_NULL_PATH(filename, filename_len)) {
-               php_error_docref(NULL, E_WARNING, "filename must not contain null bytes");
-               RETURN_FALSE;
-       }
-
        PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
 
        if (php_oci_lob_import(descriptor, filename)) {
@@ -354,6 +351,11 @@ PHP_FUNCTION(oci_lob_read)
                RETURN_THROWS();
        }
 
+       if (length <= 0) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0");
+               RETURN_THROWS();
+       }
+
        if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
                php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
                RETURN_FALSE;
@@ -361,11 +363,6 @@ PHP_FUNCTION(oci_lob_read)
 
        PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
 
-       if (length <= 0) {
-               php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
-               RETURN_FALSE;
-       }
-
        if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len)) {
                RETURN_FALSE;
        }
@@ -604,13 +601,13 @@ PHP_FUNCTION(oci_lob_truncate)
                RETURN_THROWS();
        }
 
-       if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
-               php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
-               RETURN_FALSE;
+       if (trim_length < 0) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
-       if (trim_length < 0) {
-               php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to zero");
+       if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
+               php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
                RETURN_FALSE;
        }
 
@@ -640,15 +637,15 @@ PHP_FUNCTION(oci_lob_erase)
        if (offset_is_null) {
                offset = -1;
        } else if (offset < 0) {
-               php_error_docref(NULL, E_WARNING, "Offset must be greater than or equal to 0");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        if (length_is_null) {
                length = -1;
        } else if (length < 0) {
-               php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
@@ -756,6 +753,13 @@ PHP_FUNCTION(oci_lob_copy)
                RETURN_THROWS();
        }
 
+       if (length_is_null) {
+               length = -1;
+       } else if (length < 0) {
+               zend_argument_value_error(3, "must be greater than or equal to 0");
+               RETURN_THROWS();
+       }
+
        if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor")-1)) == NULL) {
                php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
                RETURN_FALSE;
@@ -769,13 +773,6 @@ PHP_FUNCTION(oci_lob_copy)
        PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_dest, descriptor_dest);
        PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_from, descriptor_from);
 
-       if (length_is_null) {
-               length = -1;
-       } else if (length < 0) {
-               php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
-               RETURN_FALSE;
-       }
-
        if (php_oci_lob_copy(descriptor_dest, descriptor_from, length)) {
                RETURN_FALSE;
        }
@@ -831,22 +828,22 @@ PHP_FUNCTION(oci_lob_export)
        php_stream *stream;
        ub4 lob_length;
 
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &start_is_null, &length, &length_is_null) == FAILURE) {
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &start_is_null, &length, &length_is_null) == FAILURE) {
                RETURN_THROWS();
        }
 
        if (start_is_null) {
                start = -1;
        } else if (start < 0) {
-               php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        if (length_is_null) {
                length = -1;
        } else if (length < 0) {
-               php_error_docref(NULL, E_WARNING, "length parameter must be greater than or equal to 0");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(4), "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
@@ -854,11 +851,6 @@ PHP_FUNCTION(oci_lob_export)
                RETURN_FALSE;
        }
 
-       if (CHECK_NULL_PATH(filename, filename_len)) {
-               php_error_docref(NULL, E_WARNING, "filename must not contain null bytes");
-               RETURN_FALSE;
-       }
-
        PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
 
        if (php_oci_lob_get_length(descriptor, &lob_length)) {
@@ -1630,8 +1622,8 @@ PHP_FUNCTION(oci_set_prefetch)
        PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
 
        if (size < 0) {
-               php_error_docref(NULL, E_WARNING, "Number of rows to be prefetched has to be greater than or equal to 0");
-               return;
+               zend_argument_value_error(2, "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        if (php_oci_statement_set_prefetch(statement, (ub4)size)) {
@@ -1899,16 +1891,16 @@ PHP_FUNCTION(oci_password_change)
                PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
 
                if (!user_len) {
-                       php_error_docref(NULL, E_WARNING, "Username cannot be empty");
-                       RETURN_FALSE;
+                       zend_argument_value_error(2, "cannot be empty");
+                       RETURN_THROWS();
                }
                if (!pass_old_len) {
-                       php_error_docref(NULL, E_WARNING, "Old password cannot be empty");
-                       RETURN_FALSE;
+                       zend_argument_value_error(3, "cannot be empty");
+                       RETURN_THROWS();
                }
                if (!pass_new_len) {
-                       php_error_docref(NULL, E_WARNING, "New password cannot be empty");
-                       RETURN_FALSE;
+                       zend_argument_value_error(4, "cannot be empty");
+                       RETURN_THROWS();
                }
 
                if (php_oci_password_change(connection, user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len)) {
@@ -1918,16 +1910,16 @@ PHP_FUNCTION(oci_password_change)
        } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "ssss", &dbname, &dbname_len, &user, &user_len, &pass_old, &pass_old_len, &pass_new, &pass_new_len) == SUCCESS) {
 
                if (!user_len) {
-                       php_error_docref(NULL, E_WARNING, "Username cannot be empty");
-                       RETURN_FALSE;
+                       zend_argument_value_error(2, "cannot be empty");
+                       RETURN_THROWS();
                }
                if (!pass_old_len) {
-                       php_error_docref(NULL, E_WARNING, "Old password cannot be empty");
-                       RETURN_FALSE;
+                       zend_argument_value_error(3, "cannot be empty");
+                       RETURN_THROWS();
                }
                if (!pass_new_len) {
-                       php_error_docref(NULL, E_WARNING, "New password cannot be empty");
-                       RETURN_FALSE;
+                       zend_argument_value_error(4, "cannot be empty");
+                       RETURN_THROWS();
                }
 
                connection = php_oci_do_connect_ex(user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len, dbname, (int) dbname_len, NULL, OCI_DEFAULT, 0, 0);
index 14635356ba6a31d4c848d1ddb04750aeea5573ef..863f543c0f5a4986a5b5e20aa83df048fd03f0b6 100644 (file)
@@ -50,7 +50,11 @@ $statement = oci_parse($c, "BEGIN array_bind_002_pkg.iobind(:c1); END;");
 
 $array = Array("06-DEC-05","10-DEC-80","21-AUG-91","26-OCT-17","05-NOV-05");
 
-oci_bind_array_by_name($statement, ":c1", $array, 0, 0, SQLT_ODT);
+try {
+    oci_bind_array_by_name($statement, ":c1", $array, 0, 0, SQLT_ODT);
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}
 
 oci_execute($statement);
 
@@ -59,7 +63,7 @@ var_dump($array);
 echo "Done\n";
 ?>
 --EXPECTF--
-Warning: oci_bind_array_by_name(): Maximum array length must be greater than zero in %s on line %d
+oci_bind_array_by_name(): Argument #4 ($maximum_array_length) must be greater than 0
 
 Warning: oci_execute(): ORA-%r(01008|57000)%r: %s in %s on line %d
 array(5) {
index 73178ae622748ce5b6b6487c1a66b9c146ef53dc..e79fd76e1b9bd55f7e49b7bb7879a418d85cc21a 100644 (file)
@@ -26,7 +26,11 @@ $stmt = oci_parse($c, "select string from define1_tab");
 $string = '';
 var_dump(oci_define_by_name($stmt, "STRING", $string, 20));
 var_dump(oci_define_by_name($stmt, "STRING", $string, 20));
-var_dump(oci_define_by_name($stmt, "", $string, 20));
+try {
+    var_dump(oci_define_by_name($stmt, "", $string, 20));
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}
 
 oci_execute($stmt);
 
@@ -48,8 +52,6 @@ echo "Done\n";
 --EXPECTF--
 bool(true)
 bool(false)
-
-Warning: oci_define_by_name(): Column name cannot be empty in %s on line %d
-bool(false)
+oci_define_by_name(): Argument #2 ($column_name) cannot be empty
 string(4) "some"
 Done
index 80bead5964bd291cbe7f9d8bb66d433ddb58daf4..e06d15109c15d2eb67f04c3815b2d103346b608f 100644 (file)
Binary files a/ext/oci8/tests/lob_003.phpt and b/ext/oci8/tests/lob_003.phpt differ
index affdef912634d259fff24e1f081288bad00c5ff5..241b2c7c30f282bd079fa8dc97914d805f016e75 100644 (file)
Binary files a/ext/oci8/tests/lob_020.phpt and b/ext/oci8/tests/lob_020.phpt differ
index dba5adcbe36cd216b8a38f9df7b81af0affcd00d..3f57122818492a95f8622a46999af5510cfbf849 100644 (file)
@@ -34,11 +34,15 @@ $clob = oci_new_descriptor($c, OCI_D_LOB);
 oci_bind_by_name($statement, ":mylob", $clob, -1, OCI_B_CLOB);
 oci_execute($statement, OCI_DEFAULT);
 $clob->save("long data");
-$clob->save("long data", -1);
 $clob->save("long data", 0);
 
-oci_commit($c);
+try {
+    $clob->save("long data", -1);
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}    
 
+oci_commit($c);
 
 $query = 'SELECT * FROM lob_test ORDER BY mykey ASC';
 $statement = oci_parse ($c, $query);
@@ -67,7 +71,7 @@ echo "Done\n";
 ?>
 --EXPECTF--
 
-Warning: OCILob::save(): Offset parameter must be greater than or equal to 0 in %s on line %d
+OCILob::save(): Argument #2 ($offset) must be greater than or equal to 0
 string(4) "data"
 string(9) "long data"
 string(9) "long data"
index 05390d1403df06431edddd7d912698ad3e2e0398..8f5992a555a3aadb8d83c0488c079680e96f847e 100644 (file)
@@ -45,7 +45,11 @@ for ($i = 5; $i >= 0; $i--) {
 
     $row = oci_fetch_array($s);
     var_dump($row['BLOB']->load());
-    var_dump($row['BLOB']->truncate(($i-1)*10));
+    try {
+        var_dump($row['BLOB']->truncate(($i-1)*10));
+    } catch (ValueError $e) {
+        echo $e->getMessage(), "\n";
+    }
 
     oci_commit($c);
 }
@@ -56,9 +60,14 @@ oci_execute($s, OCI_DEFAULT);
 
 $row = oci_fetch_array($s);
 var_dump($row['BLOB']->load());
-var_dump($row['BLOB']->truncate(-1));
 var_dump($row['BLOB']->truncate(0));
 
+try {
+    var_dump($row['BLOB']->truncate(-1));
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}
+
 oci_commit($c);
 
 require __DIR__.'/drop_table.inc';
@@ -95,12 +104,8 @@ bool(true)
 string(10) "this is a "
 bool(true)
 string(0) ""
-
-Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d
-bool(false)
+OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
 string(0) ""
-
-Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d
-bool(false)
 bool(true)
+OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
 Done
index c2240849c249b54ea3d5ac491921d1daceca11f2..53146e12865758a0e4a25e428c50116e100f1308 100644 (file)
@@ -23,6 +23,7 @@ $blob = oci_new_descriptor($c,OCI_D_LOB);
 oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
 oci_execute($statement, OCI_DEFAULT);
 
+echo "Writing blob\n";
 var_dump($blob->write("some string here. string, I said"));
 oci_commit($c);
 
@@ -54,21 +55,34 @@ $row2 = oci_fetch_array($s);
 
 $dummy = oci_new_descriptor($c, OCI_D_LOB);
 
+//--------------------------------------------------
+
+echo "\noci_lob_copy invalid args\n";
+
 var_dump(oci_lob_copy($dummy, $row1[0]));
 var_dump(oci_lob_copy($row2[0], $dummy));
-
 var_dump(oci_lob_copy($row2[0], $row1[0], 0));
-var_dump(oci_lob_copy($row2[0], $row1[0], -1));
 var_dump(oci_lob_copy($row2[0], $row1[0], 100000));
 
+try {
+    var_dump(oci_lob_copy($row2[0], $row1[0], -1));
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}
+
+//--------------------------------------------------
+
+echo "\noci_lob_size tests\n";
+
 var_dump(oci_lob_size($row2[0]));
 unset($dummy->descriptor);
 var_dump(oci_lob_size($dummy));
 
 oci_rollback($c);
-oci_rollback($c);
-oci_commit($c);
-oci_commit($c);
+
+//--------------------------------------------------
+
+echo "\nQuery test\n";
 
 $select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 2 FOR UPDATE";
 $s = oci_parse($c, $select_sql);
@@ -82,22 +96,27 @@ echo "Done\n";
 
 ?>
 --EXPECTF--
+Writing blob
 int(32)
 
+oci_lob_copy invalid args
+
 Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d
 bool(false)
 
 Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d
 bool(false)
 bool(false)
-
-Warning: oci_lob_copy(): Length parameter must be greater than 0 in %s on line %d
-bool(false)
 bool(true)
+oci_lob_copy(): Argument #3 ($length) must be greater than or equal to 0
+
+oci_lob_size tests
 int(0)
 
 Warning: oci_lob_size(): Unable to find descriptor property in %s on line %d
 bool(false)
+
+Query test
 array(2) {
   [0]=>
   string(0) ""
index eb447f22afd80ad7c149153aa8fe6595411bdfa9..f9e072e0fe68e00e345429f19ab932ee6a3aa158 100644 (file)
@@ -32,12 +32,17 @@ var_dump($blob->write($str));
 var_dump($blob->truncate(1));
 var_dump($blob->truncate(1));
 var_dump($blob->truncate(2));
-var_dump($blob->truncate(-1));
 var_dump($blob->read(2));
 
 var_dump($blob->import("does_not_exist"));
 var_dump($blob->saveFile("does_not_exist"));
 
+try {
+    var_dump($blob->truncate(-1));
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}
+
 require(__DIR__.'/drop_table.inc');
 
 echo "Done\n";
@@ -58,9 +63,6 @@ bool(true)
 Warning: OCILob::truncate(): Size must be less than or equal to the current LOB size in %s on line %d
 bool(false)
 
-Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d
-bool(false)
-
 Warning: OCILob::read(): Offset must be less than size of the LOB in %s on line %d
 bool(false)
 
@@ -69,4 +71,5 @@ bool(false)
 
 Warning: OCILob::savefile(): Can't open file %s in %s on line %d
 bool(false)
+OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
 Done
index f922c62852d8cbee7e42b70374e44257ef53299a..d751335b1e86802a0eed52de4ec324a655f244a8 100644 (file)
@@ -9,7 +9,6 @@ if (PHP_MAJOR_VERSION < 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4))
 ?>
 --INI--
 display_errors = On
-error_reporting = E_WARNING
 --FILE--
 <?php
 
@@ -23,21 +22,23 @@ require(__DIR__.'/connect.inc');
 echo "Test 1: Import\n";
 
 $lob = oci_new_descriptor($c, OCI_D_LOB);
-$r = $lob->savefile("/tmp/abc\0def");
-var_dump($r);
+try {
+    $lob->savefile("/tmp/abc\0def");
+} catch (ValueError $e) {
+       echo $e->getMessage(), "\n";
+}
 
 echo "Test 2: Export\n";
 
-$r = $lob->export("/tmp/abc\0def");
-var_dump($r);
+try {
+    $lob->export("/tmp/abc\0def");
+} catch (ValueError $e) {
+       echo $e->getMessage(), "\n";
+}
 
 ?>
 --EXPECTF--
 Test 1: Import
-
-Warning: OCILob::savefile(): filename must not contain null bytes in %s on line %d
-bool(false)
+OCILob::savefile(): Argument #1 ($filename) must not contain any null bytes
 Test 2: Export
-
-Warning: OCILob::export(): filename must not contain null bytes in %s on line %d
-bool(false)
+OCILob::export(): Argument #1 ($filename) must not contain any null bytes
index 911a4810633ffc735a48f9047a4f7c502d8f8d8d..0297401f995dc6af33df5cd52553e30367dad5f3 100644 (file)
@@ -61,7 +61,7 @@ for ($i = 0; $i<=500; $i++) {
 }
 
 // Various values for prefetch
-$pref = array(0,1,501,499,250,12345,-12345,-1);
+$pref = array(0,1,501,499,250,12345);
 foreach($pref as $value) {
     echo"-----------------------------------------------\n";
     echo "Test with Prefetch value set to $value \n";
@@ -71,6 +71,21 @@ foreach($pref as $value) {
     fetch_frm_plsql($c,$cur1);
 }
 
+// Various invalid values for prefetch
+$pref = array(-12345,-1);
+foreach($pref as $value) {
+    try {
+        echo "-----------------------------------------------\n";
+        echo "Test with Prefetch (invalid) value set to $value \n";
+        echo "-----------------------------------------------\n";
+        $cur1 = oci_new_cursor($c);
+        fetch_frm_php($c,$cur1,$value);
+        fetch_frm_plsql($c,$cur1);
+    } catch(ValueError $e) {
+        echo $e->getMessage(), "\n";
+    }
+}
+
 
 // This function sets the prefetch count to the given $value and fetches one row .
 
@@ -206,33 +221,11 @@ Fetch Row from PL/SQL
 int(0)
 NULL
 -----------------------------------------------
-Test with Prefetch value set to -12345 
+Test with Prefetch (invalid) value set to -12345 
 -----------------------------------------------
-
-Warning: oci_set_prefetch(): Number of rows to be prefetched has to be greater than or equal to 0 in %s on line %d
-Fetch Row from PHP
-array(2) {
-  [0]=>
-  string(%d) "0"
-  [1]=>
-  string(%d) "test0"
-}
-Fetch Row from PL/SQL
-int(101)
-string(%d) "test101"
+oci_set_prefetch(): Argument #2 ($number_of_rows) must be greater than or equal to 0
 -----------------------------------------------
-Test with Prefetch value set to -1 
+Test with Prefetch (invalid) value set to -1 
 -----------------------------------------------
-
-Warning: oci_set_prefetch(): Number of rows to be prefetched has to be greater than or equal to 0 in %s on line %d
-Fetch Row from PHP
-array(2) {
-  [0]=>
-  string(%d) "0"
-  [1]=>
-  string(%d) "test0"
-}
-Fetch Row from PL/SQL
-int(101)
-string(%d) "test101"
+oci_set_prefetch(): Argument #2 ($number_of_rows) must be greater than or equal to 0
 Done