Skip to content

Commit d60f1b4

Browse files
authored
Merge pull request #5 from cjbj/valerrtest
Tweaks and test updates for PR 6116
2 parents 793e5a5 + 2b6d609 commit d60f1b4

13 files changed

+114
-81
lines changed

ext/oci8/oci8.stub.php

Lines changed: 4 additions & 4 deletions
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
@@ -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

Lines changed: 3 additions & 3 deletions
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: b795b3009f220d578fc93134bd9f07dd685b6493 */
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()
@@ -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

Lines changed: 9 additions & 7 deletions
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
{
@@ -258,7 +260,7 @@ PHP_FUNCTION(oci_lob_save)
258260
}
259261

260262
if (offset < 0) {
261-
zend_argument_value_error(3, "must be greater than or equal to 0");
263+
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
262264
RETURN_THROWS();
263265
}
264266

@@ -350,7 +352,7 @@ PHP_FUNCTION(oci_lob_read)
350352
}
351353

352354
if (length <= 0) {
353-
zend_argument_value_error(2, "must be greater than 0");
355+
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0");
354356
RETURN_THROWS();
355357
}
356358

@@ -600,7 +602,7 @@ PHP_FUNCTION(oci_lob_truncate)
600602
}
601603

602604
if (trim_length < 0) {
603-
zend_argument_value_error(2, "must be greater than or equal to zero");
605+
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
604606
RETURN_THROWS();
605607
}
606608

@@ -635,14 +637,14 @@ PHP_FUNCTION(oci_lob_erase)
635637
if (offset_is_null) {
636638
offset = -1;
637639
} else if (offset < 0) {
638-
zend_argument_value_error(2, "must be greater than or equal to 0");
640+
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
639641
RETURN_THROWS();
640642
}
641643

642644
if (length_is_null) {
643645
length = -1;
644646
} else if (length < 0) {
645-
zend_argument_value_error(3, "must be greater than or equal to 0");
647+
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
646648
RETURN_THROWS();
647649
}
648650

@@ -833,14 +835,14 @@ PHP_FUNCTION(oci_lob_export)
833835
if (start_is_null) {
834836
start = -1;
835837
} else if (start < 0) {
836-
zend_argument_value_error(3, "must be greater than or equal to 0");
838+
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
837839
RETURN_THROWS();
838840
}
839841

840842
if (length_is_null) {
841843
length = -1;
842844
} else if (length < 0) {
843-
zend_argument_value_error(4, "must be greater than or equal to 0");
845+
zend_argument_value_error(ERROR_ARG_POS(4), "must be greater than or equal to 0");
844846
RETURN_THROWS();
845847
}
846848

ext/oci8/tests/array_bind_002.phpt

Lines changed: 6 additions & 2 deletions
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

Lines changed: 6 additions & 4 deletions
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.

ext/oci8/tests/lob_022.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ $clob = oci_new_descriptor($c, OCI_D_LOB);
3434
oci_bind_by_name($statement, ":mylob", $clob, -1, OCI_B_CLOB);
3535
oci_execute($statement, OCI_DEFAULT);
3636
$clob->save("long data");
37-
$clob->save("long data", -1);
3837
$clob->save("long data", 0);
3938

40-
oci_commit($c);
39+
try {
40+
$clob->save("long data", -1);
41+
} catch (ValueError $e) {
42+
echo $e->getMessage(), "\n";
43+
}
4144

45+
oci_commit($c);
4246

4347
$query = 'SELECT * FROM lob_test ORDER BY mykey ASC';
4448
$statement = oci_parse ($c, $query);
@@ -67,7 +71,7 @@ echo "Done\n";
6771
?>
6872
--EXPECTF--
6973

70-
Warning: OCILob::save(): Offset parameter must be greater than or equal to 0 in %s on line %d
74+
OCILob::save(): Argument #2 ($offset) must be greater than or equal to 0
7175
string(4) "data"
7276
string(9) "long data"
7377
string(9) "long data"

ext/oci8/tests/lob_027.phpt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ for ($i = 5; $i >= 0; $i--) {
4545

4646
$row = oci_fetch_array($s);
4747
var_dump($row['BLOB']->load());
48-
var_dump($row['BLOB']->truncate(($i-1)*10));
48+
try {
49+
var_dump($row['BLOB']->truncate(($i-1)*10));
50+
} catch (ValueError $e) {
51+
echo $e->getMessage(), "\n";
52+
}
4953

5054
oci_commit($c);
5155
}
@@ -56,9 +60,14 @@ oci_execute($s, OCI_DEFAULT);
5660

5761
$row = oci_fetch_array($s);
5862
var_dump($row['BLOB']->load());
59-
var_dump($row['BLOB']->truncate(-1));
6063
var_dump($row['BLOB']->truncate(0));
6164

65+
try {
66+
var_dump($row['BLOB']->truncate(-1));
67+
} catch (ValueError $e) {
68+
echo $e->getMessage(), "\n";
69+
}
70+
6271
oci_commit($c);
6372

6473
require __DIR__.'/drop_table.inc';
@@ -95,12 +104,8 @@ bool(true)
95104
string(10) "this is a "
96105
bool(true)
97106
string(0) ""
98-
99-
Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d
100-
bool(false)
107+
OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
101108
string(0) ""
102-
103-
Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d
104-
bool(false)
105109
bool(true)
110+
OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
106111
Done

ext/oci8/tests/lob_035.phpt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $blob = oci_new_descriptor($c,OCI_D_LOB);
2323
oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
2424
oci_execute($statement, OCI_DEFAULT);
2525

