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