11
11
#include <string.h>
12
12
#include <stdlib.h>
13
13
#include <pgtypes_date.h>
14
+ #include <pgtypes_error.h>
14
15
#include <pgtypes_timestamp.h>
15
16
#include <pgtypes_interval.h>
16
17
22
23
23
24
24
25
25
- #line 8 "dt_test.pgc"
26
+ #line 9 "dt_test.pgc"
26
27
27
28
29
+ static void check_errno (void );
30
+
28
31
int
29
32
main (void )
30
33
{
@@ -34,19 +37,19 @@ main(void)
34
37
35
38
36
39
37
- #line 14 "dt_test.pgc"
40
+ #line 17 "dt_test.pgc"
38
41
date date1 ;
39
42
40
- #line 15 "dt_test.pgc"
43
+ #line 18 "dt_test.pgc"
41
44
timestamp ts1 ;
42
45
43
- #line 16 "dt_test.pgc"
46
+ #line 19 "dt_test.pgc"
44
47
interval * iv1 , iv2 ;
45
48
46
- #line 17 "dt_test.pgc"
49
+ #line 20 "dt_test.pgc"
47
50
char * text ;
48
51
/* exec sql end declare section */
49
- #line 18 "dt_test.pgc"
52
+ #line 21 "dt_test.pgc"
50
53
51
54
date date2 ;
52
55
int mdy [3 ] = { 4 , 19 , 1998 };
@@ -57,31 +60,31 @@ main(void)
57
60
58
61
ECPGdebug (1 , stderr );
59
62
/* exec sql whenever sqlerror do sqlprint ( ) ; */
60
- #line 27 "dt_test.pgc"
63
+ #line 30 "dt_test.pgc"
61
64
62
65
{ ECPGconnect (__LINE__ , 0 , "ecpg1_regression" , NULL , NULL , NULL , 0 );
63
- #line 28 "dt_test.pgc"
66
+ #line 31 "dt_test.pgc"
64
67
65
68
if (sqlca .sqlcode < 0 ) sqlprint ( );}
66
- #line 28 "dt_test.pgc"
69
+ #line 31 "dt_test.pgc"
67
70
68
71
{ 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"
72
+ #line 32 "dt_test.pgc"
70
73
71
74
if (sqlca .sqlcode < 0 ) sqlprint ( );}
72
- #line 29 "dt_test.pgc"
75
+ #line 32 "dt_test.pgc"
73
76
74
77
{ ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "set datestyle to iso" , ECPGt_EOIT , ECPGt_EORT );
75
- #line 30 "dt_test.pgc"
78
+ #line 33 "dt_test.pgc"
76
79
77
80
if (sqlca .sqlcode < 0 ) sqlprint ( );}
78
- #line 30 "dt_test.pgc"
81
+ #line 33 "dt_test.pgc"
79
82
80
83
{ ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "set intervalstyle to postgres_verbose" , ECPGt_EOIT , ECPGt_EORT );
81
- #line 31 "dt_test.pgc"
84
+ #line 34 "dt_test.pgc"
82
85
83
86
if (sqlca .sqlcode < 0 ) sqlprint ( );}
84
- #line 31 "dt_test.pgc"
87
+ #line 34 "dt_test.pgc"
85
88
86
89
87
90
date1 = PGTYPESdate_from_asc (d1 , NULL );
@@ -92,10 +95,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
92
95
ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L ,
93
96
ECPGt_timestamp ,& (ts1 ),(long )1 ,(long )1 ,sizeof (timestamp ),
94
97
ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L , ECPGt_EOIT , ECPGt_EORT );
95
- #line 36 "dt_test.pgc"
98
+ #line 39 "dt_test.pgc"
96
99
97
100
if (sqlca .sqlcode < 0 ) sqlprint ( );}
98
- #line 36 "dt_test.pgc"
101
+ #line 39 "dt_test.pgc"
99
102
100
103
101
104
{ ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "select * from date_test where d = $1 " ,
@@ -105,10 +108,10 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
105
108
ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L ,
106
109
ECPGt_timestamp ,& (ts1 ),(long )1 ,(long )1 ,sizeof (timestamp ),
107
110
ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L , ECPGt_EORT );
108
- #line 38 "dt_test.pgc"
111
+ #line 41 "dt_test.pgc"
109
112
110
113
if (sqlca .sqlcode < 0 ) sqlprint ( );}
111
- #line 38 "dt_test.pgc"
114
+ #line 41 "dt_test.pgc"
112
115
113
116
114
117
text = PGTYPESdate_to_asc (date1 );
@@ -263,10 +266,19 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
263
266
PGTYPESchar_free (text );
264
267
265
268
ts1 = PGTYPEStimestamp_from_asc ("1994-02-11 26:10:35" , NULL );
269
+ /* failure, check error code */
270
+ check_errno ();
266
271
text = PGTYPEStimestamp_to_asc (ts1 );
267
272
printf ("timestamp_to_asc3: %s\n" , text );
268
273
PGTYPESchar_free (text );
269
274
275
+ ts1 = PGTYPEStimestamp_from_asc ("AM95000062" , NULL );
276
+ /* failure, check error code */
277
+ check_errno ();
278
+ text = PGTYPEStimestamp_to_asc (ts1 );
279
+ printf ("timestamp_to_asc4: %s\n" , text );
280
+ PGTYPESchar_free (text );
281
+
270
282
/* abc-03:10:35-def-02/11/94-gh */
271
283
/* 12345678901234567890123456789 */
272
284
@@ -453,17 +465,35 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
453
465
free (out );
454
466
455
467
{ ECPGtrans (__LINE__ , NULL , "rollback" );
456
- #line 381 "dt_test.pgc"
468
+ #line 393 "dt_test.pgc"
457
469
458
470
if (sqlca .sqlcode < 0 ) sqlprint ( );}
459
- #line 381 "dt_test.pgc"
471
+ #line 393 "dt_test.pgc"
460
472
461
473
{ ECPGdisconnect (__LINE__ , "CURRENT" );
462
- #line 382 "dt_test.pgc"
474
+ #line 394 "dt_test.pgc"
463
475
464
476
if (sqlca .sqlcode < 0 ) sqlprint ( );}
465
- #line 382 "dt_test.pgc"
477
+ #line 394 "dt_test.pgc"
466
478
467
479
468
480
return 0 ;
469
481
}
482
+
483
+ static void
484
+ check_errno (void )
485
+ {
486
+ switch (errno )
487
+ {
488
+ case 0 :
489
+ printf ("(no errno set) - " );
490
+ break ;
491
+ case PGTYPES_TS_BAD_TIMESTAMP :
492
+ printf ("(errno == PGTYPES_TS_BAD_TIMESTAMP) - " );
493
+ break ;
494
+ default :
495
+ printf ("(unknown errno (%d))\n" , errno );
496
+ printf ("(libc: (%s)) " , strerror (errno ));
497
+ break ;
498
+ }
499
+ }
0 commit comments