Skip to content

Commit 824a2bf

Browse files
Girgiascjbj
andcommitted
Promote some warnings to ValueError in OCI8
Closes GH-6116 Co-authored-by: Christopher Jones <sixd@php.net>
1 parent 452f7b0 commit 824a2bf

13 files changed

+160
-137
lines changed

ext/oci8/oci8.stub.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ function oci_lob_copy(OCILob $lob_descriptor_to, OCILob $lob_descriptor_from, ?i
8787

8888
function oci_lob_is_equal(OCILob $lob_descriptor_first, OCILob $lob_descriptor_second): bool {}
8989

90-
function oci_lob_export(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {}
90+
function oci_lob_export(OCILob $lob_descriptor, string $filename, ?int $start = null, ?int $length = null): bool {}
9191

9292
/**
9393
* @alias oci_lob_export
9494
* @deprecated
9595
*/
96-
function ociwritelobtofile(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {}
96+
function ociwritelobtofile(OCILob $lob_descriptor, string $filename, ?int $start = null, ?int $length = null): bool {}
9797

9898
/**
9999
* @param resource $connection_resource
@@ -412,14 +412,14 @@ function oci_get_implicit_resultset($statement_resource) {}
412412
/**
413413
* @param resource $statement_resource
414414
*/
415-
function oci_set_prefetch($statement_resource, int $number_of_rows): ?bool {}
415+
function oci_set_prefetch($statement_resource, int $number_of_rows): bool {}
416416

417417
/**
418418
* @param resource $statement_resource
419419
* @alias oci_set_prefetch
420420
* @deprecated
421421
*/
422-
function ocisetprefetch($statement_resource, int $number_of_rows): ?bool {}
422+
function ocisetprefetch($statement_resource, int $number_of_rows): bool {}
423423

424424
/**
425425
* @param resource $connection_resource
@@ -718,13 +718,13 @@ public function getbuffering() {}
718718
* @alias oci_lob_export
719719
* @return bool
720720
*/
721-
public function writetofile(string $path, ?int $start = null, ?int $length = null) {}
721+
public function writetofile(string $filename, ?int $start = null, ?int $length = null) {}
722722

723723
/**
724724
* @alias oci_lob_export
725725
* @return bool
726726
*/
727-
public function export(string $path, ?int $start = null, ?int $length = null) {}
727+
public function export(string $filename, ?int $start = null, ?int $length = null) {}
728728

729729
/**
730730
* @alias oci_lob_write_temporary

ext/oci8/oci8_arginfo.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 2d553815c21edd58bc29b1ca8d294d5750fd7312 */
2+
* Stub hash: 6cdc7c967ce80c39eaef1c860ba8f8aa2cb3c979 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_define_by_name, 0, 3, _IS_BOOL, 0)
55
ZEND_ARG_INFO(0, statement_resource)
@@ -124,7 +124,7 @@ ZEND_END_ARG_INFO()
124124

125125
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_export, 0, 2, _IS_BOOL, 0)
126126
ZEND_ARG_OBJ_INFO(0, lob_descriptor, OCILob, 0)
127-
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
127+
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
128128
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null")
129129
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
130130
ZEND_END_ARG_INFO()
@@ -292,7 +292,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_get_implicit_resultset, 0, 0, 1)
292292
ZEND_ARG_INFO(0, statement_resource)
293293
ZEND_END_ARG_INFO()
294294

295-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 1)
295+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_set_prefetch, 0, 2, _IS_BOOL, 0)
296296
ZEND_ARG_INFO(0, statement_resource)
297297
ZEND_ARG_TYPE_INFO(0, number_of_rows, IS_LONG, 0)
298298
ZEND_END_ARG_INFO()
@@ -498,7 +498,7 @@ ZEND_END_ARG_INFO()
498498
#define arginfo_class_OCILob_getbuffering arginfo_class_OCILob_load
499499

500500
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_writetofile, 0, 0, 1)
501-
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
501+
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
502502
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null")
503503
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
504504
ZEND_END_ARG_INFO()

ext/oci8/oci8_interface.c

+52-60
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define OCI_STMT_CALL 10
4141
#endif
4242

43+
#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
44+
4345
/* {{{ Register a callback function for Oracle Transparent Application Failover (TAF) */
4446
PHP_FUNCTION(oci_register_taf_callback)
4547
{
@@ -109,8 +111,8 @@ PHP_FUNCTION(oci_define_by_name)
109111
ZEND_PARSE_PARAMETERS_END();
110112

111113
if (!name_len) {
112-
php_error_docref(NULL, E_WARNING, "Column name cannot be empty");
113-
RETURN_FALSE;
114+
zend_argument_value_error(2, "cannot be empty");
115+
RETURN_THROWS();
114116
}
115117

116118
PHP_OCI_ZVAL_TO_STATEMENT(stmt, statement);
@@ -210,8 +212,8 @@ PHP_FUNCTION(oci_bind_array_by_name)
210212
}
211213

