- Changed all new datatypes to lowercase.
- Fixed rounding bug in numerical types.
char *ECPGalloc(long, int);
static int
-deccall2(Decimal * arg1, Decimal * arg2, int (*ptr) (Numeric *, Numeric *))
+deccall2(decimal * arg1, decimal * arg2, int (*ptr) (numeric *, numeric *))
{
- Numeric *a1,
+ numeric *a1,
*a2;
int i;
}
static int
-deccall3(Decimal * arg1, Decimal * arg2, Decimal * result, int (*ptr) (Numeric *, Numeric *, Numeric *))
+deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric *, numeric *, numeric *))
{
- Numeric *a1,
+ numeric *a1,
*a2,
*nres;
int i;
/* we start with the numeric functions */
int
-decadd(Decimal * arg1, Decimal * arg2, Decimal * sum)
+decadd(decimal * arg1, decimal * arg2, decimal * sum)
{
deccall3(arg1, arg2, sum, PGTYPESnumeric_add);
}
int
-deccmp(Decimal * arg1, Decimal * arg2)
+deccmp(decimal * arg1, decimal * arg2)
{
return (deccall2(arg1, arg2, PGTYPESnumeric_cmp));
}
void
-deccopy(Decimal * src, Decimal * target)
+deccopy(decimal * src, decimal * target)
{
- memcpy(target, src, sizeof(Decimal));
+ memcpy(target, src, sizeof(decimal));
}
static char *
}
int
-deccvasc(char *cp, int len, Decimal * np)
+deccvasc(char *cp, int len, decimal * np)
{
- char *str = strndup(cp, len); /* Decimal_in always converts the
+ char *str = strndup(cp, len); /* decimal_in always converts the
* complete string */
int ret = 0;
- Numeric *result;
+ numeric *result;
if (risnull(CSTRINGTYPE, cp))
{
}
int
-deccvdbl(double dbl, Decimal * np)
+deccvdbl(double dbl, decimal * np)
{
- Numeric *nres = PGTYPESnumeric_new();
+ numeric *nres = PGTYPESnumeric_new();
int result = 1;
if (risnull(CDOUBLETYPE, (char *) &dbl))
}
int
-deccvint(int in, Decimal * np)
+deccvint(int in, decimal * np)
{
- Numeric *nres = PGTYPESnumeric_new();
+ numeric *nres = PGTYPESnumeric_new();
int result = 1;
if (risnull(CINTTYPE, (char *) &in))
}
int
-deccvlong(long lng, Decimal * np)
+deccvlong(long lng, decimal * np)
{
- Numeric *nres = PGTYPESnumeric_new();
+ numeric *nres = PGTYPESnumeric_new();
int result = 1;
if (risnull(CLONGTYPE, (char *) &lng))
}
int
-decdiv(Decimal * n1, Decimal * n2, Decimal * n3)
+decdiv(decimal * n1, decimal * n2, decimal * n3)
{
int i = deccall3(n1, n2, n3, PGTYPESnumeric_div);
}
int
-decmul(Decimal * n1, Decimal * n2, Decimal * n3)
+decmul(decimal * n1, decimal * n2, decimal * n3)
{
int i = deccall3(n1, n2, n3, PGTYPESnumeric_mul);
}
int
-decsub(Decimal * n1, Decimal * n2, Decimal * n3)
+decsub(decimal * n1, decimal * n2, decimal * n3)
{
int i = deccall3(n1, n2, n3, PGTYPESnumeric_sub);
}
int
-dectoasc(Decimal * np, char *cp, int len, int right)
+dectoasc(decimal * np, char *cp, int len, int right)
{
char *str;
- Numeric *nres = PGTYPESnumeric_new();
+ numeric *nres = PGTYPESnumeric_new();
if (nres == NULL)
return -1211;
}
int
-dectodbl(Decimal * np, double *dblp)
+dectodbl(decimal * np, double *dblp)
{
- Numeric *nres = PGTYPESnumeric_new();
+ numeric *nres = PGTYPESnumeric_new();
int i;
if (nres == NULL)
}
int
-dectoint(Decimal * np, int *ip)
+dectoint(decimal * np, int *ip)
{
int ret;
- Numeric *nres = PGTYPESnumeric_new();
+ numeric *nres = PGTYPESnumeric_new();
if (nres == NULL)
return -1211;
}
int
-dectolong(Decimal * np, long *lngp)
+dectolong(decimal * np, long *lngp)
{
int ret;
- Numeric *nres = PGTYPESnumeric_new();;
+ numeric *nres = PGTYPESnumeric_new();;
if (nres == NULL)
return -1211;
/* And the datetime stuff */
void
-dtcurrent(Timestamp *ts)
+dtcurrent(timestamp *ts)
{
PGTYPEStimestamp_current(ts);
}
int
-dtcvasc(char *str, Timestamp *ts)
+dtcvasc(char *str, timestamp *ts)
{
- Timestamp ts_tmp;
+ timestamp ts_tmp;
int i;
char **endptr = &str;
}
int
-dtsub(Timestamp *ts1, Timestamp *ts2, Interval *iv)
+dtsub(timestamp *ts1, timestamp *ts2, interval *iv)
{
return PGTYPEStimestamp_sub(ts1, ts2, iv);
}
int
-dttoasc(Timestamp *ts, char *output)
+dttoasc(timestamp *ts, char *output)
{
char *asctime = PGTYPEStimestamp_to_asc(*ts);
}
int
-dttofmtasc(Timestamp *ts, char *output, int str_len, char *fmtstr)
+dttofmtasc(timestamp *ts, char *output, int str_len, char *fmtstr)
{
return PGTYPEStimestamp_fmt_asc(ts, output, str_len, fmtstr);
}
int
-intoasc(Interval *i, char *str)
+intoasc(interval *i, char *str)
{
str = PGTYPESinterval_to_asc(i);
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.16 2003/08/04 00:43:32 momjian Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.17 2003/09/09 10:46:37 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
unsigned long ures;
double dres;
char *scan_length;
- Numeric *nres;
- Date ddres;
- Timestamp tres;
- Interval *ires;
+ numeric *nres;
+ date ddres;
+ timestamp tres;
+ interval *ires;
case ECPGt_short:
case ECPGt_int:
if (pval)
{
res = strtol(pval, &scan_length, 10);
+ /* INFORMIX allows for selecting a numeric into an int, the result is truncated */
if ((isarray && *scan_length != ',' && *scan_length != '}')
- || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
+ || (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
{
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
{
ures = strtoul(pval, &scan_length, 10);
if ((isarray && *scan_length != ',' && *scan_length != '}')
- || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
+ || (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
{
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
{
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
if ((isarray && *scan_length != ',' && *scan_length != '}')
- || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
+ || (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
{
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
{
*((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
if ((isarray && *scan_length != ',' && *scan_length != '}')
- || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
+ || (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
{
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
nres = PGTYPESnumeric_from_asc("0.0", &scan_length);
if (type == ECPGt_numeric)
- PGTYPESnumeric_copy(nres, (Numeric *) (var + offset * act_tuple));
+ PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
else
- PGTYPESnumeric_to_decimal(nres, (Decimal *) (var + offset * act_tuple));
+ PGTYPESnumeric_to_decimal(nres, (decimal *) (var + offset * act_tuple));
break;
case ECPGt_interval:
else
ires = PGTYPESinterval_from_asc("0 seconds", NULL);
- PGTYPESinterval_copy(ires, (Interval *) (var + offset * act_tuple));
+ PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
break;
case ECPGt_date:
if (pval)
return (false);
}
- *((Date *) (var + offset * act_tuple)) = ddres;
+ *((date *) (var + offset * act_tuple)) = ddres;
}
break;
return (false);
}
- *((Timestamp *) (var + offset * act_tuple)) = tres;
+ *((timestamp *) (var + offset * act_tuple)) = tres;
}
break;
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.23 2003/08/04 00:43:32 momjian Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.24 2003/09/09 10:46:37 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
{
char *str = NULL;
int slen;
- Numeric *nval = PGTYPESnumeric_new();
+ numeric *nval = PGTYPESnumeric_new();
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
if (var->type == ECPGt_numeric)
- PGTYPESnumeric_copy((Numeric *) ((var + var->offset * element)->value), nval);
+ PGTYPESnumeric_copy((numeric *) ((var + var->offset * element)->value), nval);
else
- PGTYPESnumeric_from_decimal((Decimal *) ((var + var->offset * element)->value), nval);
+ PGTYPESnumeric_from_decimal((decimal *) ((var + var->offset * element)->value), nval);
str = PGTYPESnumeric_to_asc(nval, 0);
PGTYPESnumeric_free(nval);
else
{
if (var->type == ECPGt_numeric)
- PGTYPESnumeric_copy((Numeric *) (var->value), nval);
+ PGTYPESnumeric_copy((numeric *) (var->value), nval);
else
- PGTYPESnumeric_from_decimal((Decimal *) (var->value), nval);
+ PGTYPESnumeric_from_decimal((decimal *) (var->value), nval);
str = PGTYPESnumeric_to_asc(nval, 0);
{
for (element = 0; element < var->arrsize; element++)
{
- str = quote_postgres(PGTYPESinterval_to_asc((Interval *) ((var + var->offset * element)->value)), stmt->lineno);
+ str = quote_postgres(PGTYPESinterval_to_asc((interval *) ((var + var->offset * element)->value)), stmt->lineno);
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), stmt->lineno)))
}
else
{
- str = quote_postgres(PGTYPESinterval_to_asc((Interval *) (var->value)), stmt->lineno);
+ str = quote_postgres(PGTYPESinterval_to_asc((interval *) (var->value)), stmt->lineno);
slen = strlen(str);
if (!(mallocedval = ECPGalloc(slen + sizeof("interval ") + 1, stmt->lineno)))
{
for (element = 0; element < var->arrsize; element++)
{
- str = quote_postgres(PGTYPESdate_to_asc(*(Date *) ((var + var->offset * element)->value)), stmt->lineno);
+ str = quote_postgres(PGTYPESdate_to_asc(*(date *) ((var + var->offset * element)->value)), stmt->lineno);
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), stmt->lineno)))
}
else
{
- str = quote_postgres(PGTYPESdate_to_asc(*(Date *) (var->value)), stmt->lineno);
+ str = quote_postgres(PGTYPESdate_to_asc(*(date *) (var->value)), stmt->lineno);
slen = strlen(str);
if (!(mallocedval = ECPGalloc(slen + sizeof("date ") + 1, stmt->lineno)))
{
for (element = 0; element < var->arrsize; element++)
{
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *) ((var + var->offset * element)->value)), stmt->lineno);
+ str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), stmt->lineno);
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), stmt->lineno)))
}
else
{
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *) (var->value)), stmt->lineno);
+ str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), stmt->lineno);
slen = strlen(str);
if (!(mallocedval = ECPGalloc(slen + sizeof("timestamp") + 1, stmt->lineno)))
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.14 2003/08/08 13:17:58 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.15 2003/09/09 10:46:37 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
*(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
break;
case ECPGt_decimal:
- memset((char *) ptr, 0, sizeof(Decimal));
- ((Decimal *) ptr)->sign = NUMERIC_NAN;
+ memset((char *) ptr, 0, sizeof(decimal));
+ ((decimal *) ptr)->sign = NUMERIC_NAN;
break;
case ECPGt_numeric:
- memset((char *) ptr, 0, sizeof(Numeric));
- ((Numeric *) ptr)->sign = NUMERIC_NAN;
+ memset((char *) ptr, 0, sizeof(numeric));
+ ((numeric *) ptr)->sign = NUMERIC_NAN;
break;
case ECPGt_interval:
- memset((char *) ptr, 0xff, sizeof(Interval));
+ memset((char *) ptr, 0xff, sizeof(interval));
break;
case ECPGt_timestamp:
- memset((char *) ptr, 0xff, sizeof(Timestamp));
+ memset((char *) ptr, 0xff, sizeof(timestamp));
break;
default:
break;
return true;
break;
case ECPGt_decimal:
- if (((Decimal *) ptr)->sign == NUMERIC_NAN)
+ if (((decimal *) ptr)->sign == NUMERIC_NAN)
return true;
break;
case ECPGt_numeric:
- if (((Numeric *) ptr)->sign == NUMERIC_NAN)
+ if (((numeric *) ptr)->sign == NUMERIC_NAN)
return true;
break;
case ECPGt_interval:
- return (_check(ptr, sizeof(Interval)));
+ return (_check(ptr, sizeof(interval)));
break;
case ECPGt_timestamp:
- return (_check(ptr, sizeof(Timestamp)));
+ return (_check(ptr, sizeof(timestamp)));
break;
default:
break;
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.8 2003/07/01 12:40:51 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.9 2003/09/09 10:46:37 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
case ECPGt_char_variable:
return "char";
case ECPGt_decimal:
- return "Decimal";
+ return "decimal";
case ECPGt_numeric:
- return "Numeric";
+ return "numeric";
case ECPGt_date:
- return "Date";
+ return "date";
case ECPGt_timestamp:
- return "Timestamp";
+ return "timestamp";
case ECPGt_interval:
- return "Interval";
+ return "interval";
case ECPGt_const:
return "Const";
default:
#include <pgtypes_interval.h>
#ifndef dtime_t
-#define dtime_t Timestamp
+#define dtime_t timestamp
#endif /* dtime_t */
#ifndef intrvl_t
-#define intrvl_t Interval
+#define intrvl_t interval
#endif /* intrvl_t */
extern void dtcurrent(dtime_t *);
#include <pgtypes_numeric.h>
#ifndef dec_t
-#define dec_t Decimal
+#define dec_t decimal
#endif /* dec_t */
int decadd(dec_t *, dec_t *, dec_t *);
#include <pgtypes_timestamp.h>
-#define Date long
+#define date long
-extern Date PGTYPESdate_from_asc(char *, char **);
-extern char *PGTYPESdate_to_asc(Date);
-extern Date PGTYPESdate_from_timestamp(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_defmt_asc(Date *, char *, char *);
-extern int PGTYPESdate_fmt_asc(Date, char *, char *);
+extern date PGTYPESdate_from_asc(char *, char **);
+extern char *PGTYPESdate_to_asc(date);
+extern date PGTYPESdate_from_timestamp(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_defmt_asc(date *, char *, char *);
+extern int PGTYPESdate_fmt_asc(date, char *, char *);
#endif /* PGTYPES_DATETIME */
#endif
long month; /* months and years, after time for
* alignment */
-} Interval;
+} interval;
-extern Interval *PGTYPESinterval_from_asc(char *, char **);
-extern char *PGTYPESinterval_to_asc(Interval *);
-extern int PGTYPESinterval_copy(Interval *, Interval *);
+extern interval *PGTYPESinterval_from_asc(char *, char **);
+extern char *PGTYPESinterval_to_asc(interval *);
+extern int PGTYPESinterval_copy(interval *, interval *);
#endif /* PGTYPES_INTERVAL */
* NUMERIC_NAN */
NumericDigit *buf; /* start of alloc'd space for digits[] */
NumericDigit *digits; /* decimal digits */
-} Numeric;
+} numeric;
typedef struct
{
int sign; /* NUMERIC_POS, NUMERIC_NEG, or
* NUMERIC_NAN */
NumericDigit digits[DECSIZE]; /* decimal digits */
-} Decimal;
+} decimal;
-Numeric *PGTYPESnumeric_new(void);
-void PGTYPESnumeric_free(Numeric *);
-Numeric *PGTYPESnumeric_from_asc(char *, char **);
-char *PGTYPESnumeric_to_asc(Numeric *, int);
-int PGTYPESnumeric_add(Numeric *, Numeric *, Numeric *);
-int PGTYPESnumeric_sub(Numeric *, Numeric *, Numeric *);
-int PGTYPESnumeric_mul(Numeric *, Numeric *, Numeric *);
-int PGTYPESnumeric_div(Numeric *, Numeric *, Numeric *);
-int PGTYPESnumeric_cmp(Numeric *, Numeric *);
-int PGTYPESnumeric_from_int(signed int, Numeric *);
-int PGTYPESnumeric_from_long(signed long int, Numeric *);
-int PGTYPESnumeric_copy(Numeric *, Numeric *);
-int PGTYPESnumeric_from_double(double, Numeric *);
-int PGTYPESnumeric_to_double(Numeric *, double *);
-int PGTYPESnumeric_to_int(Numeric *, int *);
-int PGTYPESnumeric_to_long(Numeric *, long *);
-int PGTYPESnumeric_to_decimal(Numeric *, Decimal *);
-int PGTYPESnumeric_from_decimal(Decimal *, Numeric *);
+numeric *PGTYPESnumeric_new(void);
+void PGTYPESnumeric_free(numeric *);
+numeric *PGTYPESnumeric_from_asc(char *, char **);
+char *PGTYPESnumeric_to_asc(numeric *, int);
+int PGTYPESnumeric_add(numeric *, numeric *, numeric *);
+int PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
+int PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
+int PGTYPESnumeric_div(numeric *, numeric *, numeric *);
+int PGTYPESnumeric_cmp(numeric *, numeric *);
+int PGTYPESnumeric_from_int(signed int, numeric *);
+int PGTYPESnumeric_from_long(signed long int, numeric *);
+int PGTYPESnumeric_copy(numeric *, numeric *);
+int PGTYPESnumeric_from_double(double, numeric *);
+int PGTYPESnumeric_to_double(numeric *, double *);
+int PGTYPESnumeric_to_int(numeric *, int *);
+int PGTYPESnumeric_to_long(numeric *, long *);
+int PGTYPESnumeric_to_decimal(numeric *, decimal *);
+int PGTYPESnumeric_from_decimal(decimal *, numeric *);
#endif /* PGTYPES_NUMERIC */
#include <pgtypes_interval.h>
#ifdef HAVE_INT64_TIMESTAMP
-typedef int64 Timestamp;
+typedef int64 timestamp;
typedef int64 TimestampTz;
#else
-typedef double Timestamp;
+typedef double timestamp;
typedef double TimestampTz;
#endif
-extern Timestamp PGTYPEStimestamp_from_asc(char *, char **);
-extern char *PGTYPEStimestamp_to_asc(Timestamp);
-extern int PGTYPEStimestamp_sub(Timestamp *, Timestamp *, Interval *);
-extern int PGTYPEStimestamp_fmt_asc(Timestamp *, char *, int, char *);
-extern void PGTYPEStimestamp_current(Timestamp *);
-extern int PGTYPEStimestamp_defmt_asc(char *, char *, Timestamp *);
+extern timestamp PGTYPEStimestamp_from_asc(char *, char **);
+extern char *PGTYPEStimestamp_to_asc(timestamp);
+extern int PGTYPEStimestamp_sub(timestamp *, timestamp *, interval *);
+extern int PGTYPEStimestamp_fmt_asc(timestamp *, char *, int, char *);
+extern void PGTYPEStimestamp_current(timestamp *);
+extern int PGTYPEStimestamp_defmt_asc(char *, char *, timestamp *);
#endif /* PGTYPES_TIMESTAMP */
#include "pgtypes_error.h"
#include "pgtypes_date.h"
-Date
-PGTYPESdate_from_timestamp(Timestamp dt)
+date
+PGTYPESdate_from_timestamp(timestamp dt)
{
- Date dDate;
+ date dDate;
dDate = 0; /* suppress compiler warning */
return dDate;
}
-Date
+date
PGTYPESdate_from_asc(char *str, char **endptr)
{
- Date dDate;
+ date dDate;
fsec_t fsec;
struct tm tt,
*tm = &tt;
}
char *
-PGTYPESdate_to_asc(Date dDate)
+PGTYPESdate_to_asc(date dDate)
{
struct tm tt,
*tm = &tt;
}
void
-PGTYPESdate_julmdy(Date jd, int *mdy)
+PGTYPESdate_julmdy(date jd, int *mdy)
{
int y,
m,
}
void
-PGTYPESdate_mdyjul(int *mdy, Date * jdate)
+PGTYPESdate_mdyjul(int *mdy, date * jdate)
{
/* month is mdy[0] */
/* day is mdy[1] */
/* year is mdy[2] */
- *jdate = (Date) (date2j(mdy[2], mdy[0], mdy[1]) - date2j(2000, 1, 1));
+ *jdate = (date) (date2j(mdy[2], mdy[0], mdy[1]) - date2j(2000, 1, 1));
}
int
-PGTYPESdate_dayofweek(Date dDate)
+PGTYPESdate_dayofweek(date dDate)
{
/*
* Sunday: 0 Monday: 1 Tuesday: 2 Wednesday: 3
}
void
-PGTYPESdate_today(Date * d)
+PGTYPESdate_today(date * d)
{
struct tm ts;
#define PGTYPES_FMTDATE_YEAR_DIGITS_LONG 6
int
-PGTYPESdate_fmt_asc(Date dDate, char *fmtstring, char *outbuf)
+PGTYPESdate_fmt_asc(date dDate, char *fmtstring, char *outbuf)
{
static struct
{
#define PGTYPES_DATE_MONTH_MAXLENGTH 20 /* probably even less :-) */
int
-PGTYPESdate_defmt_asc(Date * d, char *fmt, char *str)
+PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
{
/*
* token[2] = { 4,6 } means that token 2 starts at position 4 and ends
int EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str, bool);
int EncodeInterval(struct tm * tm, fsec_t fsec, int style, char *str);
-int tm2timestamp(struct tm *, fsec_t, int *, Timestamp *);
+int tm2timestamp(struct tm *, fsec_t, int *, timestamp *);
int DecodeUnits(int field, char *lowtoken, int *val);
bool ClearDateCache(bool, bool, bool);
}
/* XXX range checking */
-int PGTYPEStimestamp_defmt_scan(char **, char *, Timestamp *, int *, int *, int *,
+int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int *,
int *, int *, int *, int *);
int
-PGTYPEStimestamp_defmt_scan(char **str, char *fmt, Timestamp *d,
+PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d,
int *year, int *month, int *day,
int *hour, int *minute, int *second,
int *tz)
* Convert a interval data type to a tm structure.
*/
static int
-interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
+interval2tm(interval span, struct tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 time;
} /* interval2tm() */
static int
-tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
+tm2interval(struct tm * tm, fsec_t fsec, interval *span)
{
span->month = ((tm->tm_year * 12) + tm->tm_mon);
#ifdef HAVE_INT64_TIMESTAMP
return 0;
} /* tm2interval() */
-Interval *
+interval *
PGTYPESinterval_from_asc(char *str, char **endptr)
{
- Interval *result = NULL;
+ interval *result = NULL;
fsec_t fsec;
struct tm tt,
*tm = &tt;
return NULL;
}
- result = (Interval *) pgtypes_alloc(sizeof(Interval));
+ result = (interval *) pgtypes_alloc(sizeof(interval));
if (!result)
return NULL;
}
char *
-PGTYPESinterval_to_asc(Interval *span)
+PGTYPESinterval_to_asc(interval *span)
{
struct tm tt,
*tm = &tt;
}
int
-PGTYPESinterval_copy(Interval *intvlsrc, Interval *intrcldest)
+PGTYPESinterval_copy(interval *intvlsrc, interval *intrcldest)
{
intrcldest->time = intvlsrc->time;
intrcldest->month = intvlsrc->month;
#define Max(x, y) ((x) > (y) ? (x) : (y))
#define Min(x, y) ((x) < (y) ? (x) : (y))
-#define init_var(v) memset(v,0,sizeof(Numeric))
+#define init_var(v) memset(v,0,sizeof(numeric))
#define digitbuf_alloc(size) ((NumericDigit *) pgtypes_alloc(size))
#define digitbuf_free(buf) \
* ----------
*/
static int
-apply_typmod(Numeric *var, long typmod)
+apply_typmod(numeric *var, long typmod)
{
int precision;
int scale;
* ----------
*/
static int
-alloc_var(Numeric *var, int ndigits)
+alloc_var(numeric *var, int ndigits)
{
digitbuf_free(var->buf);
var->buf = digitbuf_alloc(ndigits + 1);
return 0;
}
-Numeric *
+numeric *
PGTYPESnumeric_new(void)
{
- Numeric *var;
+ numeric *var;
- if ((var = (Numeric *) pgtypes_alloc(sizeof(Numeric))) == NULL)
+ if ((var = (numeric *) pgtypes_alloc(sizeof(numeric))) == NULL)
return NULL;
if (alloc_var(var, 0) < 0)
* ----------
*/
static int
-set_var_from_str(char *str, char **ptr, Numeric *dest)
+set_var_from_str(char *str, char **ptr, numeric *dest)
{
bool have_dp = FALSE;
int i = 0;
* ----------
*/
static char *
-get_str_from_var(Numeric *var, int dscale)
+get_str_from_var(numeric *var, int dscale)
{
char *str;
char *cp;
return str;
}
-Numeric *
+numeric *
PGTYPESnumeric_from_asc(char *str, char **endptr)
{
- Numeric *value = (Numeric *) pgtypes_alloc(sizeof(Numeric));
+ numeric *value = (numeric *) pgtypes_alloc(sizeof(numeric));
int ret;
#if 0
}
char *
-PGTYPESnumeric_to_asc(Numeric *num, int dscale)
+PGTYPESnumeric_to_asc(numeric *num, int dscale)
{
- if (dscale <= 0)
+ if (dscale < 0)
dscale = num->dscale;
return (get_str_from_var(num, dscale));
* ----------
*/
static void
-zero_var(Numeric *var)
+zero_var(numeric *var)
{
digitbuf_free(var->buf);
var->buf = NULL;
}
void
-PGTYPESnumeric_free(Numeric *var)
+PGTYPESnumeric_free(numeric *var)
{
digitbuf_free(var->buf);
free(var);
* ----------
*/
static int
-cmp_abs(Numeric *var1, Numeric *var2)
+cmp_abs(numeric *var1, numeric *var2)
{
int i1 = 0;
int i2 = 0;
* ----------
*/
static int
-add_abs(Numeric *var1, Numeric *var2, Numeric *result)
+add_abs(numeric *var1, numeric *var2, numeric *result)
{
NumericDigit *res_buf;
NumericDigit *res_digits;
* ----------
*/
static int
-sub_abs(Numeric *var1, Numeric *var2, Numeric *result)
+sub_abs(numeric *var1, numeric *var2, numeric *result)
{
NumericDigit *res_buf;
NumericDigit *res_digits;
* ----------
*/
int
-PGTYPESnumeric_add(Numeric *var1, Numeric *var2, Numeric *result)
+PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result)
{
/*
* Decide on the signs of the two variables what to do
* ----------
*/
int
-PGTYPESnumeric_sub(Numeric *var1, Numeric *var2, Numeric *result)
+PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result)
{
/*
* Decide on the signs of the two variables what to do
* ----------
*/
int
-PGTYPESnumeric_mul(Numeric *var1, Numeric *var2, Numeric *result)
+PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result)
{
NumericDigit *res_buf;
NumericDigit *res_digits;
* Note that this must be called before div_var.
*/
static int
-select_div_scale(Numeric *var1, Numeric *var2, int *rscale)
+select_div_scale(numeric *var1, numeric *var2, int *rscale)
{
int weight1,
weight2,
}
int
-PGTYPESnumeric_div(Numeric *var1, Numeric *var2, Numeric *result)
+PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
{
NumericDigit *res_digits;
int res_ndigits;
int res_sign;
int res_weight;
- Numeric dividend;
- Numeric divisor[10];
+ numeric dividend;
+ numeric divisor[10];
int ndigits_tmp;
int weight_tmp;
int rscale_tmp;
int i;
long sum = 0;
- memcpy(&divisor[guess], &divisor[1], sizeof(Numeric));
+ memcpy(&divisor[guess], &divisor[1], sizeof(numeric));
divisor[guess].buf = digitbuf_alloc(divisor[guess].ndigits);
divisor[guess].digits = divisor[guess].buf;
for (i = divisor[1].ndigits - 1; i >= 0; i--)
int
-PGTYPESnumeric_cmp(Numeric *var1, Numeric *var2)
+PGTYPESnumeric_cmp(numeric *var1, numeric *var2)
{
/* use cmp_abs function to calculate the result */
}
int
-PGTYPESnumeric_from_int(signed int int_val, Numeric *var)
+PGTYPESnumeric_from_int(signed int int_val, numeric *var)
{
/* implicit conversion */
signed long int long_int = int_val;
}
int
-PGTYPESnumeric_from_long(signed long int long_val, Numeric *var)
+PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
{
/* calculate the size of the long int number */
/* a number n needs log_10 n digits */
}
int
-PGTYPESnumeric_copy(Numeric *src, Numeric *dst)
+PGTYPESnumeric_copy(numeric *src, numeric *dst)
{
int i;
}
int
-PGTYPESnumeric_from_double(double d, Numeric *dst)
+PGTYPESnumeric_from_double(double d, numeric *dst)
{
char buffer[100];
- Numeric *tmp;
+ numeric *tmp;
if (sprintf(buffer, "%f", d) == 0)
return -1;
}
static int
-numericvar_to_double_no_overflow(Numeric *var, double *dp)
+numericvar_to_double_no_overflow(numeric *var, double *dp)
{
char *tmp;
double val;
}
int
-PGTYPESnumeric_to_double(Numeric *nv, double *dp)
+PGTYPESnumeric_to_double(numeric *nv, double *dp)
{
double tmp;
int i;
}
int
-PGTYPESnumeric_to_int(Numeric *nv, int *ip)
+PGTYPESnumeric_to_int(numeric *nv, int *ip)
{
long l;
int i;
}
int
-PGTYPESnumeric_to_long(Numeric *nv, long *lp)
+PGTYPESnumeric_to_long(numeric *nv, long *lp)
{
int i;
long l = 0;
}
int
-PGTYPESnumeric_to_decimal(Numeric *src, Decimal * dst)
+PGTYPESnumeric_to_decimal(numeric *src, decimal * dst)
{
int i;
}
int
-PGTYPESnumeric_from_decimal(Decimal * src, Numeric *dst)
+PGTYPESnumeric_from_decimal(decimal * src, numeric *dst)
{
int i;
#include "pgtypes_date.h"
#include "datetime.h"
-int PGTYPEStimestamp_defmt_scan(char **, char *, Timestamp *, int *, int *, int *,
+int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int *,
int *, int *, int *, int *);
#ifdef HAVE_INT64_TIMESTAMP
} /* time2t() */
#endif
-static Timestamp
-dt2local(Timestamp dt, int tz)
+static timestamp
+dt2local(timestamp dt, int tz)
{
#ifdef HAVE_INT64_TIMESTAMP
dt -= (tz * INT64CONST(1000000));
* Returns -1 on failure (overflow).
*/
int
-tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
+tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result)
{
#ifdef HAVE_INT64_TIMESTAMP
- int date;
+ int dDate;
int64 time;
#else
- double date,
- time;
+ double dDate, time;
#endif
/* Julian day routines are not correct for negative Julian days */
if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
return -1;
- date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
+ dDate = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
#ifdef HAVE_INT64_TIMESTAMP
*result = (date * INT64CONST(86400000000)) + time;
if ((*result < 0) ? (date >= 0) : (date < 0))
return -1;
#else
- *result = ((date * 86400) + time);
+ *result = ((dDate * 86400) + time);
#endif
if (tzp != NULL)
*result = dt2local(*result, -(*tzp));
return 0;
} /* tm2timestamp() */
-static Timestamp
+static timestamp
SetEpochTimestamp(void)
{
- Timestamp dt;
+ timestamp dt;
struct tm tt,
*tm = &tt;
} /* SetEpochTimestamp() */
static void
-dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
+dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 time;
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
static int
-timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
+timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
{
#ifdef HAVE_INT64_TIMESTAMP
- int date,
- date0;
+ int dDate, date0;
int64 time;
#else
- double date,
- date0;
+ double dDate, date0;
double time;
#endif
time_t utime;
time = dt;
#ifdef HAVE_INT64_TIMESTAMP
- TMODULO(time, date, INT64CONST(86400000000));
+ TMODULO(time, dDate, INT64CONST(86400000000));
if (time < INT64CONST(0))
{
time += INT64CONST(86400000000);
- date -= 1;
+ dDate -= 1;
}
#else
- TMODULO(time, date, 86400e0);
+ TMODULO(time, dDate, 86400e0);
if (time < 0)
{
time += 86400;
- date -= 1;
+ dDate -= 1;
}
#endif
/* Julian day routine does not work for negative Julian days */
- if (date < -date0)
+ if (dDate < -date0)
return -1;
/* add offset to go from J2000 back to standard Julian date */
- date += date0;
+ dDate += date0;
- j2date((int) date, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
+ j2date((int) dDate, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
dt2time(time, &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
if (tzp != NULL)
* * Convert reserved timestamp data type to string.
* */
static int
-EncodeSpecialTimestamp(Timestamp dt, char *str)
+EncodeSpecialTimestamp(timestamp dt, char *str)
{
if (TIMESTAMP_IS_NOBEGIN(dt))
strcpy(str, EARLY);
return TRUE;
} /* EncodeSpecialTimestamp() */
-Timestamp
+timestamp
PGTYPEStimestamp_from_asc(char *str, char **endptr)
{
- Timestamp result;
+ timestamp result;
#ifdef HAVE_INT64_TIMESTAMP
int64 noresult = 0;
}
char *
-PGTYPEStimestamp_to_asc(Timestamp tstamp)
+PGTYPEStimestamp_to_asc(timestamp tstamp)
{
struct tm tt,
*tm = &tt;
}
void
-PGTYPEStimestamp_current(Timestamp *ts)
+PGTYPEStimestamp_current(timestamp *ts)
{
struct tm tm;
}
static int
-dttofmtasc_replace(Timestamp *ts, Date dDate, int dow, struct tm * tm,
+dttofmtasc_replace(timestamp *ts, date dDate, int dow, struct tm * tm,
char *output, int *pstr_len, char *fmtstr)
{
union un_fmt_comb replace_val;
int
-PGTYPEStimestamp_fmt_asc(Timestamp *ts, char *output, int str_len, char *fmtstr)
+PGTYPEStimestamp_fmt_asc(timestamp *ts, char *output, int str_len, char *fmtstr)
{
struct tm tm;
fsec_t fsec;
- Date dDate;
+ date dDate;
int dow;
dDate = PGTYPESdate_from_timestamp(*ts);
}
int
-PGTYPEStimestamp_sub(Timestamp *ts1, Timestamp *ts2, Interval *iv)
+PGTYPEStimestamp_sub(timestamp *ts1, timestamp *ts2, interval *iv)
{
if (TIMESTAMP_NOT_FINITE(*ts1) || TIMESTAMP_NOT_FINITE(*ts2))
return PGTYPES_TS_ERR_EINFTIME;
}
int
-PGTYPEStimestamp_defmt_asc(char *str, char *fmt, Timestamp *d)
+PGTYPEStimestamp_defmt_asc(char *str, char *fmt, timestamp *d)
{
int year,
month,
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.77 2003/08/04 00:43:33 momjian Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.78 2003/09/09 10:46:38 meskes Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
{
compat = (strcmp(optarg, "INFORMIX") == 0) ? ECPG_COMPAT_INFORMIX : ECPG_COMPAT_INFORMIX_SE;
/* system_includes = true; */
- add_preprocessor_define("dec_t=Numeric");
- add_preprocessor_define("intrvl_t=Interval");
- add_preprocessor_define("dtime_t=Timestamp");
+ add_preprocessor_define("dec_t=numeric");
+ add_preprocessor_define("intrvl_t=interval");
+ add_preprocessor_define("dtime_t=timestamp");
}
else
{
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.253 2003/08/26 16:09:01 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.254 2003/09/09 10:46:38 meskes Exp $ */
/* Copyright comment */
%{
else if (strcmp($1, "decimal") == 0)
{
$$.type_enum = ECPGt_decimal;
- $$.type_str = make_str("Decimal");
+ $$.type_str = make_str("decimal");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "date") == 0)
{
$$.type_enum = ECPGt_date;
- $$.type_str = make_str("Date");
+ $$.type_str = make_str("date");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "timestamp") == 0)
{
$$.type_enum = ECPGt_timestamp;
- $$.type_str = make_str("Timestamp");
+ $$.type_str = make_str("timestamp");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "datetime") == 0)
{
$$.type_enum = ECPGt_timestamp;
- $$.type_str = make_str("Timestamp");
+ $$.type_str = make_str("timestamp");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "interval") == 0)
{
$$.type_enum = ECPGt_interval;
- $$.type_str = make_str("Interval");
+ $$.type_str = make_str("interval");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
if (strcmp($1, "numeric") == 0)
{
$$.type_enum = ECPGt_numeric;
- $$.type_str = make_str("Numeric");
+ $$.type_str = make_str("numeric");
}
else if (strcmp($1, "decimal") == 0)
{
$$.type_enum = ECPGt_decimal;
- $$.type_str = make_str("Decimal");
+ $$.type_str = make_str("decimal");
}
else
mmerror(PARSE_ERROR, ET_ERROR, "Only numeric/decimal have precision/scale argument");
else if (strcmp($1, "numeric") == 0)
{
$$.type_enum = ECPGt_numeric;
- $$.type_str = make_str("Numeric");
+ $$.type_str = make_str("numeric");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "decimal") == 0)
{
$$.type_enum = ECPGt_decimal;
- $$.type_str = make_str("Deciaml");
+ $$.type_str = make_str("decimal");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "date") == 0)
{
$$.type_enum = ECPGt_date;
- $$.type_str = make_str("Date");
+ $$.type_str = make_str("date");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "timestamp") == 0)
{
$$.type_enum = ECPGt_timestamp;
- $$.type_str = make_str("Timestamp");
+ $$.type_str = make_str("timestamp");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "interval") == 0)
{
$$.type_enum = ECPGt_interval;
- $$.type_str = make_str("Interval");
+ $$.type_str = make_str("interval");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
else if (strcmp($1, "datetime") == 0)
{
$$.type_enum = ECPGt_timestamp;
- $$.type_str = make_str("Timestamp");
+ $$.type_str = make_str("timestamp");
$$.type_dimension = make_str("-1");
$$.type_index = make_str("-1");
$$.type_sizeof = NULL;
* we have to use a pointer here
*/
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
- sprintf(offset, "sizeof(Numeric)");
+ sprintf(offset, "sizeof(numeric)");
break;
case ECPGt_interval:
* we have to use a pointer here
*/
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
- sprintf(offset, "sizeof(Interval)");
+ sprintf(offset, "sizeof(interval)");
break;
case ECPGt_date:
* type
*/
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
- sprintf(offset, "sizeof(Date)");
+ sprintf(offset, "sizeof(date)");
break;
case ECPGt_timestamp:
* type
*/
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
- sprintf(offset, "sizeof(Date)");
+ sprintf(offset, "sizeof(timestamp)");
break;
case ECPGt_const:
interval iv1;
char *text;
exec sql end declare section;
- Date date2;
+ date date2;
int mdy[3] = { 4, 19, 1998 };
char *fmt, *out, *in;
char *d1 = "Mon Jan 17 1966";
main()
{
char *text="error\n";
- Numeric *value1, *value2, *res;
+ numeric *value1, *value2, *res;
exec sql begin declare section;
numeric(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ;
exec sql end declare section;