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