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