Skip to content

Tweaks and test updates for PR 6116 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/oci8/oci8.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -718,13 +718,13 @@ public function getbuffering() {}
* @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
Expand Down
6 changes: 3 additions & 3 deletions ext/oci8/oci8_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: b795b3009f220d578fc93134bd9f07dd685b6493 */
* 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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 9 additions & 7 deletions ext/oci8/oci8_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -258,7 +260,7 @@ PHP_FUNCTION(oci_lob_save)
}

if (offset < 0) {
zend_argument_value_error(3, "must be greater than or equal to 0");
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
RETURN_THROWS();
}

Expand Down Expand Up @@ -350,7 +352,7 @@ PHP_FUNCTION(oci_lob_read)
}

if (length <= 0) {
zend_argument_value_error(2, "must be greater than 0");
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0");
RETURN_THROWS();
}

Expand Down Expand Up @@ -600,7 +602,7 @@ PHP_FUNCTION(oci_lob_truncate)
}

if (trim_length < 0) {
zend_argument_value_error(2, "must be greater than or equal to zero");
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
RETURN_THROWS();
}

Expand Down Expand Up @@ -635,14 +637,14 @@ PHP_FUNCTION(oci_lob_erase)
if (offset_is_null) {
offset = -1;
} else if (offset < 0) {
zend_argument_value_error(2, "must be greater than or equal to 0");
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) {
zend_argument_value_error(3, "must be greater than or equal to 0");
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
RETURN_THROWS();
}

Expand Down Expand Up @@ -833,14 +835,14 @@ PHP_FUNCTION(oci_lob_export)
if (start_is_null) {
start = -1;
} else if (start < 0) {
zend_argument_value_error(3, "must be greater than or equal to 0");
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) {
zend_argument_value_error(4, "must be greater than or equal to 0");
zend_argument_value_error(ERROR_ARG_POS(4), "must be greater than or equal to 0");
RETURN_THROWS();
}

Expand Down
8 changes: 6 additions & 2 deletions ext/oci8/tests/array_bind_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions ext/oci8/tests/define1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Binary file modified ext/oci8/tests/lob_003.phpt
Binary file not shown.
Binary file modified ext/oci8/tests/lob_020.phpt
Binary file not shown.
10 changes: 7 additions & 3 deletions ext/oci8/tests/lob_022.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
21 changes: 13 additions & 8 deletions ext/oci8/tests/lob_027.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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';
Expand Down Expand Up @@ -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
35 changes: 27 additions & 8 deletions ext/oci8/tests/lob_035.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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) ""
Expand Down
11 changes: 7 additions & 4 deletions ext/oci8/tests/lob_042.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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)

Expand All @@ -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
23 changes: 12 additions & 11 deletions ext/oci8/tests/null_byte_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Loading