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