Skip to content

Commit f361d9e

Browse files
committed
MFH: fix #39988 (type argument of oci_define_by_name() is ignored)
patch and tests by Chris Jones
1 parent 12d54fa commit f361d9e

9 files changed

+435
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PHP NEWS
1818
ARRAY_AS_PROPS). (Ilia)
1919
- Fixed bug #40002 (Try/Catch performs poorly). (Dmitry)
2020
- Fixed bug #39990 (Cannot "foreach" over overloaded properties). (Dmitry)
21+
- Fixed bug #39988 (type argument of oci_define_by_name() is ignored).
22+
(Chris Jones, Tony)
2123
- Fixed bug #39979 (PGSQL_CONNECT_FORCE_NEW will causes next connect to
2224
establish a new connection). (Ilia)
2325
- Fixed bug #39504 (xmlwriter_write_dtd_entity() creates Attlist tag,

ext/oci8/oci8_interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ PHP_FUNCTION(oci_define_by_name)
5252
zval *stmt, *var;
5353
char *name;
5454
int name_len;
55-
long type = SQLT_CHR;
55+
long type = 0;
5656
php_oci_statement *statement;
5757
php_oci_define *define, *tmp_define;
5858

ext/oci8/oci8_statement.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,11 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC)
506506

507507
/* find a user-setted define */
508508
if (statement->defines) {
509-
zend_hash_find(statement->defines,outcol->name,outcol->name_len,(void **) &outcol->define);
509+
if (zend_hash_find(statement->defines,outcol->name,outcol->name_len,(void **) &outcol->define) == SUCCESS) {
510+
if (outcol->define->type) {
511+
outcol->data_type = outcol->define->type;
512+
}
513+
}
510514
}
511515

512516
buf = 0;

