1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
13 #include <pgtypes_date.h>
14 #include <pgtypes_timestamp.h>
15 #include <pgtypes_interval.h>
18 #line 1 "regression.h"
31 /* exec sql begin declare section */
37 #line 14 "dt_test.pgc"
40 #line 15 "dt_test.pgc"
43 #line 16 "dt_test.pgc"
44 interval * iv1 , iv2 ;
46 #line 17 "dt_test.pgc"
48 /* exec sql end declare section */
49 #line 18 "dt_test.pgc"
52 int mdy[3] = { 4, 19, 1998 };
54 char *d1 = "Mon Jan 17 1966";
55 char *t1 = "2000-7-12 17:34:29";
59 /* exec sql whenever sqlerror do sqlprint ( ) ; */
60 #line 27 "dt_test.pgc"
62 { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
63 #line 28 "dt_test.pgc"
65 if (sqlca.sqlcode < 0) sqlprint ( );}
66 #line 28 "dt_test.pgc"
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"
71 if (sqlca.sqlcode < 0) sqlprint ( );}
72 #line 29 "dt_test.pgc"
74 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
75 #line 30 "dt_test.pgc"
77 if (sqlca.sqlcode < 0) sqlprint ( );}
78 #line 30 "dt_test.pgc"
80 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set intervalstyle to postgres_verbose", ECPGt_EOIT, ECPGt_EORT);
81 #line 31 "dt_test.pgc"
83 if (sqlca.sqlcode < 0) sqlprint ( );}
84 #line 31 "dt_test.pgc"
87 date1 = PGTYPESdate_from_asc(d1, NULL);
88 ts1 = PGTYPEStimestamp_from_asc(t1, NULL);
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"
97 if (sqlca.sqlcode < 0) sqlprint ( );}
98 #line 36 "dt_test.pgc"
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"
110 if (sqlca.sqlcode < 0) sqlprint ( );}
111 #line 38 "dt_test.pgc"
114 text = PGTYPESdate_to_asc(date1);
115 printf ("Date: %s\n", text);
118 text = PGTYPEStimestamp_to_asc(ts1);
119 printf ("timestamp: %s\n", text);
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);
128 PGTYPESdate_mdyjul(mdy, &date2);
129 printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
131 mdy[0] = mdy[1] = mdy[2] = 0;
133 printf("date seems to get encoded to julian %ld\n", date2);
135 PGTYPESdate_julmdy(date2, mdy);
136 printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
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);
149 /* rdate_defmt_asc() */
151 date1 = 0; text = "";
153 in = "In the year 1995, the month of December, it is the 25th day";
154 /* 0123456789012345678901234567890123456789012345678901234567890
157 PGTYPESdate_defmt_asc(&date1, fmt, in);
158 text = PGTYPESdate_to_asc(date1);
159 printf("date_defmt_asc1: %s\n", text);
162 date1 = 0; text = "";
163 fmt = "mmmm. dd. yyyy";
165 PGTYPESdate_defmt_asc(&date1, fmt, in);
166 text = PGTYPESdate_to_asc(date1);
167 printf("date_defmt_asc2: %s\n", text);
170 date1 = 0; text = "";
173 PGTYPESdate_defmt_asc(&date1, fmt, in);
174 text = PGTYPESdate_to_asc(date1);
175 printf("date_defmt_asc3: %s\n", text);
178 date1 = 0; text = "";
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);
186 date1 = 0; text = "";
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);
194 date1 = 0; text = "";
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);
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);
210 date1 = 0; text = "";
211 fmt = "mmm. dd. yyyy";
213 PGTYPESdate_defmt_asc(&date1, fmt, in);
214 text = PGTYPESdate_to_asc(date1);
215 printf("date_defmt_asc8: %s\n", text);
218 date1 = 0; text = "";
221 PGTYPESdate_defmt_asc(&date1, fmt, in);
222 text = PGTYPESdate_to_asc(date1);
223 printf("date_defmt_asc9: %s\n", text);
226 date1 = 0; text = "";
227 fmt = "yyyy fierj mm dd.";
229 PGTYPESdate_defmt_asc(&date1, fmt, in);
230 text = PGTYPESdate_to_asc(date1);
231 printf("date_defmt_asc10: %s\n", text);
234 date1 = 0; text = "";
237 PGTYPESdate_defmt_asc(&date1, fmt, in);
238 text = PGTYPESdate_to_asc(date1);
239 printf("date_defmt_asc12: %s\n", text);
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); */
248 ts1 = PGTYPEStimestamp_from_asc("96-02-29", NULL);
249 text = PGTYPEStimestamp_to_asc(ts1);
250 printf("timestamp_to_asc1: %s\n", text);
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);
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);
263 /* abc-03:10:35-def-02/11/94-gh */
264 /* 12345678901234567890123456789 */
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
425 { ECPGtrans(__LINE__, NULL, "rollback ");
426 #line 351 "dt_test.pgc"
428 if (sqlca.sqlcode < 0) sqlprint ( );}
429 #line 351 "dt_test.pgc"
431 { ECPGdisconnect(__LINE__, "CURRENT");
432 #line 352 "dt_test.pgc"
434 if (sqlca.sqlcode < 0) sqlprint ( );}
435 #line 352 "dt_test.pgc"