1#include "sqltypes.h"
2#include <stdlib.h>
3
4$include ../regression;
5$define NUMBER 12;
6
7static void
8test_null(int type, char *ptr)
9{
10	printf("null: %d\n", risnull(type, ptr));
11}
12
13int main(void)
14{
15	$char c[] = "abc";
16	$short s = 17;
17	$int i = -74874;
18	$bool b = 1;
19	$float f = 3.71;
20	$long l = 487444;
21	$double dbl = 404.404;
22	$decimal dec;
23	$date dat;
24	$timestamp tmp;
25
26	ECPGdebug(1, stderr);
27	$whenever sqlerror do sqlprint();
28
29	$connect to REGRESSDB1;
30
31	$create table test(id int, c char(10), s smallint, i int, b bool,
32					   f float, l bigint, dbl double precision,
33					   dec decimal, dat date, tmp timestamptz);
34	$commit;
35
36	$insert into test (id, c, s, i, b, f, l, dbl) values (
37		1, :c, :s, :i, :b, :f, :l, :dbl
38	);
39	$commit;
40
41	rsetnull(CCHARTYPE, (char *) c);
42	rsetnull(CSHORTTYPE, (char *) &s);
43	rsetnull(CINTTYPE, (char *) &i);
44	rsetnull(CBOOLTYPE, (char *) &b);
45	rsetnull(CFLOATTYPE, (char *) &f);
46	rsetnull(CLONGTYPE, (char *) &l);
47	rsetnull(CDOUBLETYPE, (char *) &dbl);
48	rsetnull(CDECIMALTYPE, (char *) &dec);
49	rsetnull(CDATETYPE, (char *) &dat);
50	rsetnull(CDTIMETYPE, (char *) &tmp);
51
52	$insert into test (id, c, s, i, b, f, l, dbl, dec, dat, tmp) values (
53		2, :c, :s, :i, :b, :f, :l, :dbl, :dec, :dat, :tmp
54	);
55	$commit;
56
57	printf("first select\n");
58
59	$select c, s, i, b, f, l, dbl, dec, dat, tmp
60		into :c, :s, :i, :b, :f, :l, :dbl, :dec, :dat, :tmp
61		from test where id = 1;
62
63	test_null(CCHARTYPE, (char *) c);
64	test_null(CSHORTTYPE, (char *) &s);
65	test_null(CINTTYPE, (char *) &i);
66	test_null(CBOOLTYPE, (char *) &b);
67	test_null(CFLOATTYPE, (char *) &f);
68	test_null(CLONGTYPE, (char *) &l);
69	test_null(CDOUBLETYPE, (char *) &dbl);
70	test_null(CDECIMALTYPE, (char *) &dec);
71	test_null(CDATETYPE, (char *) &dat);
72	test_null(CDTIMETYPE, (char *) &tmp);
73
74	printf("second select\n");
75
76	$select c, s, i, b, f, l, dbl, dec, dat, tmp
77		into :c, :s, :i, :b, :f, :l, :dbl, :dec, :dat, :tmp
78		from test where id = 2;
79
80	test_null(CCHARTYPE, (char *) c);
81	test_null(CSHORTTYPE, (char *) &s);
82	test_null(CINTTYPE, (char *) &i);
83	test_null(CBOOLTYPE, (char *) &b);
84	test_null(CFLOATTYPE, (char *) &f);
85	test_null(CLONGTYPE, (char *) &l);
86	test_null(CDOUBLETYPE, (char *) &dbl);
87	test_null(CDECIMALTYPE, (char *) &dec);
88	test_null(CDATETYPE, (char *) &dat);
89	test_null(CDTIMETYPE, (char *) &tmp);
90
91	$drop table test;
92	$commit;
93
94	$close database;
95
96	return 0;
97}
98