xref: /PHP-7.3/ext/oci8/tests/num.phpt (revision c7a8bd6a)
1--TEST--
2oci_num_*() family
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// Initialize
11
12$stmtarray = array(
13    "drop table num_tab",
14    "create table num_tab (id number, value number)",
15);
16
17oci8_test_sql_execute($c, $stmtarray);
18
19// Run Test
20
21echo "Test 1\n";
22var_dump(ocirowcount());
23var_dump(oci_num_rows());
24var_dump(ocinumcols());
25var_dump(oci_num_fields());
26
27echo "Test 2\n";
28$insert_sql = "insert into num_tab (id, value) values (1,1)";
29if (!($s = oci_parse($c, $insert_sql))) {
30    die("oci_parse(insert) failed!\n");
31}
32
33var_dump(ocirowcount($s));
34var_dump(oci_num_rows($s));
35var_dump(ocinumcols($s));
36var_dump(oci_num_fields($s));
37
38for ($i = 0; $i<3; $i++) {
39  if (!oci_execute($s)) {
40    die("oci_execute(insert) failed!\n");
41  }
42}
43
44echo "Test 3\n";
45var_dump(ocirowcount($s));
46var_dump(oci_num_rows($s));
47var_dump(ocinumcols($s));
48var_dump(oci_num_fields($s));
49
50if (!oci_commit($c)) {
51  die("oci_commit() failed!\n");
52}
53
54echo "Test 4\n";
55var_dump(ocirowcount($s));
56var_dump(oci_num_rows($s));
57var_dump(ocinumcols($s));
58var_dump(oci_num_fields($s));
59
60// All rows
61$select_sql = "select * from num_tab";
62
63if (!($s = oci_parse($c, $select_sql))) {
64  die("oci_parse(select) failed!\n");
65}
66
67echo "Test 5a\n";
68var_dump(ocirowcount($s));
69var_dump(oci_num_rows($s));
70var_dump(ocinumcols($s));
71var_dump(oci_num_fields($s));
72
73if (!oci_execute($s)) {
74  die("oci_execute(select) failed!\n");
75}
76
77echo "Test 5b\n";
78var_dump(ocirowcount($s));
79var_dump(oci_num_rows($s));
80var_dump(ocinumcols($s));
81var_dump(oci_num_fields($s));
82
83
84if (oci_fetch_all($s,$r) === false) {
85  die("oci_fetch_all(select) failed!\n");
86}
87
88echo "Test 5c\n";
89var_dump(ocirowcount($s));
90var_dump(oci_num_rows($s));
91var_dump(ocinumcols($s));
92var_dump(oci_num_fields($s));
93
94// One row
95$select_sql = "SELECT id, value FROM num_tab WHERE ROWNUM < 2";
96
97if (!($s = oci_parse($c, $select_sql))) {
98  die("oci_parse(select) failed!\n");
99}
100
101if (!oci_execute($s)) {
102  die("oci_execute(select) failed!\n");
103}
104
105if (oci_fetch_all($s,$r) === false) {
106  die("oci_fetch_all(select) failed!\n");
107}
108
109echo "Test 6\n";
110var_dump(ocirowcount($s));
111var_dump(oci_num_rows($s));
112var_dump(ocinumcols($s));
113var_dump(oci_num_fields($s));
114
115// No rows
116$select_sql = "select id from num_tab where 1=0";
117
118if (!($s = oci_parse($c, $select_sql))) {
119  die("oci_parse(select) failed!\n");
120}
121
122if (!oci_execute($s)) {
123  die("oci_execute(select) failed!\n");
124}
125
126if (oci_fetch_all($s,$r) === false) {
127  die("oci_fetch_all(select) failed!\n");
128}
129
130echo "Test 7\n";
131var_dump(ocirowcount($s));
132var_dump(oci_num_rows($s));
133var_dump(ocinumcols($s));
134var_dump(oci_num_fields($s));
135
136$delete_sql = "delete from num_tab";
137
138if (!($s = oci_parse($c, $delete_sql))) {
139    die("oci_parse(delete) failed!\n");
140}
141
142if (!oci_execute($s)) {
143    die("oci_execute(delete) failed!\n");
144}
145
146echo "Test 8a\n";
147var_dump(ocirowcount($s));
148var_dump(oci_num_rows($s));
149var_dump(ocinumcols($s));
150var_dump(oci_num_fields($s));
151
152
153oci_commit($c);
154
155echo "Test 8b\n";
156var_dump(ocirowcount($s));
157var_dump(oci_num_rows($s));
158var_dump(ocinumcols($s));
159var_dump(oci_num_fields($s));
160
161
162// Cleanup
163
164$stmtarray = array(
165    "drop table num_tab"
166);
167
168oci8_test_sql_execute($c, $stmtarray);
169
170echo "Done\n";
171
172?>
173--EXPECTF--
174Test 1
175
176Warning: ocirowcount() expects exactly 1 parameter, 0 given in %s on line %d
177NULL
178
179Warning: oci_num_rows() expects exactly 1 parameter, 0 given in %s on line %d
180NULL
181
182Warning: ocinumcols() expects exactly 1 parameter, 0 given in %s on line %d
183NULL
184
185Warning: oci_num_fields() expects exactly 1 parameter, 0 given in %s on line %d
186NULL
187Test 2
188int(0)
189int(0)
190int(0)
191int(0)
192Test 3
193int(1)
194int(1)
195int(0)
196int(0)
197Test 4
198int(1)
199int(1)
200int(0)
201int(0)
202Test 5a
203int(0)
204int(0)
205int(0)
206int(0)
207Test 5b
208int(0)
209int(0)
210int(2)
211int(2)
212Test 5c
213int(3)
214int(3)
215int(2)
216int(2)
217Test 6
218int(1)
219int(1)
220int(2)
221int(2)
222Test 7
223int(0)
224int(0)
225int(1)
226int(1)
227Test 8a
228int(3)
229int(3)
230int(0)
231int(0)
232Test 8b
233int(3)
234int(3)
235int(0)
236int(0)
237Done
238