ext/oci8/tests/array_bind_005.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ var_dump($array);
5959
echo "Done\n";
6060
?>
6161
--EXPECTF--
62-
Warning: oci_execute(): ORA-01405: fetched column value is NULL in %s on line %d
6362
array(5) {
6463
[0]=>
6564
string(0) ""

ext/oci8/tests/coll_019.phpt

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
--TEST--
2+
Test collection Oracle error handling collections and numbers (2)
3+
--SKIPIF--
4+
<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
5+
--FILE--
6+
<?php
7+
8+
require dirname(__FILE__)."/connect.inc";
9+
10+
$ora_sql = "DROP TYPE ".$type_name;;
11+
$statement = oci_parse($c,$ora_sql);
12+
@oci_execute($statement);
13+
14+
15+
echo "Test 0\n";
16+
$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF BLOB";
17+
$statement = oci_parse($c,$ora_sql);
18+
oci_execute($statement);
19+
20+
$coll1 = oci_new_collection($c, $type_name);
21+
22+
var_dump($coll1->append('a long string')); // invalid type for append
23+
var_dump($coll1->assignElem(1, 'a long string')); // invalid type for assignelem()
24+
var_dump($coll1->getElem(0));
25+
26+
require dirname(__FILE__)."/drop_type.inc";
27+
28+
echo "Test 1\n";
29+
$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF NUMBER";
30+
$statement = oci_parse($c,$ora_sql);
31+
oci_execute($statement);
32+
33+
$coll1 = oci_new_collection($c, $type_name);
34+
35+
var_dump($coll1->assignElem(1, null)); // invalid location for null
36+
var_dump($coll1->getElem(0));
37+
38+
echo "Test 2\n";
39+
var_dump($coll1->assignElem(1, 1234)); // invalid location for number
40+
var_dump($coll1->getElem(0));
41+
42+
require dirname(__FILE__)."/drop_type.inc";
43+
44+
echo "Test 3\n";
45+
$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF VARCHAR2(1)";
46+
$statement = oci_parse($c,$ora_sql);
47+
oci_execute($statement);
48+
49+
$coll1 = oci_new_collection($c, $type_name);
50+
51+
var_dump($coll1->assignElem(1, 'abc')); // invalid location for string
52+
var_dump($coll1->getElem(0));
53+
54+
require dirname(__FILE__)."/drop_type.inc";
55+
56+
echo "Test 4\n";
57+
$ora_sql = "CREATE TYPE ".$type_name." AS TABLE OF DATE";
58+
$statement = oci_parse($c,$ora_sql);
59+
oci_execute($statement);
60+
61+
$coll1 = oci_new_collection($c, $type_name);
62+
63+
var_dump($coll1->append(1)); // invalid date format
64+
var_dump($coll1->assignElem(1, '01-JAN-06')); // invalid location for date
65+
var_dump($coll1->getElem(0));
66+
67+
require dirname(__FILE__)."/drop_type.inc";
68+
69+
echo "Done\n";
70+
71+
?>
72+
--EXPECTF--
73+
Test 0
74+
75+
Notice: OCI-Collection::append(): Unknown or unsupported type of element: 113 in %s on line %d
76+
bool(false)
77+
78+
Notice: OCI-Collection::assignelem(): Unknown or unsupported type of element: 113 in %s on line %d
79+
bool(false)
80+
bool(false)
81+
Test 1
82+
83+
Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d
84+
bool(false)
85+
bool(false)
86+
Test 2
87+
88+
Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d
89+
bool(false)
90+
bool(false)
91+
Test 3
92+
93+
Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d
94+
bool(false)
95+
bool(false)
96+
Test 4
97+
98+
Warning: OCI-Collection::append(): OCI-01840: input value not long enough for date format in %s on line %d
99+
bool(false)
100+
101+
Warning: OCI-Collection::assignelem(): OCI-22165: given index [1] must be in the range of %s in %s on line %d
102+
bool(false)
103+
bool(false)
104+
Done

ext/oci8/tests/define2.phpt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
--TEST--
2+
Test oci_define_by_name types
3+
--SKIPIF--
4+
<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
5+
--FILE--
6+
<?php
7+
8+
require dirname(__FILE__)."/connect.inc";
9+
10+
$stmt = oci_parse($c, "create table phptestrawtable( id number(10), fileimage raw(1000))");
11+
oci_execute($stmt);
12+
13+
$stmt = oci_parse ($c, "insert into phptestrawtable (id, fileimage) values (:id, :fileimage)");
14+
$i=1;
15+
$fileimage = file_get_contents( dirname(__FILE__)."/test.gif");
16+
$fileimage = substr($fileimage, 0, 300);
17+
var_dump(md5($fileimage));
18+
19+
oci_bind_by_name( $stmt, ":id", $i, -1);
20+
oci_bind_by_name( $stmt, ":fileimage", $fileimage, -1, SQLT_BIN);
21+
oci_execute($stmt, OCI_DEFAULT);
22+
oci_commit($c);
23+
24+
echo "Test 1\n";
25+
$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
26+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
27+
oci_execute($stmt);
28+
29+
while (oci_fetch($stmt)) {
30+
var_dump($fi);
31+
echo "file md5:" . md5($fi) . "\n";
32+
}
33+
34+
echo "Test 2\n";
35+
$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
36+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
37+
oci_execute($stmt);
38+
39+
while (oci_fetch($stmt)) {
40+
var_dump($fi);
41+
echo "file md5:" . md5($fi) . "\n";
42+
}
43+
44+
echo "Test 3 - test repeatability\n";
45+
$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
46+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_STR));
47+
oci_execute($stmt);
48+
49+
while (oci_fetch($stmt)) {
50+
var_dump($fi);
51+
echo "file md5:" . md5($fi) . "\n";
52+
}
53+
54+
echo "Test 4 - wrong type\n";
55+
$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
56+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_RSET));
57+
oci_execute($stmt);
58+
59+
while (oci_fetch($stmt)) {
60+
var_dump($fi);
61+
echo "file md5:" . md5($fi) . "\n";
62+
}
63+
64+
$stmt = oci_parse($c, "drop table phptestrawtable");
65+
oci_execute($stmt);
66+
67+
echo "Done\n";
68+
?>
69+
--EXPECTF--
70+
string(32) "88b274d7a257ac6f70435b83abd4e26e"
71+
Test 1
72+
bool(true)
73+
string(300) "GIF89%s"
74+
file md5:88b274d7a257ac6f70435b83abd4e26e
75+
Test 2
76+
bool(true)
77+
string(300) "GIF89%s"
78+
file md5:88b274d7a257ac6f70435b83abd4e26e
79+
Test 3 - test repeatability
80+
bool(true)
81+
string(600) "47494638396178004300E66A007F82B839374728252ACCCDE2A1A4CBD3D5E7B2B4D44342588386B98283B35252729092C2C2C4DEAAACD04C4B635B5C83DDDEEC3B383C6E71A56A6D9D61638D7579B17B7EB5E5E6F0999CC68C8DC1B9BAD96B6B924E4E6B7174A97A7AA3888BBD7274A37473988E90C15A5B7EE2E3EF7B7DADA4A5D06D70A27276AC9596C8BBBDD97478AE8588BB9295C3D8D9EA9292C46466926B6E9FA5A8CE9496C52E2B2F535168B3B4D76C6A8C5C5B768A8DBF666896686A9A9C9FC8312E39AEB0D39C9CCD5556789EA1CA9699C58182AF6769973F3D50BCBEDA5E60899899C88C8EBF898ABA57587CB6B7D7D5D7E8221E206C6F9ECED0E4BFC0DC777BB47678A75F5E7D9999CC6E6F987377AE221E1FFFFFFF908E8F595657C7C6C7EEEEF5D5D4D5F6F6"
82+
file md5:80bb3201e2a8bdcb8ab3e1a44a82bb8a
83+
Test 4 - wrong type
84+
bool(true)
85+
86+
Warning: oci_fetch(): ORA-00932: inconsistent datatypes%s on line %d
87+
Done

