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