1--TEST--
2Bind miscellaneous column types and generating errors
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11
12require __DIR__.'/connect.inc';
13
14// Initialization
15
16$stmtarray = array(
17    "drop table bind_misccoltypes_errs_tab",
18
19    "create table bind_misccoltypes_errs_tab (
20        id                number,
21        char_t            char(1),
22        char_t10          char(10),
23        varchar2_t10      varchar2(10),
24        number_t          number,
25        number_t92        number(9,2),
26        number_t6         number(6),
27        date_t            date,
28        timestamp_t       timestamp,
29        float_t           float,
30        binary_float_t    binary_float,
31        binary_double_t   binary_double,
32        decimal_t         decimal,
33        integer_t         integer,
34        nchar_t           nchar(10),
35        nvarchar2_t10     nvarchar2(10),
36        varchar_t10       varchar(10) )",
37);
38
39oci8_test_sql_execute($c, $stmtarray);
40
41function check_col($c, $colname, $id)
42{
43    $s = oci_parse($c, "select $colname from bind_misccoltypes_errs_tab where id = :id");
44    oci_bind_by_name($s, ":id", $id);
45    oci_execute($s);
46    oci_fetch_all($s, $r);
47    var_dump($r);
48}
49
50// Tests
51
52echo "\nTest 1 insert numbers\n";
53
54$n1 = -23253245.3432467;
55
56$s = oci_parse($c, "INSERT INTO bind_misccoltypes_errs_tab (id, number_t6) VALUES (1, :n1)");
57oci_bind_by_name($s, ":n1", $n1);
58oci_execute($s);
59
60check_col($c, 'number_t6', 57);
61
62echo "\nTest 2 insert numbers\n";
63
64$n1 = "Hello";
65
66$s = oci_parse($c, "INSERT INTO bind_misccoltypes_errs_tab (id, number_t6) VALUES (2, :n1)");
67oci_bind_by_name($s, ":n1", $n1);
68oci_execute($s);
69
70check_col($c, 'number_t6', 57);
71
72echo "\nTest 3 - too long CHAR\n";
73
74$s = oci_parse($c, "INSERT INTO bind_misccoltypes_errs_tab (id, char_t) VALUES (3, :c2)");
75$c2 = "AB";
76oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC);
77oci_execute($s);
78
79echo "\nTest 4 - too long VARCHAR2\n";
80
81$s = oci_parse($c, "INSERT INTO bind_misccoltypes_errs_tab (id, varchar2_t10) VALUES (4, :c2)");
82$c2 = "AAAAAAAAAAB";
83oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC);
84oci_execute($s);
85
86echo "\nTest 5 - invalid number\n";
87
88$s = oci_parse($c, "INSERT INTO bind_misccoltypes_errs_tab (id, number_t) VALUES (5, :c2)");
89$c2 = "ABC";
90oci_bind_by_name($s, ":c2", $c2, -1, SQLT_AFC);
91oci_execute($s);
92
93echo "\nTest 6 - insert a VARCHAR2 with SQLT_BIN\n";
94
95$s = oci_parse($c, "INSERT INTO bind_misccoltypes_errs_tab (id, varchar2_t10) VALUES (6, :c2)");
96$c2 = "Hood 6";
97oci_bind_by_name($s, ":c2", $c2, -1, SQLT_BIN);
98oci_execute($s);
99
100check_col($c, 'varchar2_t10', 6);
101
102echo "\nTest 7 - insert a VARCHAR2 with SQLT_LBI\n";
103
104$s = oci_parse($c, "INSERT INTO bind_misccoltypes_errs_tab (id, varchar2_t10) VALUES (7, :c2)");
105$c2 = "Hood 7";
106oci_bind_by_name($s, ":c2", $c2, -1, SQLT_LBI);
107oci_execute($s);
108
109check_col($c, 'varchar2_t10', 7);
110
111
112// Clean up
113
114$stmtarray = array(
115    "drop table bind_misccoltypes_errs_tab"
116);
117
118oci8_test_sql_execute($c, $stmtarray);
119
120oci_close($c);
121
122?>
123--EXPECTF--
124Test 1 insert numbers
125
126Warning: oci_execute(): ORA-01438: %s in %sbind_misccoltypes_errs.php on line %d
127array(1) {
128  ["NUMBER_T6"]=>
129  array(0) {
130  }
131}
132
133Test 2 insert numbers
134
135Warning: oci_execute(): ORA-01722: %s in %sbind_misccoltypes_errs.php on line %d
136array(1) {
137  ["NUMBER_T6"]=>
138  array(0) {
139  }
140}
141
142Test 3 - too long CHAR
143
144Warning: oci_execute(): ORA-12899: %r(%s "%s"."BIND_MISCCOLTYPES_ERRS_TAB"."CHAR_T" \(%s: 2, %s: 1\)|String data right truncation)%r in %sbind_misccoltypes_errs.php on line %d
145
146Test 4 - too long VARCHAR2
147
148Warning: oci_execute(): ORA-12899: %r(%s "%s"."BIND_MISCCOLTYPES_ERRS_TAB"."VARCHAR2_T10" \(%s: 11, %s: 10\)|%s data right truncation)%r in %sbind_misccoltypes_errs.php on line %d
149
150Test 5 - invalid number
151
152Warning: oci_execute(): ORA-01722: %s in %sbind_misccoltypes_errs.php on line %d
153
154Test 6 - insert a VARCHAR2 with SQLT_BIN
155
156Warning: oci_execute(): ORA-12899: %r(%s "%s"."BIND_MISCCOLTYPES_ERRS_TAB"."VARCHAR2_T10" \(%s: 12, %s: 10\)|String data right truncation)%r in %sbind_misccoltypes_errs.php on line %d
157array(1) {
158  ["VARCHAR2_T10"]=>
159  array(0) {
160  }
161}
162
163Test 7 - insert a VARCHAR2 with SQLT_LBI
164
165Warning: oci_execute(): ORA-12899: %r(%s "%s"."BIND_MISCCOLTYPES_ERRS_TAB"."VARCHAR2_T10" \(%s: 12, %s: 10\)|String data right truncation)%r in %sbind_misccoltypes_errs.php on line %d
166array(1) {
167  ["VARCHAR2_T10"]=>
168  array(0) {
169  }
170}
171