ext/oci8/tests/define3.phpt

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
--TEST--
2+
Test oci_define_by_name() LOB descriptor
3+
--SKIPIF--
4+
<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
5+
--FILE--
6+
<?php
7+
8+
require dirname(__FILE__)."/connect.inc";
9+
10+
$stmt = oci_parse($c, "create table phpdefblobtable( id number(10), fileimage blob)");
11+
oci_execute($stmt);
12+
13+
// Load data
14+
$stmt = oci_parse ($c, "insert into phpdefblobtable (id, fileimage) values (:id, empty_blob()) returning fileimage into :fileimage");
15+
$fileimage = oci_new_descriptor($c,OCI_D_LOB);
16+
oci_bind_by_name($stmt,":id",$id);
17+
oci_bind_by_name($stmt,":fileimage",$fileimage,-1,OCI_B_BLOB);
18+
$id = 1;
19+
oci_execute($stmt, OCI_DEFAULT);
20+
$fileimage->savefile(dirname(__FILE__)."/test.gif");
21+
$data = $fileimage->load();
22+
var_dump(md5($data)); // original md5
23+
oci_commit($c);
24+
25+
// New row with different data
26+
$id = 2;
27+
$data = strrev($data);
28+
var_dump(md5($data));
29+
oci_execute($stmt, OCI_DEFAULT);
30+
$fileimage->save($data);
31+
oci_commit($c);
32+
33+
echo "Test 1\n";
34+
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
35+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $f));
36+
oci_execute($stmt);
37+
38+
while (oci_fetch($stmt)) {
39+
var_dump($f);
40+
echo "file md5:" . md5($f->load()) . "\n";
41+
}
42+
43+
echo "Test 2\n";
44+
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
45+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_STR));
46+
oci_execute($stmt);
47+
48+
while (oci_fetch($stmt)) {
49+
echo "file md5:" . md5($outdata) . "\n";
50+
}
51+
52+
echo "Test 3\n";
53+
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
54+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_BIN));
55+
oci_execute($stmt);
56+
57+
while (oci_fetch($stmt)) {
58+
echo "file md5:" . md5($outdata) . "\n";
59+
}
60+
61+
echo "Test 4\n";
62+
$fid = oci_new_descriptor($c,OCI_D_LOB);
63+
$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
64+
var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fid));
65+
oci_execute($stmt);
66+
67+
while (oci_fetch($stmt)) {
68+
echo "file md5:" . md5($fid->load()) . "\n";
69+
}
70+
71+
$stmt = oci_parse($c, "drop table phpdefblobtable");
72+
oci_execute($stmt);
73+
74+
echo "Done\n";
75+
76+
?>
77+
--EXPECTF--
78+
string(32) "614fcbba1effb7caa27ef0ef25c27fcf"
79+
string(32) "06d4f219d946c74d748d43932cd9dcb2"
80+
Test 1
81+
bool(true)
82+
object(OCI-Lob)#%d (1) {
83+
["descriptor"]=>
84+
resource(%d) of type (oci8 descriptor)
85+
}
86+
file md5:614fcbba1effb7caa27ef0ef25c27fcf
87+
object(OCI-Lob)#%d (1) {
88+
["descriptor"]=>
89+
resource(%d) of type (oci8 descriptor)
90+
}
91+
file md5:06d4f219d946c74d748d43932cd9dcb2
92+
Test 2
93+
bool(true)
94+
95+
Warning: oci_fetch(): ORA-00932: %s on line %d
96+
Test 3
97+
bool(true)
98+
file md5:614fcbba1effb7caa27ef0ef25c27fcf
99+
file md5:06d4f219d946c74d748d43932cd9dcb2
100+
Test 4
101+
bool(true)
102+
file md5:614fcbba1effb7caa27ef0ef25c27fcf
103+
file md5:06d4f219d946c74d748d43932cd9dcb2
104+
Done
105+

0 commit comments

Comments
 (0)