26+
echo "Writing blob\n";
2627
var_dump($blob->write("some string here. string, I said"));
2728
oci_commit($c);
2829

@@ -54,21 +55,34 @@ $row2 = oci_fetch_array($s);
5455

5556
$dummy = oci_new_descriptor($c, OCI_D_LOB);
5657

58+
//--------------------------------------------------
59+
60+
echo "\noci_lob_copy invalid args\n";
61+
5762
var_dump(oci_lob_copy($dummy, $row1[0]));
5863
var_dump(oci_lob_copy($row2[0], $dummy));
59-
6064
var_dump(oci_lob_copy($row2[0], $row1[0], 0));
61-
var_dump(oci_lob_copy($row2[0], $row1[0], -1));
6265
var_dump(oci_lob_copy($row2[0], $row1[0], 100000));
6366

67+
try {
68+
var_dump(oci_lob_copy($row2[0], $row1[0], -1));
69+
} catch (ValueError $e) {
70+
echo $e->getMessage(), "\n";
71+
}
72+
73+
//--------------------------------------------------
74+
75+
echo "\noci_lob_size tests\n";
76+
6477
var_dump(oci_lob_size($row2[0]));
6578
unset($dummy->descriptor);
6679
var_dump(oci_lob_size($dummy));
6780

6881
oci_rollback($c);
69-
oci_rollback($c);
70-
oci_commit($c);
71-
oci_commit($c);
82+
83+
//--------------------------------------------------
84+
85+
echo "\nQuery test\n";
7286

7387
$select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 2 FOR UPDATE";
7488
$s = oci_parse($c, $select_sql);
@@ -82,22 +96,27 @@ echo "Done\n";
8296

8397
?>
8498
--EXPECTF--
99+
Writing blob
85100
int(32)
86101

102+
oci_lob_copy invalid args
103+
87104
Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d
88105
bool(false)
89106

90107
Warning: oci_lob_copy(): OCI_INVALID_HANDLE in %s on line %d
91108
bool(false)
92109
bool(false)
93-
94-
Warning: oci_lob_copy(): Length parameter must be greater than 0 in %s on line %d
95-
bool(false)
96110
bool(true)
111+
oci_lob_copy(): Argument #3 ($length) must be greater than or equal to 0
112+
113+
oci_lob_size tests
97114
int(0)
98115

99116
Warning: oci_lob_size(): Unable to find descriptor property in %s on line %d
100117
bool(false)
118+
119+
Query test
101120
array(2) {
102121
[0]=>
103122
string(0) ""

ext/oci8/tests/lob_042.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ var_dump($blob->write($str));
3232
var_dump($blob->truncate(1));
3333
var_dump($blob->truncate(1));
3434
var_dump($blob->truncate(2));
35-
var_dump($blob->truncate(-1));
3635
var_dump($blob->read(2));
3736

3837
var_dump($blob->import("does_not_exist"));
3938
var_dump($blob->saveFile("does_not_exist"));
4039

40+
try {
41+
var_dump($blob->truncate(-1));
42+
} catch (ValueError $e) {
43+
echo $e->getMessage(), "\n";
44+
}
45+
4146
require(__DIR__.'/drop_table.inc');
4247

4348
echo "Done\n";
@@ -58,9 +63,6 @@ bool(true)
5863
Warning: OCILob::truncate(): Size must be less than or equal to the current LOB size in %s on line %d
5964
bool(false)
6065

61-
Warning: OCILob::truncate(): Length must be greater than or equal to zero in %s on line %d
62-
bool(false)
63-
6466
Warning: OCILob::read(): Offset must be less than size of the LOB in %s on line %d
6567
bool(false)
6668

@@ -69,4 +71,5 @@ bool(false)
6971

7072
Warning: OCILob::savefile(): Can't open file %s in %s on line %d
7173
bool(false)
74+
OCILob::truncate(): Argument #1 ($length) must be greater than or equal to 0
7275
Done

ext/oci8/tests/null_byte_1.phpt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ if (PHP_MAJOR_VERSION < 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4))
99
?>
1010
--INI--
1111
display_errors = On
12-
error_reporting = E_WARNING
1312
--FILE--
1413
<?php
1514

@@ -23,21 +22,23 @@ require(__DIR__.'/connect.inc');
2322
echo "Test 1: Import\n";
2423

2524
$lob = oci_new_descriptor($c, OCI_D_LOB);
26-
$r = $lob->savefile("/tmp/abc\0def");
27-
var_dump($r);
25+
try {
26+
$lob->savefile("/tmp/abc\0def");
27+
} catch (ValueError $e) {
28+
echo $e->getMessage(), "\n";
29+
}
2830

2931
echo "Test 2: Export\n";
3032

31-
$r = $lob->export("/tmp/abc\0def");
32-
var_dump($r);
33+
try {
34+
$lob->export("/tmp/abc\0def");
35+
} catch (ValueError $e) {
36+
echo $e->getMessage(), "\n";
37+
}
3338

3439
?>
3540
--EXPECTF--
3641
Test 1: Import
37-
38-
Warning: OCILob::savefile(): filename must not contain null bytes in %s on line %d
39-
bool(false)
42+
OCILob::savefile(): Argument #1 ($filename) must not contain any null bytes
4043
Test 2: Export
41-
42-
Warning: OCILob::export(): filename must not contain null bytes in %s on line %d
43-
bool(false)
44+
OCILob::export(): Argument #1 ($filename) must not contain any null bytes

0 commit comments

Comments
 (0)