1--TEST-- 2SELECT oci_bind_by_name with SQLT_AFC aka CHAR 3--SKIPIF-- 4<?php 5if (!extension_loaded('oci8')) die ("skip no oci8 extension"); 6require(dirname(__FILE__)."/connect.inc"); 7// The bind buffer size edge cases seem to change each DB version. 8preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches); 9if (!(isset($matches[0]) && $matches[1] < 12)) { 10 die("skip expected output only valid when using pre-Oracle 12c database"); 11} 12?> 13--ENV-- 14NLS_LANG= 15--FILE-- 16<?php 17 18// Output is for 32 bit client to 64bit 11.1.0.6 19 20require(dirname(__FILE__).'/connect.inc'); 21 22// Initialization 23 24$stmtarray = array( 25 "drop table bind_char_tab", 26 "create table bind_char_tab (id number, c1 char(10), c2 varchar2(10))", 27 "insert into bind_char_tab values (1, 'abc', NULL)", 28 "insert into bind_char_tab values (2, NULL, 'abc')", 29 "insert into bind_char_tab values (3, NULL, 'abc ')" 30); 31 32oci8_test_sql_execute($c, $stmtarray); 33 34// Run Test 35 36echo "*** Non-null Data Tests against CHAR***\n"; 37 38$bv1 = 'abc'; 39 40echo "Test 1.1: Type: default. Length: default\n"; 41$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv"); 42$r = oci_bind_by_name($s, ":bv", $bv1); 43if ($r) 44 do_e_q($s); 45 46echo "Test 1.2: Type: AFC. Length: default\n"; 47$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC); 48if ($r) 49 do_e_q($s); 50 51echo "Test 1.3: Type: AFC: Length: 0\n"; 52$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC); 53if ($r) 54 do_e_q($s); 55 56echo "Test 1.4: Type: AFC: Length: strlen\n"; 57$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC); 58if ($r) 59 do_e_q($s); 60 61echo "Test 1.5: Type: AFC. Length: strlen-1\n"; 62$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC); 63if ($r) 64 do_e_q($s); 65 66echo "Test 1.6: Type: AFC. Length: strlen+1\n"; 67$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC); 68if ($r) 69 do_e_q($s); 70 71echo "\n\n*** NULL data tests against CHAR ***\n"; 72 73$bv1 = null; 74 75echo "Test 2.1: Type: default. Length: default\n"; 76$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv"); 77$r = oci_bind_by_name($s, ":bv", $bv1); 78if ($r) 79 do_e_q($s); 80 81echo "Test 2.2: Type: AFC. Length: default\n"; 82$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC); 83if ($r) 84 do_e_q($s); 85 86echo "Test 2.3: Type: AFC: Length: 0\n"; 87$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC); 88if ($r) 89 do_e_q($s); 90 91echo "Test 2.4: Type: AFC: Length: strlen\n"; 92$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC); 93if ($r) 94 do_e_q($s); 95 96echo "Test 2.5: Type: AFC. Length: strlen-1\n"; 97$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC); 98if ($r) 99 do_e_q($s); 100 101echo "Test 2.6: Type: AFC. Length: strlen+1\n"; 102$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC); 103if ($r) 104 do_e_q($s); 105 106 107echo "\n\n*** Non-null Data Tests against VARCHAR2***\n"; 108 109$bv1 = 'abc'; 110 111echo "Test 3.1: Type: default. Length: default\n"; 112$s = oci_parse($c, "select * from bind_char_tab where c2 = :bv"); 113$r = oci_bind_by_name($s, ":bv", $bv1); 114if ($r) 115 do_e_q($s); 116 117echo "Test 3.2: Type: AFC. Length: default\n"; 118$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC); 119if ($r) 120 do_e_q($s); 121 122echo "Test 3.3: Type: AFC: Length: 0\n"; 123$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC); 124if ($r) 125 do_e_q($s); 126 127echo "Test 3.4: Type: AFC: Length: strlen\n"; 128$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC); 129if ($r) 130 do_e_q($s); 131 132echo "Test 3.5: Type: AFC. Length: strlen-1\n"; 133$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC); 134if ($r) 135 do_e_q($s); 136 137echo "Test 3.6: Type: AFC. Length: strlen+1\n"; 138$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC); 139if ($r) 140 do_e_q($s); 141 142 143echo "\n\n*** NULL data tests against VARCHAR2 ***\n"; 144 145$bv1 = null; 146 147echo "Test 4.1: Type: default. Length: default\n"; 148$s = oci_parse($c, "select * from bind_char_tab where c2 = :bv"); 149$r = oci_bind_by_name($s, ":bv", $bv1); 150if ($r) 151 do_e_q($s); 152 153echo "Test 4.2: Type: AFC. Length: default\n"; 154$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC); 155if ($r) 156 do_e_q($s); 157 158echo "Test 4.3: Type: AFC: Length: 0\n"; 159$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC); 160if ($r) 161 do_e_q($s); 162 163echo "Test 4.4: Type: AFC: Length: strlen\n"; 164$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC); 165if ($r) 166 do_e_q($s); 167 168echo "Test 4.5: Type: AFC. Length: strlen-1\n"; 169$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC); 170if ($r) 171 do_e_q($s); 172 173echo "Test 4.6: Type: AFC. Length: strlen+1\n"; 174$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC); 175if ($r) 176 do_e_q($s); 177 178 179 180function do_e_q($s) 181{ 182 echo " Querying:\n"; 183 184 $r = @oci_execute($s); 185 if (!$r) { 186 $m = oci_error($s); 187 echo " Oci_execute error ORA-".$m['code']." Exiting Query\n"; 188 return; 189 } 190 while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) { 191 foreach ($row as $item) { 192 echo " :" . $item . ":\n"; 193 } 194 } 195} 196 197// Cleanup 198$stmtarray = array( 199 "drop table bind_char_tab" 200); 201 202oci8_test_sql_execute($c, $stmtarray); 203 204echo "Done\n"; 205 206?> 207--EXPECT-- 208*** Non-null Data Tests against CHAR*** 209Test 1.1: Type: default. Length: default 210 Querying: 211Test 1.2: Type: AFC. Length: default 212 Querying: 213 :1: 214 :abc : 215 :: 216Test 1.3: Type: AFC: Length: 0 217 Querying: 218 Oci_execute error ORA-1460 Exiting Query 219Test 1.4: Type: AFC: Length: strlen 220 Querying: 221 :1: 222 :abc : 223 :: 224Test 1.5: Type: AFC. Length: strlen-1 225 Querying: 226 Oci_execute error ORA-1460 Exiting Query 227Test 1.6: Type: AFC. Length: strlen+1 228 Querying: 229 :1: 230 :abc : 231 :: 232 233 234*** NULL data tests against CHAR *** 235Test 2.1: Type: default. Length: default 236 Querying: 237Test 2.2: Type: AFC. Length: default 238 Querying: 239Test 2.3: Type: AFC: Length: 0 240 Querying: 241Test 2.4: Type: AFC: Length: strlen 242 Querying: 243Test 2.5: Type: AFC. Length: strlen-1 244 Querying: 245Test 2.6: Type: AFC. Length: strlen+1 246 Querying: 247 248 249*** Non-null Data Tests against VARCHAR2*** 250Test 3.1: Type: default. Length: default 251 Querying: 252 :2: 253 :: 254 :abc: 255Test 3.2: Type: AFC. Length: default 256 Querying: 257 :2: 258 :: 259 :abc: 260Test 3.3: Type: AFC: Length: 0 261 Querying: 262 Oci_execute error ORA-1460 Exiting Query 263Test 3.4: Type: AFC: Length: strlen 264 Querying: 265 :2: 266 :: 267 :abc: 268Test 3.5: Type: AFC. Length: strlen-1 269 Querying: 270 Oci_execute error ORA-1460 Exiting Query 271Test 3.6: Type: AFC. Length: strlen+1 272 Querying: 273 :2: 274 :: 275 :abc: 276 277 278*** NULL data tests against VARCHAR2 *** 279Test 4.1: Type: default. Length: default 280 Querying: 281Test 4.2: Type: AFC. Length: default 282 Querying: 283Test 4.3: Type: AFC: Length: 0 284 Querying: 285Test 4.4: Type: AFC: Length: strlen 286 Querying: 287Test 4.5: Type: AFC. Length: strlen-1 288 Querying: 289Test 4.6: Type: AFC. Length: strlen+1 290 Querying: 291Done 292