xref: /PHP-7.4/ext/oci8/tests/bug72524.phpt (revision 26dfce7f)
1--TEST--
2Bug #72524 (Binding null values triggers ORA-24816 error)
3--SKIPIF--
4<?php
5$target_dbs = array('oracledb' => true, 'timesten' => true);  // test runs on these DBs
6require(__DIR__.'/skipif.inc');
7?>
8--FILE--
9<?php
10
11require(__DIR__.'/connect.inc');
12
13// Initialize
14
15$stmtarray = array(
16         "CREATE TABLE mytable (clob_col CLOB DEFAULT NULL, varchar2_col VARCHAR2(255) DEFAULT NULL)"
17);
18
19oci8_test_sql_execute($c, $stmtarray);
20
21// Run test
22
23$sql = "INSERT INTO mytable VALUES (:clob_col, :varchar2_col)";
24
25echo "Test 1 - P1 Value: NULL  P1 Length: Default  P1 Type: Default  P2 Value: NULL P2 Length: Default  P2 Type: Default\n";
26$stmt = oci_parse($c, $sql);
27
28$clob = NULL;
29$varchar2 = NULL;
30oci_bind_by_name($stmt, ':clob_col', $clob);
31oci_bind_by_name($stmt, ':varchar2_col', $varchar2);
32
33var_dump(oci_execute($stmt));
34
35echo "Test 2 - P1 Value: ''    P1 Length: Default  P1 Type: Default  P2 Value: ''   P2 Length: Default  P2 Type: Default\n";
36
37$clob = '';
38$varchar2 = '';
39oci_bind_by_name($stmt, ':clob_col', $clob);
40oci_bind_by_name($stmt, ':varchar2_col', $varchar2);
41
42var_dump(oci_execute($stmt));
43
44echo "Test 3 - P1 Value: 'abc' P1 Length: 0        P1 Type: Default  P2 Value: ''   P2 Length: 0        P2 Type: Default\n";
45$clob = 'abc';
46$varchar2 = 'abc';
47oci_bind_by_name($stmt, ':clob_col', $clob, 0);
48oci_bind_by_name($stmt, ':varchar2_col', $varchar2, 0);
49
50var_dump(oci_execute($stmt));
51
52echo "Test 4 - P1 Value: NULL  P1 Length: -1       P1 Type: SQLT_LNG P2 Value: NULL P2 Length: -1       P2 Type:Default\n";
53$clob = NULL;
54$varchar2 = NULL;
55oci_bind_by_name($stmt, ':clob_col', $clob, -1, SQLT_LNG);
56oci_bind_by_name($stmt, ':varchar2_col', $varchar2, -1, SQLT_LNG);
57
58var_dump(oci_execute($stmt));
59
60echo "Test 5 - P1 Value: NULL  P1 Length: 0        P1 Type: SQLT_LNG P2 Value: NULL P2 Length: 0        P2 Type:Default\n";
61$clob = NULL;
62$varchar2 = NULL;
63oci_bind_by_name($stmt, ':clob_col', $clob, 0, SQLT_LNG);
64oci_bind_by_name($stmt, ':varchar2_col', $varchar2, 0, SQLT_LNG);
65
66
67var_dump(oci_execute($stmt));
68
69// Cleanup
70
71$stmtarray = array(
72    "DROP TABLE mytable"
73);
74
75oci8_test_sql_execute($c, $stmtarray);
76
77?>
78===DONE===
79<?php exit(0); ?>
80--EXPECTF--
81Test 1 - P1 Value: NULL  P1 Length: Default  P1 Type: Default  P2 Value: NULL P2 Length: Default  P2 Type: Default
82bool(true)
83Test 2 - P1 Value: ''    P1 Length: Default  P1 Type: Default  P2 Value: ''   P2 Length: Default  P2 Type: Default
84bool(true)
85Test 3 - P1 Value: 'abc' P1 Length: 0        P1 Type: Default  P2 Value: ''   P2 Length: 0        P2 Type: Default
86bool(true)
87Test 4 - P1 Value: NULL  P1 Length: -1       P1 Type: SQLT_LNG P2 Value: NULL P2 Length: -1       P2 Type:Default
88
89Warning: oci_execute(): ORA-24816: %s in %s on line %d
90bool(false)
91Test 5 - P1 Value: NULL  P1 Length: 0        P1 Type: SQLT_LNG P2 Value: NULL P2 Length: 0        P2 Type:Default
92
93Warning: oci_execute(): ORA-24816: %s in %s on line %d
94bool(false)
95===DONE===
96