aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/compat_informix/rnull.pgc
blob: 232629fcd4a2145ad0eddfba08a0fb1d75b22d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "sqltypes.h"
#include <stdlib.h>

$include ../regression;
$define NUMBER 12;

static void
test_null(int type, char *ptr)
{
	printf("null: %d\n", risnull(type, ptr));
}

int main(void)
{
	$char c[] = "abc";
	$short s = 17;
	$int i = -74874;
	$bool b = 1;
	$float f = (float) 3.71;
	$long l = 487444;
	$double dbl = 404.404;
	$decimal dec;
	$date dat;
	$timestamp tmp;

	ECPGdebug(1, stderr);
	$whenever sqlerror do sqlprint();

	$connect to REGRESSDB1;

	$create table test(id int, c char(10), s smallint, i int, b bool,
					   f float, l bigint, dbl double precision,
					   dec decimal, dat date, tmp timestamptz);
	$commit;

	$insert into test (id, c, s, i, b, f, l, dbl) values (
		1, :c, :s, :i, :b, :f, :l, :dbl
	);
	$commit;

	rsetnull(CCHARTYPE, (char *) c);
	rsetnull(CSHORTTYPE, (char *) &s);
	rsetnull(CINTTYPE, (char *) &i);
	rsetnull(CBOOLTYPE, (char *) &b);
	rsetnull(CFLOATTYPE, (char *) &f);
	rsetnull(CLONGTYPE, (char *) &l);
	rsetnull(CDOUBLETYPE, (char *) &dbl);
	rsetnull(CDECIMALTYPE, (char *) &dec);
	rsetnull(CDATETYPE, (char *) &dat);
	rsetnull(CDTIMETYPE, (char *) &tmp);

	$insert into test (id, c, s, i, b, f, l, dbl, dec, dat, tmp) values (
		2, :c, :s, :i, :b, :f, :l, :dbl, :dec, :dat, :tmp
	);
	$commit;

	printf("first select\n");

	$select c, s, i, b, f, l, dbl, dec, dat, tmp
		into :c, :s, :i, :b, :f, :l, :dbl, :dec, :dat, :tmp
		from test where id = 1;

	test_null(CCHARTYPE, (char *) c);
	test_null(CSHORTTYPE, (char *) &s);
	test_null(CINTTYPE, (char *) &i);
	test_null(CBOOLTYPE, (char *) &b);
	test_null(CFLOATTYPE, (char *) &f);
	test_null(CLONGTYPE, (char *) &l);
	test_null(CDOUBLETYPE, (char *) &dbl);
	test_null(CDECIMALTYPE, (char *) &dec);
	test_null(CDATETYPE, (char *) &dat);
	test_null(CDTIMETYPE, (char *) &tmp);

	printf("second select\n");

	$select c, s, i, b, f, l, dbl, dec, dat, tmp
		into :c, :s, :i, :b, :f, :l, :dbl, :dec, :dat, :tmp
		from test where id = 2;

	test_null(CCHARTYPE, (char *) c);
	test_null(CSHORTTYPE, (char *) &s);
	test_null(CINTTYPE, (char *) &i);
	test_null(CBOOLTYPE, (char *) &b);
	test_null(CFLOATTYPE, (char *) &f);
	test_null(CLONGTYPE, (char *) &l);
	test_null(CDOUBLETYPE, (char *) &dbl);
	test_null(CDECIMALTYPE, (char *) &dec);
	test_null(CDATETYPE, (char *) &dat);
	test_null(CDTIMETYPE, (char *) &tmp);

	$drop table test;
	$commit;

	$close database;

	return 0;
}