Commit 999f1298 authored by Michael Meskes's avatar Michael Meskes

Moved Informix stuff to its own compat library. Interval datetype is now fully functional.

parent 82a91eb5
......@@ -1376,7 +1376,17 @@ Thu Mar 27 15:23:58 CET 2003
- Some more updates to pgtypeslib.
- Set optimization to -O1 until I find the reason why code is broken
with -O2.
Sat Mar 29 22:03:16 CET 2003
- Moved Informix compatibility stuff its own library.
- Added interval datetypes.
Sun Mar 30 13:43:13 CEST 2003
- Interval datetype now fully functional.
- Set ecpg version to 2.12.0.
- Set ecpg library to 3.4.2.
- Set pgtypes library to 1.0.0
- Set compat library to 1.0.0
......@@ -6,11 +6,13 @@ all install installdirs uninstall dep depend distprep:
$(MAKE) -C include $@
$(MAKE) -C ecpglib $@
$(MAKE) -C pgtypeslib $@
$(MAKE) -C compatlib $@
$(MAKE) -C preproc $@
clean distclean maintainer-clean:
-$(MAKE) -C include $@
-$(MAKE) -C ecpglib $@
-$(MAKE) -C pgtypeslib $@
-$(MAKE) -C compatlib $@
-$(MAKE) -C preproc $@
-$(MAKE) -C test clean
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.6 2003/03/27 14:29:17 meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.7 2003/03/30 11:48:18 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
......@@ -847,7 +847,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
{
for (element = 0; element < var->arrsize; element++)
{
str = PGTYPESnumeric_ntoa((Numeric *)((var + var->offset * element)->value));
str = PGTYPESnumeric_ntoa((Numeric *)((var + var->offset * element)->value), 0);
slen = strlen (str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
......@@ -863,7 +863,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
}
else
{
str = PGTYPESnumeric_ntoa((Numeric *)(var->value));
str = PGTYPESnumeric_ntoa((Numeric *)(var->value), 0);
slen = strlen (str);
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
......@@ -1239,7 +1239,9 @@ ECPGexecute(struct statement * stmt)
{
ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
stmt->lineno, notify->relname, notify->be_pid);
PQfreemem(notify);
/* PQfreemem(notify);*/
free(notify);
#warning Remove PQfreemem define
}
return status;
......
......@@ -2,6 +2,9 @@
* This file contains stuff needed to be as compatible to Informix as possible.
*/
#include <decimal.h>
#include <datetime.h>
#define SQLNOTFOUND 100
#ifndef Date
......
#ifndef PGTYPES_DATETIME
#define PGTYPES_DATETIME
#include <pgtypes_timestamp.h>
#define Date long
extern Date PGTYPESdate_atod(char *, char **);
extern char *PGTYPESdate_dtoa(Date);
extern int PGTYPESdate_julmdy(Date, int*);
extern int PGTYPESdate_mdyjul(int*, Date *);
extern int PGTYPESdate_day(Date);
extern Date PGTYPESdate_ttod(Timestamp);
extern void PGTYPESdate_julmdy(Date, int*);
extern void PGTYPESdate_mdyjul(int*, Date *);
extern int PGTYPESdate_dayofweek(Date);
extern void PGTYPESdate_today (Date *);
extern int PGTYPESdate_defmtdate(Date *, char *, char *);
extern int PGTYPESdate_fmtdate(Date, char *, char *);
#endif /* PGTYPES_DATETIME */
#define PGTYPES_OVERFLOW 201
#define PGTYPES_BAD_NUMERIC 202
#define PGTYPES_DIVIDE_ZERO 203
#define PGTYPES_NUM_OVERFLOW 201
#define PGTYPES_NUM_BAD_NUMERIC 202
#define PGTYPES_NUM_DIVIDE_ZERO 203
#define PGTYPES_BAD_DATE 210
#define PGTYPES_DATE_BAD_DATE 210
#define PGTYPES_DATE_ERR_EARGS 211
#define PGTYPES_DATE_ERR_ENOSHORTDATE 212
#define PGTYPES_DATE_ERR_ENOTDMY 213
#define PGTYPES_DATE_BAD_DAY 214
#define PGTYPES_DATE_BAD_MONTH 215
#define PGTYPES_BAD_TIMESTAMP 220
#define PGTYPES_TS_BAD_TIMESTAMP 220
#define PGTYPES_INTVL_BAD_INTERVAL 230
......@@ -23,7 +23,7 @@ typedef struct
Numeric *PGTYPESnew(void);
void PGTYPESnumeric_free(Numeric *);
Numeric *PGTYPESnumeric_aton(char *, char **);
char *PGTYPESnumeric_ntoa(Numeric *);
char *PGTYPESnumeric_ntoa(Numeric *, int);
int PGTYPESnumeric_add(Numeric *, Numeric *, Numeric *);
int PGTYPESnumeric_sub(Numeric *, Numeric *, Numeric *);
int PGTYPESnumeric_mul(Numeric *, Numeric *, Numeric *);
......
......@@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.3 2003/03/27 14:29:17 meskes Exp $
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.4 2003/03/30 11:48:18 meskes Exp $
#
#-------------------------------------------------------------------------
......@@ -18,7 +18,7 @@ SO_MINOR_VERSION= 0.0
override CPPFLAGS := -O1 -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS)
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o
all: all-lib
......
This diff is collapsed.
......@@ -296,6 +296,7 @@ extern void GetEpochTime(struct tm *);
extern int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
extern int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, int *, bool);
extern void j2date(int, int *, int *, int *);
extern void GetCurrentDateTime(struct tm*);
extern int date2j(int, int, int);
extern double rint(double x);
......
......@@ -426,10 +426,81 @@ static datetkn datetktbl[] = {
{ZULU, TZ, POS(0)}, /* UTC */
};
static datetkn deltatktbl[] = {
/* text, token, lexval */
{"@", IGNORE_DTF, 0}, /* postgres relative prefix */
{DAGO, AGO, 0}, /* "ago" indicates negative time offset */
{"c", UNITS, DTK_CENTURY}, /* "century" relative */
{"cent", UNITS, DTK_CENTURY}, /* "century" relative */
{"centuries", UNITS, DTK_CENTURY}, /* "centuries" relative */
{DCENTURY, UNITS, DTK_CENTURY}, /* "century" relative */
{"d", UNITS, DTK_DAY}, /* "day" relative */
{DDAY, UNITS, DTK_DAY}, /* "day" relative */
{"days", UNITS, DTK_DAY}, /* "days" relative */
{"dec", UNITS, DTK_DECADE}, /* "decade" relative */
{DDECADE, UNITS, DTK_DECADE}, /* "decade" relative */
{"decades", UNITS, DTK_DECADE}, /* "decades" relative */
{"decs", UNITS, DTK_DECADE}, /* "decades" relative */
{"h", UNITS, DTK_HOUR}, /* "hour" relative */
{DHOUR, UNITS, DTK_HOUR}, /* "hour" relative */
{"hours", UNITS, DTK_HOUR}, /* "hours" relative */
{"hr", UNITS, DTK_HOUR}, /* "hour" relative */
{"hrs", UNITS, DTK_HOUR}, /* "hours" relative */
{INVALID, RESERV, DTK_INVALID}, /* reserved for invalid time */
{"m", UNITS, DTK_MINUTE}, /* "minute" relative */
{"microsecon", UNITS, DTK_MICROSEC}, /* "microsecond" relative */
{"mil", UNITS, DTK_MILLENNIUM}, /* "millennium" relative */
{"millennia", UNITS, DTK_MILLENNIUM}, /* "millennia" relative */
{DMILLENNIUM, UNITS, DTK_MILLENNIUM}, /* "millennium" relative */
{"millisecon", UNITS, DTK_MILLISEC}, /* relative */
{"mils", UNITS, DTK_MILLENNIUM}, /* "millennia" relative */
{"min", UNITS, DTK_MINUTE}, /* "minute" relative */
{"mins", UNITS, DTK_MINUTE}, /* "minutes" relative */
{DMINUTE, UNITS, DTK_MINUTE}, /* "minute" relative */
{"minutes", UNITS, DTK_MINUTE}, /* "minutes" relative */
{"mon", UNITS, DTK_MONTH}, /* "months" relative */
{"mons", UNITS, DTK_MONTH}, /* "months" relative */
{DMONTH, UNITS, DTK_MONTH}, /* "month" relative */
{"months", UNITS, DTK_MONTH},
{"ms", UNITS, DTK_MILLISEC},
{"msec", UNITS, DTK_MILLISEC},
{DMILLISEC, UNITS, DTK_MILLISEC},
{"mseconds", UNITS, DTK_MILLISEC},
{"msecs", UNITS, DTK_MILLISEC},
{"qtr", UNITS, DTK_QUARTER}, /* "quarter" relative */
{DQUARTER, UNITS, DTK_QUARTER}, /* "quarter" relative */
{"reltime", IGNORE_DTF, 0}, /* pre-v6.1 "Undefined Reltime" */
{"s", UNITS, DTK_SECOND},
{"sec", UNITS, DTK_SECOND},
{DSECOND, UNITS, DTK_SECOND},
{"seconds", UNITS, DTK_SECOND},
{"secs", UNITS, DTK_SECOND},
{DTIMEZONE, UNITS, DTK_TZ}, /* "timezone" time offset */
{"timezone_h", UNITS, DTK_TZ_HOUR}, /* timezone hour units */
{"timezone_m", UNITS, DTK_TZ_MINUTE}, /* timezone minutes units */
{"undefined", RESERV, DTK_INVALID}, /* pre-v6.1 invalid time */
{"us", UNITS, DTK_MICROSEC}, /* "microsecond" relative */
{"usec", UNITS, DTK_MICROSEC}, /* "microsecond" relative */
{DMICROSEC, UNITS, DTK_MICROSEC}, /* "microsecond" relative */
{"useconds", UNITS, DTK_MICROSEC}, /* "microseconds" relative */
{"usecs", UNITS, DTK_MICROSEC}, /* "microseconds" relative */
{"w", UNITS, DTK_WEEK}, /* "week" relative */
{DWEEK, UNITS, DTK_WEEK}, /* "week" relative */
{"weeks", UNITS, DTK_WEEK}, /* "weeks" relative */
{"y", UNITS, DTK_YEAR}, /* "year" relative */
{DYEAR, UNITS, DTK_YEAR}, /* "year" relative */
{"years", UNITS, DTK_YEAR}, /* "years" relative */
{"yr", UNITS, DTK_YEAR}, /* "year" relative */
{"yrs", UNITS, DTK_YEAR}, /* "years" relative */
};
static unsigned int szdatetktbl = sizeof datetktbl / sizeof datetktbl[0];
static unsigned int szdeltatktbl = sizeof deltatktbl / sizeof deltatktbl[0];
static datetkn *datecache[MAXDATEFIELDS] = {NULL};
static datetkn *deltacache[MAXDATEFIELDS] = {NULL};
char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", NULL};
......@@ -561,6 +632,39 @@ datebsearch(char *key, datetkn *base, unsigned int nel)
return NULL;
}
/* DecodeUnits()
* Decode text string using lookup table.
* This routine supports time interval decoding.
*/
int
DecodeUnits(int field, char *lowtoken, int *val)
{
int type;
datetkn *tp;
if ((deltacache[field] != NULL)
&& (strncmp(lowtoken, deltacache[field]->token, TOKMAXLEN) == 0))
tp = deltacache[field];
else
tp = datebsearch(lowtoken, deltatktbl, szdeltatktbl);
deltacache[field] = tp;
if (tp == NULL)
{
type = UNKNOWN_FIELD;
*val = 0;
}
else
{
type = tp->type;
if ((type == TZ) || (type == DTZ))
*val = FROMVAL(tp);
else
*val = tp->value;
}
return type;
} /* DecodeUnits() */
/*
* Calendar time to Julian date conversions.
* Julian date is commonly used in astronomical applications,
......@@ -1088,7 +1192,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
#endif
}
static void
void
GetCurrentDateTime(struct tm * tm)
{
int tz;
......
......@@ -9,7 +9,6 @@
#include "c.h"
#include "extern.h"
#include "pgtypes_error.h"
#include "decimal.h"
#define Max(x, y) ((x) > (y) ? (x) : (y))
#define Min(x, y) ((x) < (y) ? (x) : (y))
......@@ -96,7 +95,7 @@ apply_typmod(Numeric *var, long typmod)
if (tweight >= maxweight && i < var->ndigits)
{
errno = PGTYPES_OVERFLOW;
errno = PGTYPES_NUM_OVERFLOW;
return -1;
}
}
......@@ -188,7 +187,7 @@ set_var_from_str(char *str, char **ptr, Numeric *dest)
if (!isdigit((unsigned char) *(*ptr)))
{
errno=PGTYPES_BAD_NUMERIC;
errno=PGTYPES_NUM_BAD_NUMERIC;
return -1;
}
......@@ -206,7 +205,7 @@ set_var_from_str(char *str, char **ptr, Numeric *dest)
{
if (have_dp)
{
errno = PGTYPES_BAD_NUMERIC;
errno = PGTYPES_NUM_BAD_NUMERIC;
return -1;
}
have_dp = TRUE;
......@@ -227,14 +226,14 @@ set_var_from_str(char *str, char **ptr, Numeric *dest)
exponent = strtol((*ptr), &endptr, 10);
if (endptr == (*ptr))
{
errno = PGTYPES_BAD_NUMERIC;
errno = PGTYPES_NUM_BAD_NUMERIC;
return -1;
}
(*ptr) = endptr;
if (exponent > NUMERIC_MAX_PRECISION ||
exponent < -NUMERIC_MAX_PRECISION)
{
errno = PGTYPES_BAD_NUMERIC;
errno = PGTYPES_NUM_BAD_NUMERIC;
return -1;
}
dest->weight += (int) exponent;
......@@ -248,7 +247,7 @@ set_var_from_str(char *str, char **ptr, Numeric *dest)
{
if (!isspace((unsigned char) *(*ptr)))
{
errno = PGTYPES_BAD_NUMERIC;
errno = PGTYPES_NUM_BAD_NUMERIC;
return -1;
}
(*ptr)++;
......@@ -402,9 +401,12 @@ PGTYPESnumeric_aton(char *str, char **endptr)
* ----------
*/
char *
PGTYPESnumeric_ntoa(Numeric *num)
PGTYPESnumeric_ntoa(Numeric *num, int dscale)
{
return(get_str_from_var(num, num->dscale));
if (dscale <= 0)
dscale = num->dscale;
return(get_str_from_var(num, dscale));
}
/* ----------
......@@ -1117,7 +1119,7 @@ PGTYPESnumeric_div(Numeric *var1, Numeric *var2, Numeric *result)
ndigits_tmp = var2->ndigits + 1;
if (ndigits_tmp == 1)
{
errno= PGTYPES_DIVIDE_ZERO;
errno= PGTYPES_NUM_DIVIDE_ZERO;
return -1;
}
......@@ -1320,7 +1322,7 @@ PGTYPESnumeric_cmp(Numeric *var1, Numeric *var2) {
return -1;
}
errno = PGTYPES_BAD_NUMERIC;
errno = PGTYPES_NUM_BAD_NUMERIC;
return INT_MAX;
}
......@@ -1438,7 +1440,7 @@ numericvar_to_double_no_overflow(Numeric *var, double *dp)
{
/* shouldn't happen ... */
free(tmp);
errno = PGTYPES_BAD_NUMERIC;
errno = PGTYPES_NUM_BAD_NUMERIC;
return -1;
}
*dp = val;
......@@ -1466,7 +1468,7 @@ PGTYPESnumeric_ntoi(Numeric* nv, int* ip) {
return i;
if (l < -INT_MAX || l > INT_MAX) {
errno = PGTYPES_OVERFLOW;
errno = PGTYPES_NUM_OVERFLOW;
return -1;
}
......@@ -1488,7 +1490,7 @@ PGTYPESnumeric_ntol(Numeric* nv, long* lp) {
l++;
}
if (l > LONG_MAX || l < 0) {
errno = PGTYPES_OVERFLOW;
errno = PGTYPES_NUM_OVERFLOW;
return -1;
}
......@@ -1499,196 +1501,3 @@ PGTYPESnumeric_ntol(Numeric* nv, long* lp) {
return 0;
}
/* Finally we need some wrappers for the INFORMIX functions */
int
decadd(Numeric *arg1, Numeric *arg2, Numeric *sum)
{
int i = PGTYPESnumeric_add(arg1, arg2, sum);
if (i == 0) /* No error */
return 0;
if (errno == PGTYPES_OVERFLOW)
return -1200;
return -1201;
}
int
deccmp(Numeric *arg1, Numeric *arg2)
{
int i = PGTYPESnumeric_cmp(arg1, arg2);
/* TODO: Need to return DECUNKNOWN instead of PGTYPES_BAD_NUMERIC */
return (i);
}
void
deccopy(Numeric *src, Numeric *target)
{
PGTYPESnumeric_copy(src, target);
}
static char *
strndup(char *str, int len)
{
int real_len = strlen(str);
int use_len = (real_len > len) ? len : real_len;
char *new = pgtypes_alloc(use_len + 1);
if (new)
{
memcpy(str, new, use_len);
new[use_len] = '\0';
}
return new;
}
int
deccvasc(char *cp, int len, Numeric *np)
{
char *str = strndup(cp, len); /* Numeric_in always converts the complete string */
int ret = 0;
if (!str)
ret = -1201;
else
{
np = PGTYPESnumeric_aton(str, NULL);
if (!np)
{
switch (errno)
{
case PGTYPES_OVERFLOW: ret = -1200;
break;
case PGTYPES_BAD_NUMERIC: ret = -1213;
break;
default: ret = -1216;
break;
}
}
}
return ret;
}
int
deccvdbl(double dbl, Numeric *np)
{
return(PGTYPESnumeric_dton(dbl, np));
}
int
deccvint(int in, Numeric *np)
{
return(PGTYPESnumeric_iton(in, np));
}
int
deccvlong(long lng, Numeric *np)
{
return(PGTYPESnumeric_lton(lng, np));
}
int
decdiv(Numeric *n1, Numeric *n2, Numeric *n3)
{
int i = PGTYPESnumeric_div(n1, n2, n3), ret = 0;
if (i != 0)
switch (errno)
{
case PGTYPES_DIVIDE_ZERO: ret = -1202;
break;
case PGTYPES_OVERFLOW: ret = -1200;
break;
default: ret = -1201;
break;
}
return ret;
}
int
decmul(Numeric *n1, Numeric *n2, Numeric *n3)
{
int i = PGTYPESnumeric_mul(n1, n2, n3), ret = 0;
if (i != 0)
switch (errno)
{
case PGTYPES_OVERFLOW: ret = -1200;
break;
default: ret = -1201;
break;
}
return ret;
}
int
decsub(Numeric *n1, Numeric *n2, Numeric *n3)
{
int i = PGTYPESnumeric_sub(n1, n2, n3), ret = 0;
if (i != 0)
switch (errno)
{
case PGTYPES_OVERFLOW: ret = -1200;
break;
default: ret = -1201;
break;
}
return ret;
}
int
dectoasc(Numeric *np, char *cp, int len, int right)
{
char *str;
if (right >= 0)
str = get_str_from_var(np, right);
else
str = get_str_from_var(np, np->dscale);
if (!str)
return -1;
/* TODO: have to take care of len here and create exponatial notion if necessary */
strncpy(cp, str, len);
free (str);
return 0;
}
int
dectodbl(Numeric *np, double *dblp)
{
return(PGTYPESnumeric_ntod(np, dblp));
}
int
dectoint(Numeric *np, int *ip)
{
int ret = PGTYPESnumeric_ntoi(np, ip);
if (ret == PGTYPES_OVERFLOW)
ret = -1200;
return ret;
}
int
dectolong(Numeric *np, long *lngp)
{
int ret = PGTYPESnumeric_ntol(np, lngp);
if (ret == PGTYPES_OVERFLOW)
ret = -1200;
return ret;
}
......@@ -13,7 +13,6 @@
#include "extern.h"
#include "pgtypes_error.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
#include "datetime.h"
#ifdef HAVE_INT64_TIMESTAMP
......@@ -288,14 +287,14 @@ PGTYPEStimestamp_atot(char *str, char **endptr)
errno = 0;
if (strlen(str) >= sizeof(lowstr))
{
errno = PGTYPES_BAD_TIMESTAMP;
errno = PGTYPES_TS_BAD_TIMESTAMP;
return (noresult);
}
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz, 0) != 0))
{
errno = PGTYPES_BAD_TIMESTAMP;
errno = PGTYPES_TS_BAD_TIMESTAMP;
return (noresult);
}
......@@ -304,7 +303,7 @@ PGTYPEStimestamp_atot(char *str, char **endptr)
case DTK_DATE:
if (tm2timestamp(tm, fsec, NULL, &result) != 0)
{
errno = PGTYPES_BAD_TIMESTAMP;
errno = PGTYPES_TS_BAD_TIMESTAMP;
return (noresult);;
}
break;
......@@ -322,11 +321,11 @@ PGTYPEStimestamp_atot(char *str, char **endptr)
break;
case DTK_INVALID:
errno = PGTYPES_BAD_TIMESTAMP;
errno = PGTYPES_TS_BAD_TIMESTAMP;
return (noresult);
default:
errno = PGTYPES_BAD_TIMESTAMP;
errno = PGTYPES_TS_BAD_TIMESTAMP;
return (noresult);
}
......@@ -350,67 +349,8 @@ PGTYPEStimestamp_ttoa(Timestamp tstamp)
EncodeDateTime(tm, fsec, NULL, &tzn, DateStyle, buf, 0);
else
{
errno = PGTYPES_BAD_TIMESTAMP;
errno = PGTYPES_TS_BAD_TIMESTAMP;
return NULL;
}
return pgtypes_strdup(buf);
}
void
dtcurrent (Timestamp *ts)
{
return;
}
int
dtcvasc (char *str, Timestamp *ts)
{
return 0;
}
int
dtsub (Timestamp *ts1, Timestamp *ts2, Interval *iv)
{
return 0;
}
int
dttoasc (Timestamp *ts, char *output)
{
return 0;
}
int
dttofmtasc (Timestamp *ts, char *output, int str_len, char *fmtstr)
{
return 0;
}
int
intoasc(Interval *i, char *str)
{
return 0;
}
Interval *
PGTYPESinterval_atoi(char *str, char **endptr)
{
Interval *result = NULL;
return result;
}
char *
PGTYPESinterval_itoa(Interval *intvl)
{
char buf[MAXDATELEN + 1];
return pgtypes_strdup(buf);
}
int
PGTYPESinterval_copy(Interval *intvlsrc, Interval *intrcldest)
{
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pgtypes_date.h>
#include <pgtypes_timestamp.h>
#include <pgtypes_interval.h>
int
main()
......@@ -8,38 +11,142 @@ main()
exec sql begin declare section;
date date1;
timestamp ts1;
interval iv1;
char *text;
exec sql end declare section;
#if 0
Date date2;
short int mdy[3] = { 4, 19, 1998 };
#endif
int mdy[3] = { 4, 19, 1998 };
char *fmt, *out, *in;
FILE *dbgs;
if ((dbgs = fopen("log", "w")) != NULL)
ECPGdebug(1, dbgs);
exec sql whenever sqlerror do sqlprint();
exec sql connect to mm;
exec sql create table date_test (d date, ts timestamp);
exec sql create table date_test (d date, ts timestamp, iv interval);
exec sql insert into date_test(d, ts) values ('Mon Jan 17 1966', '2000-7-12 17:34:29');
exec sql insert into date_test(d, ts, iv) values ('Mon Jan 17 1966', '2000-7-12 17:34:29', now()-'Mon Jan 17 1966');
exec sql select * into :date1, :ts1 from date_test;
exec sql select * into :date1, :ts1 , :iv1 from date_test;
text = PGTYPESdate_dtoa(date1);
printf ("Date: %s\n", text);
ts1 = PGTYPEStimestamp_atot("2000-7-12 17:34:29", NULL);
text = PGTYPEStimestamp_ttoa(ts1);
printf ("timestamp: %s\n", text);
#if 0
text = PGTYPESinterval_itoa(&iv1);
printf ("interval: %s\n", text);
PGTYPESdate_mdyjul(mdy, &date2);
printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
/* reset */
mdy[0] = mdy[1] = mdy[2] = 0;
printf("date seems to get encoded to julian %ld\n", date2);
PGTYPESdate_julmdy(date2, mdy);
printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]);
#endif
ts1 = PGTYPEStimestamp_atot("2003-12-04 17:34:29", NULL);
text = PGTYPEStimestamp_ttoa(ts1);
printf("date_day of %s is %d\n", text, PGTYPESdate_dayofweek(ts1));
PGTYPESdate_today(&date1);
text = PGTYPESdate_dtoa(date1);
printf("today is %s\n", text);
fmt = "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end";
out = (char*) malloc(strlen(fmt) + 1);
PGTYPESdate_fmtdate(date1, fmt, out);
printf("Today in format \"%s\" is \"%s\"\n", fmt, out);
free(out);
/* rdefmtdate() */
date1 = 0; text = "";
fmt = "yy/mm/dd";
in = "In the year 1995, the month of December, it is the 25th day";
/* 0123456789012345678901234567890123456789012345678901234567890
* 0 1 2 3 4 5 6
*/
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate1: %s\n", text);
date1 = 0; text = "";
fmt = "mmmm. dd. yyyy";
in = "12/25/95";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate2: %s\n", text);
date1 = 0; text = "";
fmt = "yy/mm/dd";
in = "95/12/25";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate3: %s\n", text);
date1 = 0; text = "";
fmt = "yy/mm/dd";
in = "1995, December 25th";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate4: %s\n", text);
date1 = 0; text = "";
fmt = "dd-mm-yy";
in = "This is 25th day of December, 1995";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate5: %s\n", text);
date1 = 0; text = "";
fmt = "mmddyy";
in = "Dec. 25th, 1995";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate6: %s\n", text);
date1 = 0; text = "";
fmt = "mmm. dd. yyyy";
in = "dec 25th 1995";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate7: %s\n", text);
date1 = 0; text = "";
fmt = "mmm. dd. yyyy";
in = "DEC-25-1995";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate8: %s\n", text);
date1 = 0; text = "";
fmt = "mm yy dd.";
in = "12199525";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate9: %s\n", text);
date1 = 0; text = "";
fmt = "yyyy fierj mm dd.";
in = "19951225";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate10: %s\n", text);
date1 = 0; text = "";
fmt = "mm/dd/yy";
in = "122595";
PGTYPESdate_defmtdate(&date1, fmt, in);
text = PGTYPESdate_dtoa(date1);
printf("defmtdate12: %s\n", text);
exec sql rollback;
exec sql disconnect;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment