1--TEST-- 2Bind with SQLT_NUM 3--SKIPIF-- 4<?php 5if (!extension_loaded('oci8')) die("skip no oci8 extension"); 6preg_match('/^[[:digit:]]+/', oci_client_version(), $matches); 7if (!(isset($matches[0]) && $matches[0] >= 12)) { 8 die("skip works only with Oracle 12c or greater version of Oracle client libraries"); 9} 10?> 11--FILE-- 12<?php 13 14require(__DIR__.'/connect.inc'); 15 16// Initialization 17 18$stmtarray = array( 19 "drop table bind_sqltnum_tab", 20 21 "create table bind_sqltnum_tab ( 22 id number, 23 varchar2_t10 varchar2(10), 24 number_t number, 25 number_t92 number(9,2))" 26); 27 28oci8_test_sql_execute($c, $stmtarray); 29 30function check_col($c, $colname, $id) 31{ 32 $s = oci_parse($c, "select dump($colname) from bind_sqltnum_tab where id = :id"); 33 oci_bind_by_name($s, ":id", $id); 34 oci_execute($s); 35 oci_fetch_all($s, $r); 36 var_dump($r); 37} 38 39 40// Run Test 41 42echo "Test 1 - baseline test\n"; 43 44$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (100, :c2)"); 45$c2 = "Hood"; 46$r = oci_bind_by_name($s, ":c2", $c2, -1); 47if (!$r) { 48 $e = oci_error($s); 49 var_dump($e); 50} 51$r = oci_execute($s, OCI_DEFAULT); 52if (!$r) { 53 $e = oci_error($s); 54 var_dump($e); 55} 56 57$s = oci_parse($c, "select id, varchar2_t10 from bind_sqltnum_tab"); 58oci_execute($s); 59oci_fetch_all($s, $data); 60var_dump($data); 61 62echo "Test 2 - SQLT_NUM to a VARCHAR2 column\n"; 63 64$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (100, :c2)"); 65$c2 = "Hood"; 66$r = oci_bind_by_name($s, ":c2", $c2, -1, SQLT_NUM); 67if (!$r) { 68 $e = oci_error($s); 69 var_dump($e['message']); 70} 71$r = oci_execute($s, OCI_DEFAULT); 72if (!$r) { 73 $e = oci_error($s); 74 var_dump($e['message']); 75} 76 77echo "\nTEST41 wrong bind type SQLT_NUM\n"; 78 79$c2 = "Hood41"; 80$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (41, :c2)"); 81oci_bind_by_name($s, ":c2", $c2, -1, SQLT_NUM); 82oci_execute($s); 83 84echo "\nTEST42 insert numbers SQLT_NUM\n"; 85 86$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (42, :n1)"); 87$n1 = 42; 88oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 89oci_execute($s); 90 91check_col($c, 'number_t', 42); 92 93echo "\nTEST43 insert numbers SQLT_NUM\n"; 94 95$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (43, :n1)"); 96$n1 = 42.69; 97oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 98oci_execute($s); 99 100check_col($c, 'number_t', 43); 101 102echo "\nTEST44\n"; 103 104$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (44, :n1)"); 105$n1 = 0; 106oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 107oci_execute($s); 108 109check_col($c, 'number_t', 44); 110 111echo "\nTEST45\n"; 112 113$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (45, :n1)"); 114$n1 = -23; 115oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 116oci_execute($s); 117 118check_col($c, 'number_t', 45); 119 120echo "\nTEST46 insert numbers\n"; 121 122$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (46, :n1)"); 123$n1 = "-23"; 124oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 125oci_execute($s); 126 127check_col($c, 'number_t', 46); 128 129echo "\nTEST47\n"; 130 131$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (47, :n1)"); 132$n1 = "23"; 133oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 134oci_execute($s); 135 136check_col($c, 'number_t', 47); 137 138echo "\nTEST48\n"; 139 140$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (48, :n1)"); 141$n1 = 123.56; 142oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 143oci_execute($s); 144 145check_col($c, 'number_t92', 48); 146 147echo "\nTEST49\n"; 148 149$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (49, :n1)"); 150$n1 = "123.56"; 151oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 152oci_execute($s); 153 154check_col($c, 'number_t92', 49); 155 156echo "\nTEST50\n"; 157 158$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (50, :n1)"); 159$n1 = ""; 160oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM); 161oci_execute($s); 162 163check_col($c, 'number_t92', 50); 164 165// Clean up 166 167$stmtarray = array( 168 "drop table bind_sqltnum_tab" 169); 170 171oci8_test_sql_execute($c, $stmtarray); 172 173?> 174--EXPECTF-- 175Test 1 - baseline test 176array(2) { 177 ["ID"]=> 178 array(1) { 179 [0]=> 180 string(3) "100" 181 } 182 ["VARCHAR2_T10"]=> 183 array(1) { 184 [0]=> 185 string(4) "Hood" 186 } 187} 188Test 2 - SQLT_NUM to a VARCHAR2 column 189 190Warning: oci_execute(): ORA-12899: %s (%s: 40, %s: 10) in %sbind_sqltnum.php on line %d 191string(%d) "ORA-12899: %s" 192 193TEST41 wrong bind type SQLT_NUM 194 195Warning: oci_execute(): ORA-12899: %s "%s"."BIND_SQLTNUM_TAB"."VARCHAR2_T10" (%s: 40, %s: 10) in %sbind_sqltnum.php on line %d 196 197TEST42 insert numbers SQLT_NUM 198array(1) { 199 ["DUMP(NUMBER_T)"]=> 200 array(1) { 201 [0]=> 202 string(29) "Typ=2 Len=8: 42,0,0,0,0,0,0,0" 203 } 204} 205 206TEST43 insert numbers SQLT_NUM 207array(1) { 208 ["DUMP(NUMBER_T)"]=> 209 array(1) { 210 [0]=> 211 string(29) "Typ=2 Len=8: 42,0,0,0,0,0,0,0" 212 } 213} 214 215TEST44 216array(1) { 217 ["DUMP(NUMBER_T)"]=> 218 array(1) { 219 [0]=> 220 string(28) "Typ=2 Len=8: 0,0,0,0,0,0,0,0" 221 } 222} 223 224TEST45 225array(1) { 226 ["DUMP(NUMBER_T)"]=> 227 array(1) { 228 [0]=> 229 string(44) "Typ=2 Len=8: 233,255,255,255,255,255,255,255" 230 } 231} 232 233TEST46 insert numbers 234array(1) { 235 ["DUMP(NUMBER_T)"]=> 236 array(1) { 237 [0]=> 238 string(44) "Typ=2 Len=8: 233,255,255,255,255,255,255,255" 239 } 240} 241 242TEST47 243array(1) { 244 ["DUMP(NUMBER_T)"]=> 245 array(1) { 246 [0]=> 247 string(29) "Typ=2 Len=8: 23,0,0,0,0,0,0,0" 248 } 249} 250 251TEST48 252array(1) { 253 ["DUMP(NUMBER_T92)"]=> 254 array(1) { 255 [0]=> 256 string(16) "Typ=2 Len=1: 128" 257 } 258} 259 260TEST49 261array(1) { 262 ["DUMP(NUMBER_T92)"]=> 263 array(1) { 264 [0]=> 265 string(16) "Typ=2 Len=1: 128" 266 } 267} 268 269TEST50 270 271Warning: oci_execute(): ORA-01438: %s in %sbind_sqltnum.php on line %d 272array(1) { 273 ["DUMP(NUMBER_T92)"]=> 274 array(0) { 275 } 276} 277