]> granicus.if.org Git - postgresql/blob - src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
Applied patch by Ron Mayer <rm_pg@cheapcomplexdevices.com> to merge the new
[postgresql] / src / interfaces / ecpg / test / expected / pgtypeslib-dt_test.c
1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8
9 #line 1 "dt_test.pgc"
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <pgtypes_date.h>
14 #include <pgtypes_timestamp.h>
15 #include <pgtypes_interval.h>
16
17
18 #line 1 "regression.h"
19
20
21
22
23
24
25 #line 8 "dt_test.pgc"
26
27
28 int
29 main(void)
30 {
31         /* exec sql begin declare section */
32                  
33                  
34                   
35                  
36         
37 #line 14 "dt_test.pgc"
38  date  date1    ;
39  
40 #line 15 "dt_test.pgc"
41  timestamp  ts1    ;
42  
43 #line 16 "dt_test.pgc"
44  interval * iv1    ,  iv2    ;
45  
46 #line 17 "dt_test.pgc"
47  char * text    ;
48 /* exec sql end declare section */
49 #line 18 "dt_test.pgc"
50
51         date date2;
52         int mdy[3] = { 4, 19, 1998 };
53         char *fmt, *out, *in;
54         char *d1 = "Mon Jan 17 1966";
55         char *t1 = "2000-7-12 17:34:29";
56         int i;
57
58         ECPGdebug(1, stderr);
59         /* exec sql whenever sqlerror  do sqlprint (  ) ; */
60 #line 27 "dt_test.pgc"
61
62         { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
63 #line 28 "dt_test.pgc"
64
65 if (sqlca.sqlcode < 0) sqlprint (  );}
66 #line 28 "dt_test.pgc"
67
68         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create  table date_test ( d date    , ts timestamp    )    ", ECPGt_EOIT, ECPGt_EORT);
69 #line 29 "dt_test.pgc"
70
71 if (sqlca.sqlcode < 0) sqlprint (  );}
72 #line 29 "dt_test.pgc"
73
74         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
75 #line 30 "dt_test.pgc"
76
77 if (sqlca.sqlcode < 0) sqlprint (  );}
78 #line 30 "dt_test.pgc"
79
80         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set intervalstyle to postgres_verbose", ECPGt_EOIT, ECPGt_EORT);
81 #line 31 "dt_test.pgc"
82
83 if (sqlca.sqlcode < 0) sqlprint (  );}
84 #line 31 "dt_test.pgc"
85
86
87         date1 = PGTYPESdate_from_asc(d1, NULL); 
88         ts1 = PGTYPEStimestamp_from_asc(t1, NULL); 
89
90         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into date_test ( d  , ts  ) values (  $1  ,  $2  ) ", 
91         ECPGt_date,&(date1),(long)1,(long)1,sizeof(date), 
92         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
93         ECPGt_timestamp,&(ts1),(long)1,(long)1,sizeof(timestamp), 
94         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
95 #line 36 "dt_test.pgc"
96
97 if (sqlca.sqlcode < 0) sqlprint (  );}
98 #line 36 "dt_test.pgc"
99
100
101         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select  *  from date_test where d =  $1   ", 
102         ECPGt_date,&(date1),(long)1,(long)1,sizeof(date), 
103         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
104         ECPGt_date,&(date1),(long)1,(long)1,sizeof(date), 
105         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
106         ECPGt_timestamp,&(ts1),(long)1,(long)1,sizeof(timestamp), 
107         ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
108 #line 38 "dt_test.pgc"
109
110 if (sqlca.sqlcode < 0) sqlprint (  );}
111 #line 38 "dt_test.pgc"
112
113
114         text = PGTYPESdate_to_asc(date1);
115         printf ("Date: %s\n", text);
116         free(text);
117
118         text = PGTYPEStimestamp_to_asc(ts1);
119         printf ("timestamp: %s\n", text);
120         free(text);
121
122         iv1 = PGTYPESinterval_from_asc("13556 days 12 hours 34 minutes 14 seconds ", NULL);
123         PGTYPESinterval_copy(iv1, &iv2);
124         text = PGTYPESinterval_to_asc(&iv2);
125         printf ("interval: %s\n", text);
126         free(text);
127
128         PGTYPESdate_mdyjul(mdy, &date2);
129         printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
130         /* reset */
131         mdy[0] = mdy[1] = mdy[2] = 0;
132
133         printf("date seems to get encoded to julian %ld\n", date2);
134
135         PGTYPESdate_julmdy(date2, mdy);
136         printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
137
138         ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL);
139         text = PGTYPEStimestamp_to_asc(ts1);
140         fmt = "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end";
141         out = (char*) malloc(strlen(fmt) + 1);
142         date1 = PGTYPESdate_from_timestamp(ts1);
143         PGTYPESdate_fmt_asc(date1, fmt, out);
144         printf("date_day of %s is %d\n", text, PGTYPESdate_dayofweek(date1));
145         printf("Above date in format \"%s\" is \"%s\"\n", fmt, out);
146         free(text);
147         free(out);
148
149         /* rdate_defmt_asc() */
150
151         date1 = 0; text = "";
152         fmt = "yy/mm/dd";
153         in = "In the year 1995, the month of December, it is the 25th day";
154         /*    0123456789012345678901234567890123456789012345678901234567890
155          *    0         1         2         3         4         5         6
156          */
157         PGTYPESdate_defmt_asc(&date1, fmt, in);
158         text = PGTYPESdate_to_asc(date1);
159         printf("date_defmt_asc1: %s\n", text);
160         free(text);
161
162         date1 = 0; text = "";
163         fmt = "mmmm. dd. yyyy";
164         in = "12/25/95";
165         PGTYPESdate_defmt_asc(&date1, fmt, in);
166         text = PGTYPESdate_to_asc(date1);
167         printf("date_defmt_asc2: %s\n", text);
168         free(text);
169
170         date1 = 0; text = "";
171         fmt = "yy/mm/dd";
172         in = "95/12/25";
173         PGTYPESdate_defmt_asc(&date1, fmt, in);
174         text = PGTYPESdate_to_asc(date1);
175         printf("date_defmt_asc3: %s\n", text);
176         free(text);
177
178         date1 = 0; text = "";
179         fmt = "yy/mm/dd";
180         in = "1995, December 25th";
181         PGTYPESdate_defmt_asc(&date1, fmt, in);
182         text = PGTYPESdate_to_asc(date1);
183         printf("date_defmt_asc4: %s\n", text);
184         free(text);
185
186         date1 = 0; text = "";
187         fmt = "dd-mm-yy";
188         in = "This is 25th day of December, 1995";
189         PGTYPESdate_defmt_asc(&date1, fmt, in);
190         text = PGTYPESdate_to_asc(date1);
191         printf("date_defmt_asc5: %s\n", text);
192         free(text);
193
194         date1 = 0; text = "";
195         fmt = "mmddyy";
196         in = "Dec. 25th, 1995";
197         PGTYPESdate_defmt_asc(&date1, fmt, in);
198         text = PGTYPESdate_to_asc(date1);
199         printf("date_defmt_asc6: %s\n", text);
200         free(text);
201
202         date1 = 0; text = "";
203         fmt = "mmm. dd. yyyy";
204         in = "dec 25th 1995";
205         PGTYPESdate_defmt_asc(&date1, fmt, in);
206         text = PGTYPESdate_to_asc(date1);
207         printf("date_defmt_asc7: %s\n", text);
208         free(text);
209
210         date1 = 0; text = "";
211         fmt = "mmm. dd. yyyy";
212         in = "DEC-25-1995";
213         PGTYPESdate_defmt_asc(&date1, fmt, in);
214         text = PGTYPESdate_to_asc(date1);
215         printf("date_defmt_asc8: %s\n", text);
216         free(text);
217
218         date1 = 0; text = "";
219         fmt = "mm yy   dd.";
220         in = "12199525";
221         PGTYPESdate_defmt_asc(&date1, fmt, in);
222         text = PGTYPESdate_to_asc(date1);
223         printf("date_defmt_asc9: %s\n", text);
224         free(text);
225
226         date1 = 0; text = "";
227         fmt = "yyyy fierj mm   dd.";
228         in = "19951225";
229         PGTYPESdate_defmt_asc(&date1, fmt, in);
230         text = PGTYPESdate_to_asc(date1);
231         printf("date_defmt_asc10: %s\n", text);
232         free(text);
233
234         date1 = 0; text = "";
235         fmt = "mm/dd/yy";
236         in = "122595";
237         PGTYPESdate_defmt_asc(&date1, fmt, in);
238         text = PGTYPESdate_to_asc(date1);
239         printf("date_defmt_asc12: %s\n", text);
240         free(text);
241
242         PGTYPEStimestamp_current(&ts1);
243         text = PGTYPEStimestamp_to_asc(ts1);
244         /* can't output this in regression mode */
245         /* printf("timestamp_current: Now: %s\n", text); */
246         free(text);
247
248         ts1 = PGTYPEStimestamp_from_asc("96-02-29", NULL);
249         text = PGTYPEStimestamp_to_asc(ts1);
250         printf("timestamp_to_asc1: %s\n", text);
251         free(text);
252
253         ts1 = PGTYPEStimestamp_from_asc("1994-02-11 3:10:35", NULL);
254         text = PGTYPEStimestamp_to_asc(ts1);
255         printf("timestamp_to_asc2: %s\n", text);
256         free(text);
257
258         ts1 = PGTYPEStimestamp_from_asc("1994-02-11 26:10:35", NULL);
259         text = PGTYPEStimestamp_to_asc(ts1);
260         printf("timestamp_to_asc3: %s\n", text);
261         free(text);
262
263 /*      abc-03:10:35-def-02/11/94-gh  */
264 /*      12345678901234567890123456789 */
265
266         out = (char*) malloc(32);
267         i = PGTYPEStimestamp_fmt_asc(&ts1, out, 31, "abc-%X-def-%x-ghi%%");
268         printf("timestamp_fmt_asc: %d: %s\n", i, out);
269         free(out);
270
271         fmt = "This is a %m/%d/%y %H-%Ml%Stest";
272         in =  "This is a 4/12/80 3-39l12test";
273         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
274         text = PGTYPEStimestamp_to_asc(ts1);
275         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
276         free(text);
277
278         fmt = "%a %b %d %H:%M:%S %z %Y";
279         in =  "Tue Jul 22 17:28:44 +0200 2003";
280         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
281         text = PGTYPEStimestamp_to_asc(ts1);
282         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
283         free(text);
284
285         fmt = "%a %b %d %H:%M:%S %z %Y";
286         in =  "Tue Feb 29 17:28:44 +0200 2000";
287         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
288         text = PGTYPEStimestamp_to_asc(ts1);
289         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
290         free(text);
291
292         fmt = "%a %b %d %H:%M:%S %z %Y";
293         in =  "Tue Feb 29 17:28:44 +0200 1900";
294         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
295         text = PGTYPEStimestamp_to_asc(ts1);
296         printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
297         free(text);
298
299         fmt = "%a %b %d %H:%M:%S %z %Y";
300         in =  "Tue Feb 29 17:28:44 +0200 1996";
301         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
302         text = PGTYPEStimestamp_to_asc(ts1);
303         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
304         free(text);
305
306         fmt = "%b %d %H:%M:%S %z %Y";
307         in =  "      Jul 31 17:28:44 +0200 1996";
308         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
309         text = PGTYPEStimestamp_to_asc(ts1);
310         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
311         free(text);
312
313         fmt = "%b %d %H:%M:%S %z %Y";
314         in =  "      Jul 32 17:28:44 +0200 1996";
315         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
316         text = PGTYPEStimestamp_to_asc(ts1);
317         printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
318         free(text);
319
320         fmt = "%a %b %d %H:%M:%S %z %Y";
321         in =  "Tue Feb 29 17:28:44 +0200 1997";
322         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
323         text = PGTYPEStimestamp_to_asc(ts1);
324         printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
325         free(text);
326
327         fmt = "%";
328         in =  "Tue Jul 22 17:28:44 +0200 2003";
329         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
330         text = PGTYPEStimestamp_to_asc(ts1);
331         printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
332         free(text);
333
334         fmt = "a %";
335         in =  "Tue Jul 22 17:28:44 +0200 2003";
336         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
337         text = PGTYPEStimestamp_to_asc(ts1);
338         printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
339         free(text);
340
341         fmt = "%b, %d %H_%M`%S %z %Y";
342         in =  "    Jul, 22 17_28 `44 +0200  2003  ";
343         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
344         text = PGTYPEStimestamp_to_asc(ts1);
345         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
346         free(text);
347
348         fmt = "%a %b %%%d %H:%M:%S %Z %Y";
349         in =  "Tue Jul %22 17:28:44 CEST 2003";
350         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
351         text = PGTYPEStimestamp_to_asc(ts1);
352         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
353         free(text);
354
355         fmt = "%a %b %%%d %H:%M:%S %Z %Y";
356         in =  "Tue Jul %22 17:28:44 CEST 2003";
357         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
358         text = PGTYPEStimestamp_to_asc(ts1);
359         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
360         free(text);
361
362         fmt = "abc%n %C %B %%%d %H:%M:%S %Z %Y";
363         in =  "abc\n   19 October %22 17:28:44 CEST 2003";
364         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
365         text = PGTYPEStimestamp_to_asc(ts1);
366         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
367         free(text);
368
369         fmt = "abc%n %C %B %%%d %H:%M:%S %Z %y";
370         in =  "abc\n   18 October %34 17:28:44 CEST 80";
371         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
372         text = PGTYPEStimestamp_to_asc(ts1);
373         printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
374         free(text);
375
376         fmt = "";
377         in =  "abc\n   18 October %34 17:28:44 CEST 80";
378         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
379         text = PGTYPEStimestamp_to_asc(ts1);
380         printf("timestamp_defmt_asc(%s, %s) = %s, error (should be error!): %d\n", in, fmt, text, i);
381         free(text);
382
383         fmt = NULL;
384         in =  "1980-04-12 3:49:44      ";
385         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
386         text = PGTYPEStimestamp_to_asc(ts1);
387         printf("timestamp_defmt_asc(%s, NULL) = %s, error: %d\n", in, text, i);
388         free(text);
389
390         fmt = "%B %d, %Y. Time: %I:%M%p";
391         in =  "July 14, 1988. Time: 9:15am";
392         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
393         text = PGTYPEStimestamp_to_asc(ts1);
394         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
395         free(text);
396
397         in = "September 6 at 01:30 pm in the year 1983";
398         fmt = "%B %d at %I:%M %p in the year %Y";
399         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
400         text = PGTYPEStimestamp_to_asc(ts1);
401         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
402         free(text);
403
404         in = "  1976, July 14. Time: 9:15am";
405         fmt = "%Y,   %B %d. Time: %I:%M %p";
406         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
407         text = PGTYPEStimestamp_to_asc(ts1);
408         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
409         free(text);
410
411         in = "  1976, July 14. Time: 9:15 am";
412         fmt = "%Y,   %B %d. Time: %I:%M%p";
413         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
414         text = PGTYPEStimestamp_to_asc(ts1);
415         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
416         free(text);
417
418         in = "  1976, P.M. July 14. Time: 9:15";
419         fmt = "%Y, %P  %B %d. Time: %I:%M";
420         i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
421         text = PGTYPEStimestamp_to_asc(ts1);
422         printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
423         free(text);
424
425         { ECPGtrans(__LINE__, NULL, "rollback ");
426 #line 351 "dt_test.pgc"
427
428 if (sqlca.sqlcode < 0) sqlprint (  );}
429 #line 351 "dt_test.pgc"
430
431         { ECPGdisconnect(__LINE__, "CURRENT");
432 #line 352 "dt_test.pgc"
433
434 if (sqlca.sqlcode < 0) sqlprint (  );}
435 #line 352 "dt_test.pgc"
436
437
438         return (0);
439 }
440