212214
if (max_array_len <= 0) {
213-
php_error_docref(NULL, E_WARNING, "Maximum array length must be greater than zero");
214-
RETURN_FALSE;
215+
zend_argument_value_error(4, "must be greater than 0");
216+
RETURN_THROWS();
215217
}
216218

217219
if (php_oci_bind_array_by_name(statement, name, (sb4) name_len, bind_var, max_array_len, max_item_len, type)) {
@@ -257,18 +259,18 @@ PHP_FUNCTION(oci_lob_save)
257259
RETURN_THROWS();
258260
}
259261

262+
if (offset < 0) {
263+
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
264+
RETURN_THROWS();
265+
}
266+
260267
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
261268
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
262269
RETURN_FALSE;
263270
}
264271

265272
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
266273

267-
if (offset < 0) {
268-
php_error_docref(NULL, E_WARNING, "Offset parameter must be greater than or equal to 0");
269-
RETURN_FALSE;
270-
}
271-
272274
if (php_oci_lob_write(descriptor, (ub4) offset, data, (ub4) data_len, &bytes_written)) {
273275
RETURN_FALSE;
274276
}
@@ -284,7 +286,7 @@ PHP_FUNCTION(oci_lob_import)
284286
char *filename;
285287
size_t filename_len;
286288

287-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
289+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Op", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
288290
RETURN_THROWS();
289291
}
290292

@@ -293,11 +295,6 @@ PHP_FUNCTION(oci_lob_import)
293295
RETURN_FALSE;
294296
}
295297

296-
if (CHECK_NULL_PATH(filename, filename_len)) {
297-
php_error_docref(NULL, E_WARNING, "filename must not contain null bytes");
298-
RETURN_FALSE;
299-
}
300-
301298
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
302299

303300
if (php_oci_lob_import(descriptor, filename)) {
@@ -354,18 +351,18 @@ PHP_FUNCTION(oci_lob_read)
354351
RETURN_THROWS();
355352
}
356353

354+
if (length <= 0) {
355+
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0");
356+
RETURN_THROWS();
357+
}
358+
357359
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
358360
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
359361
RETURN_FALSE;
360362
}
361363

362364
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
363365

364-
if (length <= 0) {
365-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
366-
RETURN_FALSE;
367-
}
368-
369366
if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len)) {
370367
RETURN_FALSE;
371368
}
@@ -604,13 +601,13 @@ PHP_FUNCTION(oci_lob_truncate)
604601
RETURN_THROWS();
605602
}
606603

607-
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
608-
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
609-
RETURN_FALSE;
604+
if (trim_length < 0) {
605+
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
606+
RETURN_THROWS();
610607
}
611608

612-
if (trim_length < 0) {
613-
php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to zero");
609+
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
610+
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
614611
RETURN_FALSE;
615612
}
616613

@@ -640,15 +637,15 @@ PHP_FUNCTION(oci_lob_erase)
640637
if (offset_is_null) {
641638
offset = -1;
642639
} else if (offset < 0) {
643-
php_error_docref(NULL, E_WARNING, "Offset must be greater than or equal to 0");
644-
RETURN_FALSE;
640+
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
641+
RETURN_THROWS();
645642
}
646643

647644
if (length_is_null) {
648645
length = -1;
649646
} else if (length < 0) {
650-
php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0");
651-
RETURN_FALSE;
647+
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
648+
RETURN_THROWS();
652649
}
653650

654651
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)
756753
RETURN_THROWS();
757754
}
758755

756+
if (length_is_null) {
757+
length = -1;
758+
} else if (length < 0) {
759+
zend_argument_value_error(3, "must be greater than or equal to 0");
760+
RETURN_THROWS();
761+
}
762+
759763
if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor")-1)) == NULL) {
760764
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
761765
RETURN_FALSE;
@@ -769,13 +773,6 @@ PHP_FUNCTION(oci_lob_copy)
769773
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_dest, descriptor_dest);
770774
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp_from, descriptor_from);
771775

772-
if (length_is_null) {
773-
length = -1;
774-
} else if (length < 0) {
775-
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
776-
RETURN_FALSE;
777-
}
778-
779776
if (php_oci_lob_copy(descriptor_dest, descriptor_from, length)) {
780777
RETURN_FALSE;
781778
}
@@ -831,34 +828,29 @@ PHP_FUNCTION(oci_lob_export)
831828
php_stream *stream;
832829
ub4 lob_length;
833830

834-
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) {
831+
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) {
835832
RETURN_THROWS();
836833
}
837834

838835
if (start_is_null) {
839836
start = -1;
840837
} else if (start < 0) {
841-
php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0");
842-
RETURN_FALSE;
838+
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
839+
RETURN_THROWS();
843840
}
844841

845842
if (length_is_null) {
846843
length = -1;
847844
} else if (length < 0) {
848-
php_error_docref(NULL, E_WARNING, "length parameter must be greater than or equal to 0");
849-
RETURN_FALSE;
845+
zend_argument_value_error(ERROR_ARG_POS(4), "must be greater than or equal to 0");
846+
RETURN_THROWS();
850847
}
851848

