xref: /PHP-5.3/ext/interbase/tests/006.phpt (revision ddac8c17)
1--TEST--
2InterBase: binding (may take a while)
3--SKIPIF--
4<?php include("skipif.inc"); ?>
5--FILE--
6<?php /* $Id$ */
7
8	require("interbase.inc");
9
10	ibase_connect($test_base);
11
12	ibase_query(
13		"create table test6 (
14			iter		integer,
15			v_char		char(1000),
16			v_date      timestamp,
17			v_decimal   decimal(12,3),
18			v_double  	double precision,
19			v_float     float,
20			v_integer   integer,
21			v_numeric   numeric(4,2),
22			v_smallint  smallint,
23			v_varchar   varchar(10000)
24			)");
25	ibase_query(
26		"create procedure add1 (arg integer)
27		returns (result integer)
28		as
29		begin
30			result = arg +1;
31		end");
32	ibase_commit();
33
34	/* if timefmt not supported, hide error */
35	ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S");
36
37	echo "insert\n";
38
39	for($iter = 0; $iter < 3; $iter++) {
40		/* prepare data  */
41		$v_char = rand_str(1000);
42		$v_date = rand_datetime();
43		$v_decimal = rand_number(12,3);
44		$v_double  = rand_number(20);
45		$v_float   = rand_number(7);
46		$v_integer = rand_number(9,0);
47		$v_numeric = rand_number(4,2);
48		$v_smallint = rand_number(5) % 32767;
49		$v_varchar = rand_str(10000);
50
51		ibase_query("insert into test6
52			(iter,v_char,v_date,v_decimal,v_double,v_float,
53			v_integer,v_numeric,v_smallint,v_varchar)
54			values (?,?,?,?,?,?,?,?,?,?)",
55			$iter, $v_char, $v_date, $v_decimal, $v_double, $v_float,
56			$v_integer, $v_numeric, $v_smallint, $v_varchar);
57		$sel = ibase_query("select * from test6 where iter = ?", $iter);
58
59		$row = ibase_fetch_object($sel);
60		if(substr($row->V_CHAR,0,strlen($v_char)) != $v_char) {
61			echo " CHAR fail:\n";
62			echo " in:  $v_char\n";
63			echo " out: $row->V_CHAR\n";
64		}
65		if($row->V_DATE != $v_date) {
66			echo " DATE fail\n";
67			echo " in:  $v_date\n";
68			echo " out: $row->V_DATE\n";
69		}
70		if($row->V_DECIMAL != $v_decimal) {
71			echo " DECIMAL fail\n";
72			echo " in:  $v_decimal\n";
73			echo " out: $row->V_DECIMAL\n";
74		}
75		if(abs($row->V_DOUBLE - $v_double) > abs($v_double / 1E15)) {
76			echo " DOUBLE fail\n";
77			echo " in:  $v_double\n";
78			echo " out: $row->V_DOUBLE\n";
79		}
80		if(abs($row->V_FLOAT - $v_float) > abs($v_float / 1E7)) {
81			echo " FLOAT fail\n";
82			echo " in:  $v_float\n";
83			echo " out: $row->V_FLOAT\n";
84		}
85		if($row->V_INTEGER != $v_integer) {
86			echo " INTEGER fail\n";
87			echo " in:  $v_integer\n";
88			echo " out: $row->V_INTEGER\n";
89		}
90		if ($row->V_NUMERIC != $v_numeric) {
91			echo " NUMERIC fail\n";
92			echo " in:  $v_numeric\n";
93			echo " out: $row->V_NUMERIC\n";
94		}
95		if ($row->V_SMALLINT != $v_smallint) {
96			echo " SMALLINT fail\n";
97			echo " in:  $v_smallint\n";
98			echo " out: $row->V_SMALLINT\n";
99		}
100		if ($row->V_VARCHAR != $v_varchar) {
101			echo " VARCHAR fail:\n";
102			echo " in:  $v_varchar\n";
103			echo " out: $row->V_VARCHAR\n";
104		}
105		ibase_free_result($sel);
106	}/* for($iter)*/
107
108	echo "select\n";
109	for($iter = 0; $iter < 3; $iter++) {
110		/* prepare data  */
111		$v_char = rand_str(1000);
112		$v_date = (int)rand_number(10,0,0);
113		$v_decimal = rand_number(12,3);
114		$v_double  = rand_number(20);
115		$v_float   = rand_number(7);
116		$v_integer = rand_number(9,0);
117		$v_numeric = rand_number(4,2);
118		$v_smallint = rand_number(5) % 32767;
119		$v_varchar = rand_str(10000);
120
121		/* clear table*/
122		ibase_query("delete from test6");
123
124		/* make one record */
125		ibase_query("insert into test6
126			(iter, v_char,v_date,v_decimal,
127			v_integer,v_numeric,v_smallint,v_varchar)
128			values (666, '$v_char',?,$v_decimal, $v_integer,
129			$v_numeric, $v_smallint, '$v_varchar')",$v_date);
130
131		/* test all types */
132		if(!($sel = ibase_query(
133			"select iter from test6 where v_char = ?", $v_char)) ||
134			!ibase_fetch_row($sel)) {
135			echo "CHAR fail\n";
136		}
137		ibase_free_result($sel);
138		if(!($sel = ibase_query(
139			"select iter from test6 where v_date = ?", $v_date)) ||
140			!ibase_fetch_row($sel)) {
141			echo "DATE fail\n";
142		}
143		ibase_free_result($sel);
144		if(!($sel = ibase_query(
145			"select iter from test6 where v_decimal = ?", $v_decimal)) ||
146			!ibase_fetch_row($sel)) {
147			echo "DECIMAL fail\n";
148		}
149		ibase_free_result($sel);
150		if(!($sel = ibase_query(
151			"select iter from test6 where v_integer = ?", $v_integer)) ||
152			!ibase_fetch_row($sel)) {
153			echo "INTEGER fail\n";
154		}
155		ibase_free_result($sel);
156		if(!($sel = ibase_query(
157			"select iter from test6 where v_numeric = ?", $v_numeric)) ||
158			!ibase_fetch_row($sel)) {
159			echo "NUMERIC fail\n";
160		}
161		ibase_free_result($sel);
162		if(!($sel = ibase_query(
163			"select iter from test6 where v_smallint = ?", $v_smallint)) ||
164			!ibase_fetch_row($sel)) {
165			echo "SMALLINT fail\n";
166		}
167		ibase_free_result($sel);
168		if(!($sel = ibase_query(
169			"select iter from test6 where v_varchar = ?", $v_varchar)) ||
170			!ibase_fetch_row($sel)) {
171			echo "VARCHAR fail\n";
172		}
173		ibase_free_result($sel);
174
175	} /*for iter*/
176
177	echo "prepare and exec insert\n";
178
179    /* prepare table */
180	ibase_query("delete from test6");
181
182	/* prepare query */
183	$query = ibase_prepare(
184		"insert into test6 (v_integer) values (?)");
185
186	for($i = 0; $i < 10; $i++) {
187		ibase_execute($query, $i);
188	}
189
190	out_table("test6");
191
192	ibase_free_query($query);
193
194	echo "prepare and exec select\n";
195
196	/* prepare query */
197	$query = ibase_prepare("select * from test6
198		where v_integer between ? and ?");
199
200	$low_border = 2;
201	$high_border = 6;
202
203	$res = ibase_execute($query, $low_border, $high_border);
204	out_result($res, "test6");
205	ibase_free_result($res);
206
207	$low_border = 0;
208	$high_border = 4;
209	$res = ibase_execute($query, $low_border, $high_border);
210	out_result($res, "test6");
211	ibase_free_result($res);
212
213	$res = ibase_execute($query, "5", 7.499);
214	out_result($res, "test6");
215	ibase_free_result($res);
216
217	ibase_free_query($query);
218
219	/* test execute procedure */
220	$query = ibase_prepare("execute procedure add1(?)");
221	$res = array();
222	for ($i = 0; $i < 10; $i++) {
223		$res[] = ibase_execute($query,$i);
224	}
225	ibase_free_query($query);
226	foreach ($res as $r) {
227		out_result($r, "proc add1");
228		ibase_free_result($r);
229	}
230
231	ibase_close();
232	echo "end of test\n";
233?>
234--EXPECT--
235insert
236select
237prepare and exec insert
238--- test6 ---
239						0
240						1
241						2
242						3
243						4
244						5
245						6
246						7
247						8
248						9
249---
250prepare and exec select
251--- test6 ---
252						2
253						3
254						4
255						5
256						6
257---
258--- test6 ---
259						0
260						1
261						2
262						3
263						4
264---
265--- test6 ---
266						5
267						6
268						7
269---
270--- proc add1 ---
2711
272---
273--- proc add1 ---
2742
275---
276--- proc add1 ---
2773
278---
279--- proc add1 ---
2804
281---
282--- proc add1 ---
2835
284---
285--- proc add1 ---
2866
287---
288--- proc add1 ---
2897
290---
291--- proc add1 ---
2928
293---
294--- proc add1 ---
2959
296---
297--- proc add1 ---
29810
299---
300end of test
301
302