xref: /PHP-8.3/ext/oci8/tests/bind_sqltafc.phpt (revision a53e5617)
1--TEST--
2Bind tests with SQLT_AFC
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11
12require __DIR__.'/connect.inc';
13
14// Initialization
15
16$stmtarray = array(
17    "drop table bind_sqltafc_tab",
18    "create table bind_sqltafc_tab (id number, char_t char(1), char_t10 char(10), varchar2_t10 varchar2(10), number_t number)",
19    "insert into bind_sqltafc_tab values (0, 'a', 'abcd', 'efghij', 1.1)"
20);
21
22oci8_test_sql_execute($c, $stmtarray);
23
24// Run Test
25
26function q($c, $id)
27{
28    $s = oci_parse($c, "select * from bind_sqltafc_tab where id = $id");
29    oci_execute($s);
30    oci_fetch_all($s, $r);
31    var_dump($r);
32}
33
34echo "Test 0 - base table creation without binds\n";
35
36q($c, 0);
37
38echo "\nTest 1 - successful insert\n";
39
40$s = oci_parse($c, "INSERT INTO bind_sqltafc_tab (id, char_t, char_t10, varchar2_t10, number_t) VALUES (1, :c2, :c3, :c4, :c5)");
41$c2 = "H";
42$c3 = "AAAAAAAAAA";  // max length allowed in column
43$c4 = "BBBBBBBBBB";  // max length allowed in column
44$c5 = "123.45";
45oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC);
46oci_bind_by_name($s, ":c3", $c3, -1, SQLT_AFC);
47oci_bind_by_name($s, ":c4", $c4, -1, SQLT_AFC);
48oci_bind_by_name($s, ":c5", $c5, -1, SQLT_AFC);
49oci_execute($s);
50
51q($c, 1);
52
53echo "\nTest 2 - Empty Strings\n";
54
55$s = oci_parse($c, "INSERT INTO bind_sqltafc_tab (id, char_t, char_t10, varchar2_t10, number_t) VALUES (5, :c2, :c3, :c4, :c5)");
56$c2 = "";
57$c3 = "";
58$c4 = "";
59$c5 = "";
60oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC);
61oci_bind_by_name($s, ":c3", $c3, -1, SQLT_AFC);
62oci_bind_by_name($s, ":c4", $c4, -1, SQLT_AFC);
63oci_bind_by_name($s, ":c5", $c5, -1, SQLT_AFC);
64oci_execute($s);
65
66q($c, 5);
67
68echo "\nTest 3 - NULLs\n";
69
70$s = oci_parse($c, "INSERT INTO bind_sqltafc_tab (id, char_t, char_t10, varchar2_t10, number_t) VALUES (6, :c2, :c3, :c4, :c5)");
71$c2 = null;
72$c3 = null;
73$c4 = null;
74$c5 = null;
75oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC);
76oci_bind_by_name($s, ":c3", $c3, -1, SQLT_AFC);
77oci_bind_by_name($s, ":c4", $c4, -1, SQLT_AFC);
78oci_bind_by_name($s, ":c5", $c5, -1, SQLT_AFC);
79oci_execute($s);
80
81q($c, 6);
82
83// Clean up
84
85$stmtarray = array(
86    "drop table bind_sqltafc_tab"
87);
88
89oci8_test_sql_execute($c, $stmtarray);
90
91oci_close($c);
92
93?>
94--EXPECT--
95Test 0 - base table creation without binds
96array(5) {
97  ["ID"]=>
98  array(1) {
99    [0]=>
100    string(1) "0"
101  }
102  ["CHAR_T"]=>
103  array(1) {
104    [0]=>
105    string(1) "a"
106  }
107  ["CHAR_T10"]=>
108  array(1) {
109    [0]=>
110    string(10) "abcd      "
111  }
112  ["VARCHAR2_T10"]=>
113  array(1) {
114    [0]=>
115    string(6) "efghij"
116  }
117  ["NUMBER_T"]=>
118  array(1) {
119    [0]=>
120    string(3) "1.1"
121  }
122}
123
124Test 1 - successful insert
125array(5) {
126  ["ID"]=>
127  array(1) {
128    [0]=>
129    string(1) "1"
130  }
131  ["CHAR_T"]=>
132  array(1) {
133    [0]=>
134    string(1) "H"
135  }
136  ["CHAR_T10"]=>
137  array(1) {
138    [0]=>
139    string(10) "AAAAAAAAAA"
140  }
141  ["VARCHAR2_T10"]=>
142  array(1) {
143    [0]=>
144    string(10) "BBBBBBBBBB"
145  }
146  ["NUMBER_T"]=>
147  array(1) {
148    [0]=>
149    string(6) "123.45"
150  }
151}
152
153Test 2 - Empty Strings
154array(5) {
155  ["ID"]=>
156  array(1) {
157    [0]=>
158    string(1) "5"
159  }
160  ["CHAR_T"]=>
161  array(1) {
162    [0]=>
163    NULL
164  }
165  ["CHAR_T10"]=>
166  array(1) {
167    [0]=>
168    NULL
169  }
170  ["VARCHAR2_T10"]=>
171  array(1) {
172    [0]=>
173    NULL
174  }
175  ["NUMBER_T"]=>
176  array(1) {
177    [0]=>
178    NULL
179  }
180}
181
182Test 3 - NULLs
183array(5) {
184  ["ID"]=>
185  array(1) {
186    [0]=>
187    string(1) "6"
188  }
189  ["CHAR_T"]=>
190  array(1) {
191    [0]=>
192    NULL
193  }
194  ["CHAR_T10"]=>
195  array(1) {
196    [0]=>
197    NULL
198  }
199  ["VARCHAR2_T10"]=>
200  array(1) {
201    [0]=>
202    NULL
203  }
204  ["NUMBER_T"]=>
205  array(1) {
206    [0]=>
207    NULL
208  }
209}
210