summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/dt_test.pgc
blob: 34f520f891b57ca6859cc96845cb21fe51032a4f (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
#include <stdio.h>
#include <pgtypes_date.h>
#include <pgtypes_timestamp.h>

int
main()
{
	exec sql begin declare section;
	date date1;
	timestamp ts1;
	char *text;
	exec sql end declare section;
#if 0
	Date date2;
	short int mdy[3] = { 4, 19, 1998 };
#endif
	FILE *dbgs;

        if ((dbgs = fopen("log", "w")) != NULL)
                 ECPGdebug(1, dbgs);
        exec sql whenever sqlerror do sqlprint();
        exec sql connect to mm;
        exec sql create table date_test (d date, ts timestamp);

	exec sql insert into date_test(d, ts) values ('Mon Jan 17 1966', '2000-7-12 17:34:29');

	exec sql select * into :date1, :ts1 from date_test;
	
	text = PGTYPESdate_dtoa(date1);
	printf ("Date: %s\n", text);
	ts1 = PGTYPEStimestamp_atot("2000-7-12 17:34:29", NULL);
	text = PGTYPEStimestamp_ttoa(ts1);
	printf ("timestamp: %s\n", text);
#if 0
	PGTYPESdate_mdyjul(mdy, &date2);
	printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
	/* reset */
	mdy[0] = mdy[1] = mdy[2] = 0;

	PGTYPESdate_julmdy(date2, mdy);
	printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
#endif
        exec sql rollback;
        exec sql disconnect;

	if (dbgs != NULL)
		fclose(dbgs);
						
	return (0);
}