1--TEST-- 2Bind tests with SQLT_AFC 3--SKIPIF-- 4<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?> 5--FILE-- 6<?php 7 8require(__DIR__.'/connect.inc'); 9 10// Initialization 11 12$stmtarray = array( 13 "drop table bind_sqltafc_tab", 14 "create table bind_sqltafc_tab (id number, char_t char(1), char_t10 char(10), varchar2_t10 varchar2(10), number_t number)", 15 "insert into bind_sqltafc_tab values (0, 'a', 'abcd', 'efghij', 1.1)" 16); 17 18oci8_test_sql_execute($c, $stmtarray); 19 20// Run Test 21 22function q($c, $id) 23{ 24 $s = oci_parse($c, "select * from bind_sqltafc_tab where id = $id"); 25 oci_execute($s); 26 oci_fetch_all($s, $r); 27 var_dump($r); 28} 29 30echo "Test 0 - base table creation without binds\n"; 31 32q($c, 0); 33 34echo "\nTest 1 - successful insert\n"; 35 36$s = oci_parse($c, "INSERT INTO bind_sqltafc_tab (id, char_t, char_t10, varchar2_t10, number_t) VALUES (1, :c2, :c3, :c4, :c5)"); 37$c2 = "H"; 38$c3 = "AAAAAAAAAA"; // max length allowed in column 39$c4 = "BBBBBBBBBB"; // max length allowed in column 40$c5 = "123.45"; 41oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC); 42oci_bind_by_name($s, ":c3", $c3, -1, SQLT_AFC); 43oci_bind_by_name($s, ":c4", $c4, -1, SQLT_AFC); 44oci_bind_by_name($s, ":c5", $c5, -1, SQLT_AFC); 45oci_execute($s); 46 47q($c, 1); 48 49echo "\nTest 2 - Empty Strings\n"; 50 51$s = oci_parse($c, "INSERT INTO bind_sqltafc_tab (id, char_t, char_t10, varchar2_t10, number_t) VALUES (5, :c2, :c3, :c4, :c5)"); 52$c2 = ""; 53$c3 = ""; 54$c4 = ""; 55$c5 = ""; 56oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC); 57oci_bind_by_name($s, ":c3", $c3, -1, SQLT_AFC); 58oci_bind_by_name($s, ":c4", $c4, -1, SQLT_AFC); 59oci_bind_by_name($s, ":c5", $c5, -1, SQLT_AFC); 60oci_execute($s); 61 62q($c, 5); 63 64echo "\nTest 3 - NULLs\n"; 65 66$s = oci_parse($c, "INSERT INTO bind_sqltafc_tab (id, char_t, char_t10, varchar2_t10, number_t) VALUES (6, :c2, :c3, :c4, :c5)"); 67$c2 = null; 68$c3 = null; 69$c4 = null; 70$c5 = null; 71oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC); 72oci_bind_by_name($s, ":c3", $c3, -1, SQLT_AFC); 73oci_bind_by_name($s, ":c4", $c4, -1, SQLT_AFC); 74oci_bind_by_name($s, ":c5", $c5, -1, SQLT_AFC); 75oci_execute($s); 76 77q($c, 6); 78 79// Clean up 80 81$stmtarray = array( 82 "drop table bind_sqltafc_tab" 83); 84 85oci8_test_sql_execute($c, $stmtarray); 86 87oci_close($c); 88 89?> 90--EXPECT-- 91Test 0 - base table creation without binds 92array(5) { 93 ["ID"]=> 94 array(1) { 95 [0]=> 96 string(1) "0" 97 } 98 ["CHAR_T"]=> 99 array(1) { 100 [0]=> 101 string(1) "a" 102 } 103 ["CHAR_T10"]=> 104 array(1) { 105 [0]=> 106 string(10) "abcd " 107 } 108 ["VARCHAR2_T10"]=> 109 array(1) { 110 [0]=> 111 string(6) "efghij" 112 } 113 ["NUMBER_T"]=> 114 array(1) { 115 [0]=> 116 string(3) "1.1" 117 } 118} 119 120Test 1 - successful insert 121array(5) { 122 ["ID"]=> 123 array(1) { 124 [0]=> 125 string(1) "1" 126 } 127 ["CHAR_T"]=> 128 array(1) { 129 [0]=> 130 string(1) "H" 131 } 132 ["CHAR_T10"]=> 133 array(1) { 134 [0]=> 135 string(10) "AAAAAAAAAA" 136 } 137 ["VARCHAR2_T10"]=> 138 array(1) { 139 [0]=> 140 string(10) "BBBBBBBBBB" 141 } 142 ["NUMBER_T"]=> 143 array(1) { 144 [0]=> 145 string(6) "123.45" 146 } 147} 148 149Test 2 - Empty Strings 150array(5) { 151 ["ID"]=> 152 array(1) { 153 [0]=> 154 string(1) "5" 155 } 156 ["CHAR_T"]=> 157 array(1) { 158 [0]=> 159 NULL 160 } 161 ["CHAR_T10"]=> 162 array(1) { 163 [0]=> 164 NULL 165 } 166 ["VARCHAR2_T10"]=> 167 array(1) { 168 [0]=> 169 NULL 170 } 171 ["NUMBER_T"]=> 172 array(1) { 173 [0]=> 174 NULL 175 } 176} 177 178Test 3 - NULLs 179array(5) { 180 ["ID"]=> 181 array(1) { 182 [0]=> 183 string(1) "6" 184 } 185 ["CHAR_T"]=> 186 array(1) { 187 [0]=> 188 NULL 189 } 190 ["CHAR_T10"]=> 191 array(1) { 192 [0]=> 193 NULL 194 } 195 ["VARCHAR2_T10"]=> 196 array(1) { 197 [0]=> 198 NULL 199 } 200 ["NUMBER_T"]=> 201 array(1) { 202 [0]=> 203 NULL 204 } 205} 206