1#include <locale.h>
2#include <string.h>
3#include <stdlib.h>
4
5#include <pgtypes_date.h>
6#include <pgtypes_interval.h>
7#include <pgtypes_numeric.h>
8#include <pgtypes_timestamp.h>
9
10exec sql whenever sqlerror sqlprint;
11
12exec sql include sqlca;
13exec sql include ../regression;
14
15int
16main (void)
17{
18EXEC SQL BEGIN DECLARE SECTION;
19	int i = 1, j;
20	int *did = &i;
21	short a[10] = {9,8,7,6,5,4,3,2,1,0};
22	timestamp ts[10];
23	date d[10];
24	interval in[10];
25	numeric n[10];
26	char text[25] = "klmnopqrst";
27	char *t = (char *)malloc(11);
28	double f;
29EXEC SQL END DECLARE SECTION;
30
31	strcpy(t, "0123456789");
32	setlocale(LC_ALL, "C");
33
34	ECPGdebug(1, stderr);
35
36	for (j = 0; j < 10; j++) {
37		char str[28];
38		numeric *value;
39		interval *inter;
40
41		sprintf(str, "2000-1-1 0%d:00:00", j);
42		ts[j] = PGTYPEStimestamp_from_asc(str, NULL);
43		sprintf(str, "2000-1-1%d\n", j);
44		d[j] = PGTYPESdate_from_asc(str, NULL);
45		sprintf(str, "%d hours", j+10);
46		inter = PGTYPESinterval_from_asc(str, NULL);
47		in[j] = *inter;
48		value = PGTYPESnumeric_new();
49		PGTYPESnumeric_from_int(j, value);
50		n[j] = *value;
51	}
52
53        EXEC SQL CONNECT TO REGRESSDB1;
54
55	EXEC SQL SET AUTOCOMMIT = ON;
56
57	EXEC SQL BEGIN WORK;
58
59	EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), ts timestamp[10], n numeric[10], d date[10], inter interval[10]);
60
61	EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij',:ts,:n,:d,:in);
62
63	EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(140787.0,2,:a,:text,:ts,:n,:d,:in);
64
65	EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(14.07,:did,:a,:t,:ts,:n,:d,:in);
66
67	EXEC SQL COMMIT;
68
69	for (j = 0; j < 10; j++) {
70		ts[j] = PGTYPEStimestamp_from_asc("1900-01-01 00:00:00", NULL);
71		d[j] = PGTYPESdate_from_asc("1900-01-01", NULL);
72		in[j] = *PGTYPESinterval_new();
73		n[j] = *PGTYPESnumeric_new();
74	}
75	EXEC SQL BEGIN WORK;
76
77	EXEC SQL SELECT f,text
78         INTO :f,:text
79         FROM test
80         WHERE i = 1;
81
82	printf("Found f=%f text=%10.10s\n", f, text);
83
84	f=140787;
85	EXEC SQL SELECT a,text,ts,n,d,inter
86	 INTO :a,:t,:ts,:n,:d,:in
87	 FROM test
88	 WHERE f = :f;
89
90	for (i = 0; i < 10; i++)
91		printf("Found a[%d] = %d ts[%d] = %s n[%d] = %s d[%d] = %s in[%d] = %s\n", i, a[i], i, PGTYPEStimestamp_to_asc(ts[i]), i, PGTYPESnumeric_to_asc(&(n[i]), -1), i, PGTYPESdate_to_asc(d[i]), i, PGTYPESinterval_to_asc(&(in[i])));
92
93	printf("Found text=%10.10s\n", t);
94
95	EXEC SQL SELECT a
96	 INTO :text
97	 FROM test
98	 WHERE f = :f;
99
100	printf("Found text=%s\n", text);
101
102	EXEC SQL DROP TABLE test;
103
104	EXEC SQL COMMIT;
105
106	EXEC SQL DISCONNECT;
107
108	free(t);
109
110	return 0;
111}
112