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