Header And Logo

PostgreSQL
| The world's most advanced open source database.

compat_informix-rfmtdate.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* Needed for informix compatibility */
00007 #include <ecpg_informix.h>
00008 /* End of automatic include section */
00009 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00010 
00011 #line 1 "rfmtdate.pgc"
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <pgtypes_error.h>
00015 #include <sqltypes.h>
00016 
00017 /*
00018  * This file tests various forms of date-input/output by means of
00019  * rfmtdate / rdefmtdate / rstrdate
00020  */
00021 
00022 
00023 static void
00024 check_return(int ret);
00025 
00026 static void
00027 date_test_strdate(char *input)
00028 {
00029     static int i;
00030     date d;
00031     int r, q;
00032     char dbuf[11];
00033 
00034     r = rstrdate(input, &d);
00035     printf("r: %d ", r);
00036     if (r == 0)
00037     {
00038         q = rdatestr(d, dbuf);
00039         printf("q: %d ", q);
00040         if (q == 0)
00041         {
00042             printf("date %d: %s\n", i++, dbuf);
00043         }
00044         else
00045             printf("\n");
00046     }
00047     else
00048         check_return(r);
00049 }
00050 
00051 static void
00052 date_test_defmt(char *fmt, char *input)
00053 {
00054     static int i;
00055     char dbuf[11];
00056     date d;
00057     int q, r;
00058 
00059     r = rdefmtdate(&d, fmt, input);
00060     printf("r: %d ", r);
00061     if (r == 0)
00062     {
00063         q = rdatestr(d, dbuf);
00064         printf("q: %d ", q);
00065         if (q == 0)
00066         {
00067             printf("date %d: %s\n", i++, dbuf);
00068         }
00069         else
00070             printf("\n");
00071     }
00072     else
00073         check_return(r);
00074 }
00075 
00076 static void
00077 date_test_fmt(date d, char *fmt)
00078 {
00079     static int i;
00080     char buf[200];
00081     int r;
00082 
00083     r = rfmtdate(d, fmt, buf);
00084     printf("r: %d ", r);
00085     if (r != 0)
00086         check_return(r);
00087     else
00088         printf("date: %d: %s\n", i++, buf);
00089 }
00090 
00091 
00092 int
00093 main(void)
00094 {
00095     short mdy[3] = { 11, 23, 1959 };
00096     char dbuf[11];
00097     date d;
00098     int r;
00099 
00100     ECPGdebug(1, stderr);
00101 
00102     r = rmdyjul(mdy, &d);
00103     printf("create: r: %d\n", r);
00104     if (r == 0)
00105     {
00106         rdatestr(d, dbuf);
00107         printf("date: %s\n", dbuf);
00108     }
00109 
00110     /* input mask is mmddyyyy */
00111     date_test_strdate("12031994");
00112     date_test_strdate("9.6.1994");
00113 
00114     date_test_fmt(d, "mmddyy");
00115     date_test_fmt(d, "ddmmyy");
00116     date_test_fmt(d, "yymmdd");
00117     date_test_fmt(d, "yy/mm/dd");
00118     date_test_fmt(d, "yy mm dd");
00119     date_test_fmt(d, "yy.mm.dd");
00120     date_test_fmt(d, ".mm.yyyy.dd.");
00121     date_test_fmt(d, "mmm. dd, yyyy");
00122     date_test_fmt(d, "mmm dd yyyy");
00123     date_test_fmt(d, "yyyy dd mm");
00124     date_test_fmt(d, "ddd, mmm. dd, yyyy");
00125     date_test_fmt(d, "(ddd) mmm. dd, yyyy");
00126 
00127     date_test_defmt("ddmmyy", "21-2-54");
00128     date_test_defmt("ddmmyy", "2-12-54");
00129     date_test_defmt("ddmmyy", "20111954");
00130     date_test_defmt("ddmmyy", "130464");
00131     date_test_defmt("mmm.dd.yyyy", "MAR-12-1967");
00132     date_test_defmt("yy/mm/dd", "1954, February 3rd");
00133     date_test_defmt("mmm.dd.yyyy", "041269");
00134     date_test_defmt("yy/mm/dd", "In the year 2525, in the month of July, mankind will be alive on the 28th day");
00135     date_test_defmt("dd-mm-yy", "I said on the 28th of July in the year 2525");
00136     date_test_defmt("mmm.dd.yyyy", "9/14/58");
00137     date_test_defmt("yy/mm/dd", "47/03/29");
00138     date_test_defmt("mmm.dd.yyyy", "oct 28 1975");
00139     date_test_defmt("mmddyy", "Nov 14th, 1985");
00140     /* ok: still contains dd mm yy */
00141     date_test_defmt("bladdfoommbaryybong", "20/11/1954");
00142     /* 1994 is not a leap year, it accepts the date as 01-03-1994 */
00143     date_test_defmt("ddmmyy", "29-02-1994");
00144 
00145     /* ECPG_INFORMIX_ENOTDMY, need "dd", "mm" and "yy" */
00146     date_test_defmt("dmy", "20/11/1954");
00147 
00148     /* ECPG_INFORMIX_ENOSHORTDATE */
00149     date_test_defmt("ddmmyy", "21254");
00150     date_test_defmt("ddmmyy", "    21254    ");
00151 
00152     /* ECPG_INFORMIX_BAD_DAY */
00153     date_test_defmt("ddmmyy", "320494");
00154 
00155     /* ECPG_INFORMIX_BAD_MONTH */
00156     date_test_defmt("mm-yyyy-dd", "13-1993-21");
00157 
00158     /* ECPG_INFORMIX_BAD_YEAR */
00159     /* ??? */
00160 
00161     return (0);
00162 }
00163 
00164 static void
00165 check_return(int ret)
00166 {
00167     switch(ret)
00168     {
00169         case ECPG_INFORMIX_ENOTDMY:
00170             printf("(ECPG_INFORMIX_ENOTDMY)");
00171             break;
00172         case ECPG_INFORMIX_ENOSHORTDATE:
00173             printf("(ECPG_INFORMIX_ENOSHORTDATE)");
00174             break;
00175         case ECPG_INFORMIX_BAD_DAY:
00176             printf("(ECPG_INFORMIX_BAD_DAY)");
00177             break;
00178         case ECPG_INFORMIX_BAD_MONTH:
00179             printf("(ECPG_INFORMIX_BAD_MONTH)");
00180             break;
00181         default:
00182             printf("(unknown ret: %d)", ret);
00183             break;
00184     }
00185     printf("\n");
00186 }