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