1--TEST-- 2PL/SQL oci_bind_by_name with SQLT_AFC aka CHAR to CHAR parameter 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 "create or replace function bind_char_3_fn(p1 char) return char as begin return p1; end;", 25); 26 27oci8_test_sql_execute($c, $stmtarray); 28 29// Run Test 30 31echo "Test 1.1 In Length: default. In Type: default. Out Length: default. Out Type: default\n"; 32 33$s = oci_parse($c, "begin :bv2 := bind_char_3_fn(:bv1); end;"); 34$bv1 = 'abc'; 35$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2); 36if ($r) 37 do_e($s); 38var_dump($bv1, $bv2); 39 40echo "Test 1.2 In Length: default. In Type: default. Out Length: 10. Out Type: default\n"; 41 42$bv1 = 'abc'; 43$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2, 10); 44if ($r) 45 do_e($s); 46var_dump($bv1, $bv2); 47 48 49echo "Test 1.3 In Length: -1. In Type: AFC. Out Length: 10. Out Type: default\n"; 50 51$bv1 = 'abc'; 52$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10); 53if ($r) 54 do_e($s); 55var_dump($bv1, $bv2); 56 57 58 59echo "Test 1.4 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC\n"; 60 61$bv1 = 'abc'; 62$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC); 63if ($r) 64 do_e($s); 65var_dump($bv1, $bv2); 66 67 68echo "Test 1.5 In Length: strlen. In Type: AFC. Out Length: strlen(input). Out Type: AFC\n"; 69 70$bv1 = 'abc'; 71$r = oci_bind_by_name($s, ':bv1', $bv1, strlen($bv1), SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, strlen($bv1), SQLT_AFC); 72if ($r) 73 do_e($s); 74var_dump($bv1, $bv2); 75 76 77echo "Test 1.6 In Length: strlen. In Type: AFC. Out Length: strlen(input)-1. Out Type: AFC\n"; 78 79$bv1 = 'abc'; 80$r = oci_bind_by_name($s, ':bv1', $bv1, strlen($bv1), SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, strlen($bv1)-1, SQLT_AFC); 81if ($r) 82 do_e($s); 83var_dump($bv1, $bv2); 84 85 86echo "Test 1.7 In Length: strlen. In Type: AFC. Out Length: strlen(input)+1. Out Type: AFC\n"; 87 88$bv1 = 'abc'; 89$r = oci_bind_by_name($s, ':bv1', $bv1, strlen($bv1), SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, strlen($bv1)+1, SQLT_AFC); 90if ($r) 91 do_e($s); 92var_dump($bv1, $bv2); 93 94 95echo "\n\nTests with ''\n\n"; 96 97echo "Test 2.1 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC\n"; 98 99$bv1 = ''; 100$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC); 101if ($r) 102 do_e($s); 103var_dump($bv1, $bv2); 104 105 106echo "Test 2.2 In Length: default. In Type: default. Out Length: 10. Out Type: default\n"; 107 108$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2, 10); 109if ($r) 110 do_e($s); 111var_dump($bv1, $bv2); 112 113 114 115echo "Test 2.3 In Length: -1. In Type: AFC. Out Length: 10. Out Type: default\n"; 116 117$bv1 = ''; 118$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10); 119if ($r) 120 do_e($s); 121var_dump($bv1, $bv2); 122 123 124 125echo "Test 2.4 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC\n"; 126 127$bv1 = ''; 128$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC); 129if ($r) 130 do_e($s); 131var_dump($bv1, $bv2); 132 133 134 135echo "Test 2.5 In Length: -1. In Type: AFC. Out Length: 0. Out Type: AFC\n"; 136 137$bv1 = ''; 138$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 0, SQLT_AFC); 139if ($r) 140 do_e($s); 141var_dump($bv1, $bv2); 142 143 144 145echo "Test 2.6 In Length: 0. In Type: AFC. Out Length: 0. Out Type: AFC\n"; 146 147$bv1 = ''; 148$r = oci_bind_by_name($s, ':bv1', $bv1, 0, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 0, SQLT_AFC); 149if ($r) 150 do_e($s); 151var_dump($bv1, $bv2); 152 153 154 155echo "Test 2.7 In Length: 1. In Type: AFC. Out Length: 1. Out Type: AFC\n"; 156 157$bv1 = ''; 158$r = oci_bind_by_name($s, ':bv1', $bv1, 1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 1, SQLT_AFC); 159if ($r) 160 do_e($s); 161var_dump($bv1, $bv2); 162 163 164 165echo "\n\nTests with NULL\n"; 166 167echo "Test 3.1 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC\n"; 168 169$bv1 = null; 170$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC); 171if ($r) 172 do_e($s); 173var_dump($bv1, $bv2); 174 175 176echo "Test 3.2 In Length: default. In Type: default. Out Length: 10. Out Type: default\n"; 177 178$bv1 = null; 179$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2, 10); 180if ($r) 181 do_e($s); 182var_dump($bv1, $bv2); 183 184 185 186echo "Test 3.3 In Length: -1. In Type: AFC. Out Length: 10. Out Type: default\n"; 187 188$bv1 = null; 189$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10); 190if ($r) 191 do_e($s); 192var_dump($bv1, $bv2); 193 194 195 196echo "Test 3.4 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC\n"; 197 198$bv1 = null; 199$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC); 200if ($r) 201 do_e($s); 202var_dump($bv1, $bv2); 203 204 205echo "Test 3.5 In Length: -1. In Type: AFC. Out Length: 0. Out Type: AFC\n"; 206 207$bv1 = null; 208$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 0, SQLT_AFC); 209if ($r) 210 do_e($s); 211var_dump($bv1, $bv2); 212 213 214 215echo "Test 3.6 In Length: -1. In Type: AFC. Out Length: 1. Out Type: AFC\n"; 216 217$bv1 = null; 218$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 1, SQLT_AFC); 219if ($r) 220 do_e($s); 221var_dump($bv1, $bv2); 222 223 224function do_e($s) 225{ 226 echo " Executing:\n"; 227 228 $r = @oci_execute($s); 229 if (!$r) { 230 $m = oci_error($s); 231 echo " Oci_execute error ORA-".$m['code']."\n"; 232 return; 233 } 234} 235 236// Cleanup 237 238$stmtarray = array( 239 "drop function bind_char_3_fn" 240); 241 242oci8_test_sql_execute($c, $stmtarray); 243 244echo "Done\n"; 245 246?> 247--EXPECT-- 248Test 1.1 In Length: default. In Type: default. Out Length: default. Out Type: default 249 Executing: 250 Oci_execute error ORA-6502 251string(3) "abc" 252NULL 253Test 1.2 In Length: default. In Type: default. Out Length: 10. Out Type: default 254 Executing: 255string(3) "abc" 256string(3) "abc" 257Test 1.3 In Length: -1. In Type: AFC. Out Length: 10. Out Type: default 258 Executing: 259string(3) "abc" 260string(3) "abc" 261Test 1.4 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC 262 Executing: 263string(3) "abc" 264string(10) "abc " 265Test 1.5 In Length: strlen. In Type: AFC. Out Length: strlen(input). Out Type: AFC 266 Executing: 267string(3) "abc" 268string(3) "abc" 269Test 1.6 In Length: strlen. In Type: AFC. Out Length: strlen(input)-1. Out Type: AFC 270 Executing: 271 Oci_execute error ORA-6502 272string(3) "abc" 273string(3) "abc" 274Test 1.7 In Length: strlen. In Type: AFC. Out Length: strlen(input)+1. Out Type: AFC 275 Executing: 276string(3) "abc" 277string(4) "abc " 278 279 280Tests with '' 281 282Test 2.1 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC 283 Executing: 284string(0) "" 285NULL 286Test 2.2 In Length: default. In Type: default. Out Length: 10. Out Type: default 287 Executing: 288string(0) "" 289NULL 290Test 2.3 In Length: -1. In Type: AFC. Out Length: 10. Out Type: default 291 Executing: 292string(0) "" 293NULL 294Test 2.4 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC 295 Executing: 296string(0) "" 297NULL 298Test 2.5 In Length: -1. In Type: AFC. Out Length: 0. Out Type: AFC 299 Executing: 300string(0) "" 301NULL 302Test 2.6 In Length: 0. In Type: AFC. Out Length: 0. Out Type: AFC 303 Executing: 304string(0) "" 305NULL 306Test 2.7 In Length: 1. In Type: AFC. Out Length: 1. Out Type: AFC 307 Executing: 308string(0) "" 309NULL 310 311 312Tests with NULL 313Test 3.1 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC 314 Executing: 315NULL 316NULL 317Test 3.2 In Length: default. In Type: default. Out Length: 10. Out Type: default 318 Executing: 319NULL 320NULL 321Test 3.3 In Length: -1. In Type: AFC. Out Length: 10. Out Type: default 322 Executing: 323NULL 324NULL 325Test 3.4 In Length: -1. In Type: AFC. Out Length: 10. Out Type: AFC 326 Executing: 327NULL 328NULL 329Test 3.5 In Length: -1. In Type: AFC. Out Length: 0. Out Type: AFC 330 Executing: 331NULL 332NULL 333Test 3.6 In Length: -1. In Type: AFC. Out Length: 1. Out Type: AFC 334 Executing: 335NULL 336NULL 337Done 338