xref: /PHP-7.0/ext/oci8/tests/bug72524.phpt (revision f5552247)
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(dirname(__FILE__).'/skipif.inc');
7?>
8--FILE--
9
10<?php
11
12require(dirname(__FILE__).'/connect.inc');
13
14// Initialize
15
16$stmtarray = array(
17         "CREATE TABLE mytable (clob_col CLOB DEFAULT NULL, varchar2_col VARCHAR2(255) DEFAULT NULL)"
18);
19
20oci8_test_sql_execute($c, $stmtarray);
21
22// Run test
23
24$sql = "INSERT INTO mytable VALUES (:clob_col, :varchar2_col)";
25
26echo "Test 1 - P1 Value: NULL  P1 Length: Default  P1 Type: Default  P2 Value: NULL P2 Length: Default  P2 Type: Default\n";
27$stmt = oci_parse($c, $sql);
28
29$clob = NULL;
30$varchar2 = NULL;
31oci_bind_by_name($stmt, ':clob_col', $clob);
32oci_bind_by_name($stmt, ':varchar2_col', $varchar2);
33
34var_dump(oci_execute($stmt));
35
36echo "Test 2 - P1 Value: ''    P1 Length: Default  P1 Type: Default  P2 Value: ''   P2 Length: Default  P2 Type: Default\n";
37
38$clob = '';
39$varchar2 = '';
40oci_bind_by_name($stmt, ':clob_col', $clob);
41oci_bind_by_name($stmt, ':varchar2_col', $varchar2);
42
43var_dump(oci_execute($stmt));
44
45echo "Test 3 - P1 Value: 'abc' P1 Length: 0        P1 Type: Default  P2 Value: ''   P2 Length: 0        P2 Type: Default\n";
46$clob = 'abc';
47$varchar2 = 'abc';
48oci_bind_by_name($stmt, ':clob_col', $clob, 0);
49oci_bind_by_name($stmt, ':varchar2_col', $varchar2, 0);
50
51var_dump(oci_execute($stmt));
52
53echo "Test 4 - P1 Value: NULL  P1 Length: -1       P1 Type: SQLT_LNG P2 Value: NULL P2 Length: -1       P2 Type:Default\n";
54$clob = NULL;
55$varchar2 = NULL;
56oci_bind_by_name($stmt, ':clob_col', $clob, -1, SQLT_LNG);
57oci_bind_by_name($stmt, ':varchar2_col', $varchar2, -1, SQLT_LNG);
58
59var_dump(oci_execute($stmt));
60
61echo "Test 5 - P1 Value: NULL  P1 Length: 0        P1 Type: SQLT_LNG P2 Value: NULL P2 Length: 0        P2 Type:Default\n";
62$clob = NULL;
63$varchar2 = NULL;
64oci_bind_by_name($stmt, ':clob_col', $clob, 0, SQLT_LNG);
65oci_bind_by_name($stmt, ':varchar2_col', $varchar2, 0, SQLT_LNG);
66
67
68var_dump(oci_execute($stmt));
69
70// Cleanup
71
72$stmtarray = array(
73    "DROP TABLE mytable"
74);
75
76oci8_test_sql_execute($c, $stmtarray);
77
78?>
79===DONE===
80<?php exit(0); ?>
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===DONE===
97