PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
compat_informix-rfmtdate.c
Go to the documentation of this file.
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 /* Needed for informix compatibility */
7 #include <ecpg_informix.h>
8 /* End of automatic include section */
9 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
10 
11 #line 1 "rfmtdate.pgc"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <pgtypes_error.h>
15 #include <sqltypes.h>
16 
17 /*
18  * This file tests various forms of date-input/output by means of
19  * rfmtdate / rdefmtdate / rstrdate
20  */
21 
22 
23 static void
24 check_return(int ret);
25 
26 static void
27 date_test_strdate(char *input)
28 {
29  static int i;
30  date d;
31  int r, q;
32  char dbuf[11];
33 
34  r = rstrdate(input, &d);
35  printf("r: %d ", r);
36  if (r == 0)
37  {
38  q = rdatestr(d, dbuf);
39  printf("q: %d ", q);
40  if (q == 0)
41  {
42  printf("date %d: %s\n", i++, dbuf);
43  }
44  else
45  printf("\n");
46  }
47  else
48  check_return(r);
49 }
50 
51 static void
52 date_test_defmt(char *fmt, char *input)
53 {
54  static int i;
55  char dbuf[11];
56  date d;
57  int q, r;
58 
59  r = rdefmtdate(&d, fmt, input);
60  printf("r: %d ", r);
61  if (r == 0)
62  {
63  q = rdatestr(d, dbuf);
64  printf("q: %d ", q);
65  if (q == 0)
66  {
67  printf("date %d: %s\n", i++, dbuf);
68  }
69  else
70  printf("\n");
71  }
72  else
73  check_return(r);
74 }
75 
76 static void
77 date_test_fmt(date d, char *fmt)
78 {
79  static int i;
80  char buf[200];
81  int r;
82 
83  r = rfmtdate(d, fmt, buf);
84  printf("r: %d ", r);
85  if (r != 0)
86  check_return(r);
87  else
88  printf("date: %d: %s\n", i++, buf);
89 }
90 
91 
92 int
93 main(void)
94 {
95  short mdy[3] = { 11, 23, 1959 };
96  char dbuf[11];
97  date d;
98  int r;
99 
100  ECPGdebug(1, stderr);
101 
102  r = rmdyjul(mdy, &d);
103  printf("create: r: %d\n", r);
104  if (r == 0)
105  {
106  rdatestr(d, dbuf);
107  printf("date: %s\n", dbuf);
108  }
109 
110  /* input mask is mmddyyyy */
111  date_test_strdate("12031994");
112  date_test_strdate("9.6.1994");
113 
114  date_test_fmt(d, "mmddyy");
115  date_test_fmt(d, "ddmmyy");
116  date_test_fmt(d, "yymmdd");
117  date_test_fmt(d, "yy/mm/dd");
118  date_test_fmt(d, "yy mm dd");
119  date_test_fmt(d, "yy.mm.dd");
120  date_test_fmt(d, ".mm.yyyy.dd.");
121  date_test_fmt(d, "mmm. dd, yyyy");
122  date_test_fmt(d, "mmm dd yyyy");
123  date_test_fmt(d, "yyyy dd mm");
124  date_test_fmt(d, "ddd, mmm. dd, yyyy");
125  date_test_fmt(d, "(ddd) mmm. dd, yyyy");
126 
127  date_test_defmt("ddmmyy", "21-2-54");
128  date_test_defmt("ddmmyy", "2-12-54");
129  date_test_defmt("ddmmyy", "20111954");
130  date_test_defmt("ddmmyy", "130464");
131  date_test_defmt("mmm.dd.yyyy", "MAR-12-1967");
132  date_test_defmt("yy/mm/dd", "1954, February 3rd");
133  date_test_defmt("mmm.dd.yyyy", "041269");
134  date_test_defmt("yy/mm/dd", "In the year 2525, in the month of July, mankind will be alive on the 28th day");
135  date_test_defmt("dd-mm-yy", "I said on the 28th of July in the year 2525");
136  date_test_defmt("mmm.dd.yyyy", "9/14/58");
137  date_test_defmt("yy/mm/dd", "47/03/29");
138  date_test_defmt("mmm.dd.yyyy", "oct 28 1975");
139  date_test_defmt("mmddyy", "Nov 14th, 1985");
140  /* ok: still contains dd mm yy */
141  date_test_defmt("bladdfoommbaryybong", "20/11/1954");
142  /* 1994 is not a leap year, it accepts the date as 01-03-1994 */
143  date_test_defmt("ddmmyy", "29-02-1994");
144 
145  /* ECPG_INFORMIX_ENOTDMY, need "dd", "mm" and "yy" */
146  date_test_defmt("dmy", "20/11/1954");
147 
148  /* ECPG_INFORMIX_ENOSHORTDATE */
149  date_test_defmt("ddmmyy", "21254");
150  date_test_defmt("ddmmyy", " 21254 ");
151 
152  /* ECPG_INFORMIX_BAD_DAY */
153  date_test_defmt("ddmmyy", "320494");
154 
155  /* ECPG_INFORMIX_BAD_MONTH */
156  date_test_defmt("mm-yyyy-dd", "13-1993-21");
157 
158  /* ECPG_INFORMIX_BAD_YEAR */
159  /* ??? */
160 
161  return (0);
162 }
163 
164 static void
165 check_return(int ret)
166 {
167  switch(ret)
168  {
170  printf("(ECPG_INFORMIX_ENOTDMY)");
171  break;
173  printf("(ECPG_INFORMIX_ENOSHORTDATE)");
174  break;
176  printf("(ECPG_INFORMIX_BAD_DAY)");
177  break;
179  printf("(ECPG_INFORMIX_BAD_MONTH)");
180  break;
181  default:
182  printf("(unknown ret: %d)", ret);
183  break;
184  }
185  printf("\n");
186 }
int rdatestr(date d, char *str)
Definition: informix.c:502
#define ECPG_INFORMIX_BAD_MONTH
Definition: ecpg_informix.h:20
int rstrdate(char *str, date *d)
Definition: informix.c:523
long date
Definition: pgtypes_date.h:8
static void check_return(int ret)
int rdefmtdate(date *d, char *fmt, char *str)
Definition: informix.c:548
static char * buf
Definition: pg_test_fsync.c:66
static void date_test_defmt(char *fmt, char *input)
static void date_test_fmt(date d, char *fmt)
#define ECPGdebug(X, Y)
#define ECPG_INFORMIX_ENOSHORTDATE
Definition: ecpg_informix.h:22
static void date_test_strdate(char *input)
int main(void)
int i
#define ECPG_INFORMIX_ENOTDMY
Definition: ecpg_informix.h:25
int rfmtdate(date d, char *fmt, char *str)
Definition: informix.c:574
#define ECPG_INFORMIX_BAD_DAY
Definition: ecpg_informix.h:21
int rmdyjul(short mdy[3], date *d)
Definition: informix.c:587