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