852849
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor")-1)) == NULL) {
853850
php_error_docref(NULL, E_WARNING, "Unable to find descriptor property");
854851
RETURN_FALSE;
855852
}
856853

857-
if (CHECK_NULL_PATH(filename, filename_len)) {
858-
php_error_docref(NULL, E_WARNING, "filename must not contain null bytes");
859-
RETURN_FALSE;
860-
}
861-
862854
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);
863855

864856
if (php_oci_lob_get_length(descriptor, &lob_length)) {
@@ -1630,8 +1622,8 @@ PHP_FUNCTION(oci_set_prefetch)
16301622
PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
16311623

16321624
if (size < 0) {
1633-
php_error_docref(NULL, E_WARNING, "Number of rows to be prefetched has to be greater than or equal to 0");
1634-
return;
1625+
zend_argument_value_error(2, "must be greater than or equal to 0");
1626+
RETURN_THROWS();
16351627
}
16361628

16371629
if (php_oci_statement_set_prefetch(statement, (ub4)size)) {
@@ -1899,16 +1891,16 @@ PHP_FUNCTION(oci_password_change)
18991891
PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
19001892

19011893
if (!user_len) {
1902-
php_error_docref(NULL, E_WARNING, "Username cannot be empty");
1903-
RETURN_FALSE;
1894+
zend_argument_value_error(2, "cannot be empty");
1895+
RETURN_THROWS();
19041896
}
19051897
if (!pass_old_len) {
1906-
php_error_docref(NULL, E_WARNING, "Old password cannot be empty");
1907-
RETURN_FALSE;
1898+
zend_argument_value_error(3, "cannot be empty");
1899+
RETURN_THROWS();
19081900
}
19091901
if (!pass_new_len) {
1910-
php_error_docref(NULL, E_WARNING, "New password cannot be empty");
1911-
RETURN_FALSE;
1902+
zend_argument_value_error(4, "cannot be empty");
1903+
RETURN_THROWS();
19121904
}
19131905

19141906
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)
19181910
} 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) {
19191911

19201912
if (!user_len) {
1921-
php_error_docref(NULL, E_WARNING, "Username cannot be empty");
1922-
RETURN_FALSE;
1913+
zend_argument_value_error(2, "cannot be empty");
1914+
RETURN_THROWS();
19231915
}
19241916
if (!pass_old_len) {
1925-
php_error_docref(NULL, E_WARNING, "Old password cannot be empty");
1926-
RETURN_FALSE;
1917+
zend_argument_value_error(3, "cannot be empty");
1918+
RETURN_THROWS();
19271919
}
19281920
if (!pass_new_len) {
1929-
php_error_docref(NULL, E_WARNING, "New password cannot be empty");
1930-
RETURN_FALSE;
1921+
zend_argument_value_error(4, "cannot be empty");
1922+
RETURN_THROWS();
19311923
}
19321924

19331925
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);

ext/oci8/tests/array_bind_002.phpt

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ $statement = oci_parse($c, "BEGIN array_bind_002_pkg.iobind(:c1); END;");
5050

5151
$array = Array("06-DEC-05","10-DEC-80","21-AUG-91","26-OCT-17","05-NOV-05");
5252

53-
oci_bind_array_by_name($statement, ":c1", $array, 0, 0, SQLT_ODT);
53+
try {
54+
oci_bind_array_by_name($statement, ":c1", $array, 0, 0, SQLT_ODT);
55+
} catch (ValueError $e) {
56+
echo $e->getMessage(), "\n";
57+
}
5458

5559
oci_execute($statement);
5660

@@ -59,7 +63,7 @@ var_dump($array);
5963
echo "Done\n";
6064
?>
6165
--EXPECTF--
62-
Warning: oci_bind_array_by_name(): Maximum array length must be greater than zero in %s on line %d
66+
oci_bind_array_by_name(): Argument #4 ($maximum_array_length) must be greater than 0
6367

6468
Warning: oci_execute(): ORA-%r(01008|57000)%r: %s in %s on line %d
6569
array(5) {

ext/oci8/tests/define1.phpt

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ $stmt = oci_parse($c, "select string from define1_tab");
2626
$string = '';
2727
var_dump(oci_define_by_name($stmt, "STRING", $string, 20));
2828
var_dump(oci_define_by_name($stmt, "STRING", $string, 20));
29-
var_dump(oci_define_by_name($stmt, "", $string, 20));
29+
try {
30+
var_dump(oci_define_by_name($stmt, "", $string, 20));
31+
} catch (ValueError $e) {
32+
echo $e->getMessage(), "\n";
33+
}
3034

3135
oci_execute($stmt);
3236

@@ -48,8 +52,6 @@ echo "Done\n";
4852
--EXPECTF--
4953
bool(true)
5054
bool(false)
51-
52-
Warning: oci_define_by_name(): Column name cannot be empty in %s on line %d
53-
bool(false)
55+
oci_define_by_name(): Argument #2 ($column_name) cannot be empty
5456
string(4) "some"
5557
Done

ext/oci8/tests/lob_003.phpt

37 Bytes
Binary file not shown.

ext/oci8/tests/lob_020.phpt

609 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)