Commit 89508a84 authored by Michael Meskes's avatar Michael Meskes

More changes to pgtypeslib and set optimization to -O1.

parent 5e5c5cd3
...@@ -1369,6 +1369,13 @@ Fri Mar 21 15:13:42 CET 2003 ...@@ -1369,6 +1369,13 @@ Fri Mar 21 15:13:42 CET 2003
- Made sure preprocessor accepts new datatypes. - Made sure preprocessor accepts new datatypes.
- Do not free prepared statements at the end of a transaction. - Do not free prepared statements at the end of a transaction.
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.
- Set ecpg version to 2.12.0. - Set ecpg version to 2.12.0.
- Set ecpg library to 3.4.2. - Set ecpg library to 3.4.2.
- Set pgtypes library to 1.0.0 - Set pgtypes library to 1.0.0
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.3 2003/03/27 14:29:17 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "pgtypes_numeric.h" #include "pgtypes_numeric.h"
#include "pgtypes_date.h" #include "pgtypes_date.h"
#include "pgtypes_timestamp.h" #include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
bool bool
ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
...@@ -100,9 +101,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -100,9 +101,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
unsigned long ures; unsigned long ures;
double dres; double dres;
char *scan_length; char *scan_length;
NumericVar *nres; Numeric *nres;
Date ddres; Date ddres;
Timestamp tres; Timestamp tres;
Interval *ires;
case ECPGt_short: case ECPGt_short:
case ECPGt_int: case ECPGt_int:
...@@ -392,16 +394,39 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -392,16 +394,39 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if ((isarray && *scan_length != ',' && *scan_length != '}') if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */ || (!isarray && *scan_length != '\0')) /* Garbage left */
{ {
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval); ECPGraise(lineno, ECPG_NUMERIC_FORMAT, pval);
return (false); return (false);
} }
} }
else else
nres = PGTYPESnumeric_aton("0.0", &scan_length); nres = PGTYPESnumeric_aton("0.0", &scan_length);
PGTYPESnumeric_copy(nres, (NumericVar *)(var + offset * act_tuple)); PGTYPESnumeric_copy(nres, (Numeric *)(var + offset * act_tuple));
break; break;
case ECPGt_interval:
if (pval)
{
if (isarray && *pval == '"')
ires = PGTYPESinterval_atoi(pval + 1, &scan_length);
else
ires = PGTYPESinterval_atoi(pval, &scan_length);
if (isarray && *scan_length == '"')
scan_length++;
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
ECPGraise(lineno, ECPG_INTERVAL_FORMAT, pval);
return (false);
}
}
else
ires = PGTYPESinterval_atoi("0 seconds", NULL);
PGTYPESinterval_copy(ires, (Interval *)(var + offset * act_tuple));
break;
case ECPGt_date: case ECPGt_date:
if (pval) if (pval)
{ {
...@@ -416,7 +441,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -416,7 +441,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if ((isarray && *scan_length != ',' && *scan_length != '}') if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */ || (!isarray && *scan_length != '\0')) /* Garbage left */
{ {
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval); ECPGraise(lineno, ECPG_DATE_FORMAT, pval);
return (false); return (false);
} }
...@@ -438,7 +463,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -438,7 +463,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if ((isarray && *scan_length != ',' && *scan_length != '}') if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */ || (!isarray && *scan_length != '\0')) /* Garbage left */
{ {
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval); ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, pval);
return (false); return (false);
} }
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.5 2003/03/25 02:44:36 momjian Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.6 2003/03/27 14:29:17 meskes Exp $ */
/* /*
* The aim is to get a simpler inteface to the database routines. * The aim is to get a simpler inteface to the database routines.
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "pgtypes_numeric.h" #include "pgtypes_numeric.h"
#include "pgtypes_date.h" #include "pgtypes_date.h"
#include "pgtypes_timestamp.h" #include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
/* variables visible to the programs */ /* variables visible to the programs */
struct sqlca sqlca = struct sqlca sqlca =
...@@ -846,7 +847,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, ...@@ -846,7 +847,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
{ {
for (element = 0; element < var->arrsize; element++) for (element = 0; element < var->arrsize; element++)
{ {
str = PGTYPESnumeric_ntoa((NumericVar *)((var + var->offset * element)->value)); str = PGTYPESnumeric_ntoa((Numeric *)((var + var->offset * element)->value));
slen = strlen (str); slen = strlen (str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno))) if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
...@@ -862,7 +863,48 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, ...@@ -862,7 +863,48 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
} }
else else
{ {
str = PGTYPESnumeric_ntoa((NumericVar *)(var->value)); str = PGTYPESnumeric_ntoa((Numeric *)(var->value));
slen = strlen (str);
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
return false;
strncpy(mallocedval, str , slen);
mallocedval[slen] = '\0';
}
*tobeinserted_p = mallocedval;
*malloced_p = true;
free(str);
}
break;
case ECPGt_interval:
{
char *str = NULL;
int slen;
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
str = PGTYPESinterval_itoa((Interval *)((var + var->offset * element)->value));
slen = strlen (str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
return false;
if (!element)
strcpy(mallocedval, "'{");
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
}
else
{
str = PGTYPESinterval_itoa((Interval *)(var->value));
slen = strlen (str); slen = strlen (str);
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno))) if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.3 2003/03/27 14:29:17 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -53,6 +53,8 @@ ECPGtype_name(enum ECPGttype typ) ...@@ -53,6 +53,8 @@ ECPGtype_name(enum ECPGttype typ)
return "date"; return "date";
case ECPGt_timestamp: case ECPGt_timestamp:
return "timestamp"; return "timestamp";
case ECPGt_interval:
return "interval";
default: default:
abort(); abort();
} }
......
#include <pgtypes_timestamp.h> #include <pgtypes_timestamp.h>
#include <pgtypes_interval.h>
#ifndef dtime_t #ifndef dtime_t
#define dtime_t Timestamp #define dtime_t Timestamp
#endif /* dtime_t */ #endif /* dtime_t */
#ifndef intrvl_t #ifndef intrvl_t
#define intrvl_t Timestamp #define intrvl_t Interval
#endif /* intrvl_t */ #endif /* intrvl_t */
extern void dtcurrent (dtime_t *); extern void dtcurrent (dtime_t *);
......
#include <pgtypes_numeric.h> #include <pgtypes_numeric.h>
#ifndef dec_t #ifndef dec_t
#define dec_t NumericVar #define dec_t Numeric
#endif /* dec_t */ #endif /* dec_t */
int decadd(dec_t *, NumericVar *, NumericVar *); int decadd(dec_t *, Numeric *, Numeric *);
int deccmp(dec_t *, NumericVar *); int deccmp(dec_t *, Numeric *);
void deccopy(dec_t *, NumericVar *); void deccopy(dec_t *, Numeric *);
int deccvasc(char *, int, dec_t *); int deccvasc(char *, int, dec_t *);
int deccvdbl(double, dec_t *); int deccvdbl(double, dec_t *);
int deccvint(int, dec_t *); int deccvint(int, dec_t *);
int deccvlong(long, dec_t *); int deccvlong(long, dec_t *);
int decdiv(dec_t *, NumericVar *, NumericVar *); int decdiv(dec_t *, Numeric *, Numeric *);
int decmul(dec_t *, NumericVar *, NumericVar *); int decmul(dec_t *, Numeric *, Numeric *);
int decsub(dec_t *, NumericVar *, NumericVar *); int decsub(dec_t *, Numeric *, Numeric *);
int dectoasc(dec_t *, char *, int, int); int dectoasc(dec_t *, char *, int, int);
int dectodbl(dec_t *, double *); int dectodbl(dec_t *, double *);
int dectoint(dec_t *, int *); int dectoint(dec_t *, int *);
......
...@@ -20,12 +20,16 @@ ...@@ -20,12 +20,16 @@
#define ECPG_INT_FORMAT -204 #define ECPG_INT_FORMAT -204
#define ECPG_UINT_FORMAT -205 #define ECPG_UINT_FORMAT -205
#define ECPG_FLOAT_FORMAT -206 #define ECPG_FLOAT_FORMAT -206
#define ECPG_CONVERT_BOOL -207 #define ECPG_NUMERIC_FORMAT -207
#define ECPG_EMPTY -208 #define ECPG_INTERVAL_FORMAT -208
#define ECPG_MISSING_INDICATOR -209 #define ECPG_DATE_FORMAT -209
#define ECPG_NO_ARRAY -210 #define ECPG_TIMESTAMP_FORMAT -210
#define ECPG_DATA_NOT_ARRAY -211 #define ECPG_CONVERT_BOOL -211
#define ECPG_ARRAY_INSERT -212 #define ECPG_EMPTY -212
#define ECPG_MISSING_INDICATOR -213
#define ECPG_NO_ARRAY -214
#define ECPG_DATA_NOT_ARRAY -215
#define ECPG_ARRAY_INSERT -216
#define ECPG_NO_CONN -220 #define ECPG_NO_CONN -220
#define ECPG_NOT_CONN -221 #define ECPG_NOT_CONN -221
......
...@@ -54,7 +54,8 @@ enum ECPGttype ...@@ -54,7 +54,8 @@ enum ECPGttype
ECPGt_descriptor, /* sql descriptor, no C variable */ ECPGt_descriptor, /* sql descriptor, no C variable */
ECPGt_numeric, ECPGt_numeric,
ECPGt_date, ECPGt_date,
ECPGt_timestamp ECPGt_timestamp,
ECPGt_interval
}; };
/* descriptor items */ /* descriptor items */
......
#ifndef PGTYPES_INTERVAL
#define PGTYPES_INTERVAL
#include <pgtypes_timestamp.h>
typedef struct
{
#ifdef HAVE_INT64_TIMESTAMP
int64 time; /* all time units other than months and years */
#else
double time; /* all time units other than months and years */
#endif
long month; /* months and years, after time for alignment */
} Interval;
extern Interval *PGTYPESinterval_atoi(char *, char **);
extern char *PGTYPESinterval_itoa(Interval *);
extern int PGTYPESinterval_copy(Interval *, Interval *);
#endif /* PGTYPES_INTERVAL */
#ifndef PGTYPES_NUMERIC #ifndef PGTYPES_NUMERIC
#define PGTYPES_NUMERIC #define PGTYPES_NUMERIC
#define NUMERIC_POS 0x0000
#define NUMERIC_NEG 0x4000
#define NUMERIC_MAX_PRECISION 1000
#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
#define NUMERIC_MIN_DISPLAY_SCALE 0
#define NUMERIC_MIN_SIG_DIGITS 16
typedef unsigned char NumericDigit; typedef unsigned char NumericDigit;
typedef struct NumericVar typedef struct
{ {
int ndigits; /* number of digits in digits[] - can be 0! */ int ndigits; /* number of digits in digits[] - can be 0! */
int weight; /* weight of first digit */ int weight; /* weight of first digit */
...@@ -11,23 +18,23 @@ typedef struct NumericVar ...@@ -11,23 +18,23 @@ typedef struct NumericVar
int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */ int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
NumericDigit *buf; /* start of alloc'd space for digits[] */ NumericDigit *buf; /* start of alloc'd space for digits[] */
NumericDigit *digits; /* decimal digits */ NumericDigit *digits; /* decimal digits */
} NumericVar; } Numeric;
NumericVar *PGTYPESnew(void); Numeric *PGTYPESnew(void);
void PGTYPESnumeric_free(NumericVar *); void PGTYPESnumeric_free(Numeric *);
NumericVar *PGTYPESnumeric_aton(char *, char **); Numeric *PGTYPESnumeric_aton(char *, char **);
char *PGTYPESnumeric_ntoa(NumericVar *); char *PGTYPESnumeric_ntoa(Numeric *);
int PGTYPESnumeric_add(NumericVar *, NumericVar *, NumericVar *); int PGTYPESnumeric_add(Numeric *, Numeric *, Numeric *);
int PGTYPESnumeric_sub(NumericVar *, NumericVar *, NumericVar *); int PGTYPESnumeric_sub(Numeric *, Numeric *, Numeric *);
int PGTYPESnumeric_mul(NumericVar *, NumericVar *, NumericVar *); int PGTYPESnumeric_mul(Numeric *, Numeric *, Numeric *);
int PGTYPESnumeric_div(NumericVar *, NumericVar *, NumericVar *); int PGTYPESnumeric_div(Numeric *, Numeric *, Numeric *);
int PGTYPESnumeric_cmp(NumericVar *, NumericVar *); int PGTYPESnumeric_cmp(Numeric *, Numeric *);
int PGTYPESnumeric_iton(signed int, NumericVar *); int PGTYPESnumeric_iton(signed int, Numeric *);
int PGTYPESnumeric_lton(signed long int, NumericVar *); int PGTYPESnumeric_lton(signed long int, Numeric *);
int PGTYPESnumeric_copy(NumericVar *, NumericVar *); int PGTYPESnumeric_copy(Numeric *, Numeric *);
int PGTYPESnumeric_dton(double, NumericVar *); int PGTYPESnumeric_dton(double, Numeric *);
int PGTYPESnumeric_ntod(NumericVar *, double *); int PGTYPESnumeric_ntod(Numeric *, double *);
int PGTYPESnumeric_ntoi(NumericVar *, int *); int PGTYPESnumeric_ntoi(Numeric *, int *);
int PGTYPESnumeric_ntol(NumericVar *, long *); int PGTYPESnumeric_ntol(Numeric *, long *);
#endif /* PGTYPES_NUMERIC */ #endif /* PGTYPES_NUMERIC */
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
# Copyright (c) 1994, Regents of the University of California # Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.2 2003/03/20 15:56:50 meskes Exp $ # $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.3 2003/03/27 14:29:17 meskes Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -16,7 +16,7 @@ NAME= pgtypes ...@@ -16,7 +16,7 @@ NAME= pgtypes
SO_MAJOR_VERSION= 1 SO_MAJOR_VERSION= 1
SO_MINOR_VERSION= 0.0 SO_MINOR_VERSION= 0.0
override CPPFLAGS := -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS) 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
......
#include <errno.h> #include <errno.h>
#include <stdlib.h>
#include "extern.h" #include "extern.h"
......
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
#include "c.h" #include "c.h"
#include "extern.h" #include "extern.h"
#include "numeric.h"
#include "pgtypes_error.h" #include "pgtypes_error.h"
#include "decimal.h" #include "decimal.h"
#define Max(x, y) ((x) > (y) ? (x) : (y)) #define Max(x, y) ((x) > (y) ? (x) : (y))
#define Min(x, y) ((x) < (y) ? (x) : (y)) #define Min(x, y) ((x) < (y) ? (x) : (y))
#define init_var(v) memset(v,0,sizeof(NumericVar)) #define init_var(v) memset(v,0,sizeof(Numeric))
#define digitbuf_alloc(size) ((NumericDigit *) pgtypes_alloc(size)) #define digitbuf_alloc(size) ((NumericDigit *) pgtypes_alloc(size))
#define digitbuf_free(buf) \ #define digitbuf_free(buf) \
...@@ -35,7 +34,7 @@ ...@@ -35,7 +34,7 @@
* ---------- * ----------
*/ */
static int static int
apply_typmod(NumericVar *var, long typmod) apply_typmod(Numeric *var, long typmod)
{ {
int precision; int precision;
int scale; int scale;
...@@ -115,7 +114,7 @@ apply_typmod(NumericVar *var, long typmod) ...@@ -115,7 +114,7 @@ apply_typmod(NumericVar *var, long typmod)
* ---------- * ----------
*/ */
static int static int
alloc_var(NumericVar *var, int ndigits) alloc_var(Numeric *var, int ndigits)
{ {
digitbuf_free(var->buf); digitbuf_free(var->buf);
var->buf = digitbuf_alloc(ndigits + 1); var->buf = digitbuf_alloc(ndigits + 1);
...@@ -127,12 +126,12 @@ alloc_var(NumericVar *var, int ndigits) ...@@ -127,12 +126,12 @@ alloc_var(NumericVar *var, int ndigits)
return 0; return 0;
} }
NumericVar * Numeric *
PGTYPESnew(void) PGTYPESnew(void)
{ {
NumericVar *var; Numeric *var;
if ((var = (NumericVar *)pgtypes_alloc(sizeof(NumericVar))) == NULL) if ((var = (Numeric *)pgtypes_alloc(sizeof(Numeric))) == NULL)
return NULL; return NULL;
if (alloc_var(var, 0) < 0) { if (alloc_var(var, 0) < 0) {
...@@ -149,7 +148,7 @@ PGTYPESnew(void) ...@@ -149,7 +148,7 @@ PGTYPESnew(void)
* ---------- * ----------
*/ */
static int static int
set_var_from_str(char *str, char **ptr, NumericVar *dest) set_var_from_str(char *str, char **ptr, Numeric *dest)
{ {
bool have_dp = FALSE; bool have_dp = FALSE;
int i = 0; int i = 0;
...@@ -278,7 +277,7 @@ set_var_from_str(char *str, char **ptr, NumericVar *dest) ...@@ -278,7 +277,7 @@ set_var_from_str(char *str, char **ptr, NumericVar *dest)
* ---------- * ----------
*/ */
static char * static char *
get_str_from_var(NumericVar *var, int dscale) get_str_from_var(Numeric *var, int dscale)
{ {
char *str; char *str;
char *cp; char *cp;
...@@ -370,10 +369,10 @@ get_str_from_var(NumericVar *var, int dscale) ...@@ -370,10 +369,10 @@ get_str_from_var(NumericVar *var, int dscale)
* Input function for numeric data type * Input function for numeric data type
* ---------- * ----------
*/ */
NumericVar * Numeric *
PGTYPESnumeric_aton(char *str, char **endptr) PGTYPESnumeric_aton(char *str, char **endptr)
{ {
NumericVar *value = (NumericVar *)pgtypes_alloc(sizeof(NumericVar)); Numeric *value = (Numeric *)pgtypes_alloc(sizeof(Numeric));
int ret; int ret;
#if 0 #if 0
long typmod = -1; long typmod = -1;
...@@ -403,7 +402,7 @@ PGTYPESnumeric_aton(char *str, char **endptr) ...@@ -403,7 +402,7 @@ PGTYPESnumeric_aton(char *str, char **endptr)
* ---------- * ----------
*/ */
char * char *
PGTYPESnumeric_ntoa(NumericVar *num) PGTYPESnumeric_ntoa(Numeric *num)
{ {
return(get_str_from_var(num, num->dscale)); return(get_str_from_var(num, num->dscale));
} }
...@@ -416,7 +415,7 @@ PGTYPESnumeric_ntoa(NumericVar *num) ...@@ -416,7 +415,7 @@ PGTYPESnumeric_ntoa(NumericVar *num)
* ---------- * ----------
*/ */
static void static void
zero_var(NumericVar *var) zero_var(Numeric *var)
{ {
digitbuf_free(var->buf); digitbuf_free(var->buf);
var->buf = NULL; var->buf = NULL;
...@@ -427,7 +426,7 @@ zero_var(NumericVar *var) ...@@ -427,7 +426,7 @@ zero_var(NumericVar *var)
} }
void void
PGTYPESnumeric_free(NumericVar *var) PGTYPESnumeric_free(Numeric *var)
{ {
digitbuf_free(var->buf); digitbuf_free(var->buf);
free(var); free(var);
...@@ -443,7 +442,7 @@ PGTYPESnumeric_free(NumericVar *var) ...@@ -443,7 +442,7 @@ PGTYPESnumeric_free(NumericVar *var)
* ---------- * ----------
*/ */
static int static int
cmp_abs(NumericVar *var1, NumericVar *var2) cmp_abs(Numeric *var1, Numeric *var2)
{ {
int i1 = 0; int i1 = 0;
int i2 = 0; int i2 = 0;
...@@ -501,7 +500,7 @@ cmp_abs(NumericVar *var1, NumericVar *var2) ...@@ -501,7 +500,7 @@ cmp_abs(NumericVar *var1, NumericVar *var2)
* ---------- * ----------
*/ */
static int static int
add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) add_abs(Numeric *var1, Numeric *var2, Numeric *result)
{ {
NumericDigit *res_buf; NumericDigit *res_buf;
NumericDigit *res_digits; NumericDigit *res_digits;
...@@ -589,7 +588,7 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) ...@@ -589,7 +588,7 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ---------- * ----------
*/ */
static int static int
sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) sub_abs(Numeric *var1, Numeric *var2, Numeric *result)
{ {
NumericDigit *res_buf; NumericDigit *res_buf;
NumericDigit *res_digits; NumericDigit *res_digits;
...@@ -673,7 +672,7 @@ sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) ...@@ -673,7 +672,7 @@ sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ---------- * ----------
*/ */
int int
PGTYPESnumeric_add(NumericVar *var1, NumericVar *var2, NumericVar *result) PGTYPESnumeric_add(Numeric *var1, Numeric *var2, Numeric *result)
{ {
/* /*
* Decide on the signs of the two variables what to do * Decide on the signs of the two variables what to do
...@@ -802,7 +801,7 @@ PGTYPESnumeric_add(NumericVar *var1, NumericVar *var2, NumericVar *result) ...@@ -802,7 +801,7 @@ PGTYPESnumeric_add(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ---------- * ----------
*/ */
int int
PGTYPESnumeric_sub(NumericVar *var1, NumericVar *var2, NumericVar *result) PGTYPESnumeric_sub(Numeric *var1, Numeric *var2, Numeric *result)
{ {
/* /*
* Decide on the signs of the two variables what to do * Decide on the signs of the two variables what to do
...@@ -933,7 +932,7 @@ PGTYPESnumeric_sub(NumericVar *var1, NumericVar *var2, NumericVar *result) ...@@ -933,7 +932,7 @@ PGTYPESnumeric_sub(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ---------- * ----------
*/ */
int int
PGTYPESnumeric_mul(NumericVar *var1, NumericVar *var2, NumericVar *result) PGTYPESnumeric_mul(Numeric *var1, Numeric *var2, Numeric *result)
{ {
NumericDigit *res_buf; NumericDigit *res_buf;
NumericDigit *res_digits; NumericDigit *res_digits;
...@@ -1024,7 +1023,7 @@ PGTYPESnumeric_mul(NumericVar *var1, NumericVar *var2, NumericVar *result) ...@@ -1024,7 +1023,7 @@ PGTYPESnumeric_mul(NumericVar *var1, NumericVar *var2, NumericVar *result)
* Note that this must be called before div_var. * Note that this must be called before div_var.
*/ */
static int static int
select_div_scale(NumericVar *var1, NumericVar *var2, int *rscale) select_div_scale(Numeric *var1, Numeric *var2, int *rscale)
{ {
int weight1, int weight1,
weight2, weight2,
...@@ -1091,14 +1090,14 @@ select_div_scale(NumericVar *var1, NumericVar *var2, int *rscale) ...@@ -1091,14 +1090,14 @@ select_div_scale(NumericVar *var1, NumericVar *var2, int *rscale)
} }
int int
PGTYPESnumeric_div(NumericVar *var1, NumericVar *var2, NumericVar *result) PGTYPESnumeric_div(Numeric *var1, Numeric *var2, Numeric *result)
{ {
NumericDigit *res_digits; NumericDigit *res_digits;
int res_ndigits; int res_ndigits;
int res_sign; int res_sign;
int res_weight; int res_weight;
NumericVar dividend; Numeric dividend;
NumericVar divisor[10]; Numeric divisor[10];
int ndigits_tmp; int ndigits_tmp;
int weight_tmp; int weight_tmp;
int rscale_tmp; int rscale_tmp;
...@@ -1214,7 +1213,7 @@ PGTYPESnumeric_div(NumericVar *var1, NumericVar *var2, NumericVar *result) ...@@ -1214,7 +1213,7 @@ PGTYPESnumeric_div(NumericVar *var1, NumericVar *var2, NumericVar *result)
int i; int i;
long sum = 0; long sum = 0;
memcpy(&divisor[guess], &divisor[1], sizeof(NumericVar)); memcpy(&divisor[guess], &divisor[1], sizeof(Numeric));
divisor[guess].buf = digitbuf_alloc(divisor[guess].ndigits); divisor[guess].buf = digitbuf_alloc(divisor[guess].ndigits);
divisor[guess].digits = divisor[guess].buf; divisor[guess].digits = divisor[guess].buf;
for (i = divisor[1].ndigits - 1; i >= 0; i--) for (i = divisor[1].ndigits - 1; i >= 0; i--)
...@@ -1297,7 +1296,7 @@ PGTYPESnumeric_div(NumericVar *var1, NumericVar *var2, NumericVar *result) ...@@ -1297,7 +1296,7 @@ PGTYPESnumeric_div(NumericVar *var1, NumericVar *var2, NumericVar *result)
int int
PGTYPESnumeric_cmp(NumericVar *var1, NumericVar *var2) { PGTYPESnumeric_cmp(Numeric *var1, Numeric *var2) {
/* use cmp_abs function to calculate the result */ /* use cmp_abs function to calculate the result */
...@@ -1327,14 +1326,14 @@ PGTYPESnumeric_cmp(NumericVar *var1, NumericVar *var2) { ...@@ -1327,14 +1326,14 @@ PGTYPESnumeric_cmp(NumericVar *var1, NumericVar *var2) {
} }
int int
PGTYPESnumeric_iton(signed int int_val, NumericVar *var) { PGTYPESnumeric_iton(signed int int_val, Numeric *var) {
/* implicit conversion */ /* implicit conversion */
signed long int long_int = int_val; signed long int long_int = int_val;
return PGTYPESnumeric_lton(long_int, var); return PGTYPESnumeric_lton(long_int, var);
} }
int int
PGTYPESnumeric_lton(signed long int long_val, NumericVar *var) { PGTYPESnumeric_lton(signed long int long_val, Numeric *var) {
/* calculate the size of the long int number */ /* calculate the size of the long int number */
/* a number n needs log_10 n digits */ /* a number n needs log_10 n digits */
/* however we multiply by 10 each time and compare instead of /* however we multiply by 10 each time and compare instead of
...@@ -1386,7 +1385,7 @@ PGTYPESnumeric_lton(signed long int long_val, NumericVar *var) { ...@@ -1386,7 +1385,7 @@ PGTYPESnumeric_lton(signed long int long_val, NumericVar *var) {
} }
int int
PGTYPESnumeric_copy(NumericVar *src, NumericVar *dst) { PGTYPESnumeric_copy(Numeric *src, Numeric *dst) {
int i; int i;
zero_var(dst); zero_var(dst);
...@@ -1407,10 +1406,10 @@ PGTYPESnumeric_copy(NumericVar *src, NumericVar *dst) { ...@@ -1407,10 +1406,10 @@ PGTYPESnumeric_copy(NumericVar *src, NumericVar *dst) {
} }
int int
PGTYPESnumeric_dton(double d, NumericVar *dst) PGTYPESnumeric_dton(double d, Numeric *dst)
{ {
char buffer[100]; char buffer[100];
NumericVar *tmp; Numeric *tmp;
if (sprintf(buffer, "%f", d) == 0) if (sprintf(buffer, "%f", d) == 0)
return -1; return -1;
...@@ -1424,7 +1423,7 @@ PGTYPESnumeric_dton(double d, NumericVar *dst) ...@@ -1424,7 +1423,7 @@ PGTYPESnumeric_dton(double d, NumericVar *dst)
} }
static int static int
numericvar_to_double_no_overflow(NumericVar *var, double *dp) numericvar_to_double_no_overflow(Numeric *var, double *dp)
{ {
char *tmp; char *tmp;
double val; double val;
...@@ -1448,7 +1447,7 @@ numericvar_to_double_no_overflow(NumericVar *var, double *dp) ...@@ -1448,7 +1447,7 @@ numericvar_to_double_no_overflow(NumericVar *var, double *dp)
} }
int int
PGTYPESnumeric_ntod(NumericVar* nv, double* dp) { PGTYPESnumeric_ntod(Numeric* nv, double* dp) {
double tmp; double tmp;
int i; int i;
...@@ -1459,7 +1458,7 @@ PGTYPESnumeric_ntod(NumericVar* nv, double* dp) { ...@@ -1459,7 +1458,7 @@ PGTYPESnumeric_ntod(NumericVar* nv, double* dp) {
} }
int int
PGTYPESnumeric_ntoi(NumericVar* nv, int* ip) { PGTYPESnumeric_ntoi(Numeric* nv, int* ip) {
long l; long l;
int i; int i;
...@@ -1476,7 +1475,7 @@ PGTYPESnumeric_ntoi(NumericVar* nv, int* ip) { ...@@ -1476,7 +1475,7 @@ PGTYPESnumeric_ntoi(NumericVar* nv, int* ip) {
} }
int int
PGTYPESnumeric_ntol(NumericVar* nv, long* lp) { PGTYPESnumeric_ntol(Numeric* nv, long* lp) {
int i; int i;
long l = 0; long l = 0;
...@@ -1502,7 +1501,7 @@ PGTYPESnumeric_ntol(NumericVar* nv, long* lp) { ...@@ -1502,7 +1501,7 @@ PGTYPESnumeric_ntol(NumericVar* nv, long* lp) {
/* Finally we need some wrappers for the INFORMIX functions */ /* Finally we need some wrappers for the INFORMIX functions */
int int
decadd(NumericVar *arg1, NumericVar *arg2, NumericVar *sum) decadd(Numeric *arg1, Numeric *arg2, Numeric *sum)
{ {
int i = PGTYPESnumeric_add(arg1, arg2, sum); int i = PGTYPESnumeric_add(arg1, arg2, sum);
...@@ -1515,7 +1514,7 @@ decadd(NumericVar *arg1, NumericVar *arg2, NumericVar *sum) ...@@ -1515,7 +1514,7 @@ decadd(NumericVar *arg1, NumericVar *arg2, NumericVar *sum)
} }
int int
deccmp(NumericVar *arg1, NumericVar *arg2) deccmp(Numeric *arg1, Numeric *arg2)
{ {
int i = PGTYPESnumeric_cmp(arg1, arg2); int i = PGTYPESnumeric_cmp(arg1, arg2);
...@@ -1524,7 +1523,7 @@ deccmp(NumericVar *arg1, NumericVar *arg2) ...@@ -1524,7 +1523,7 @@ deccmp(NumericVar *arg1, NumericVar *arg2)
} }
void void
deccopy(NumericVar *src, NumericVar *target) deccopy(Numeric *src, Numeric *target)
{ {
PGTYPESnumeric_copy(src, target); PGTYPESnumeric_copy(src, target);
} }
...@@ -1547,7 +1546,7 @@ strndup(char *str, int len) ...@@ -1547,7 +1546,7 @@ strndup(char *str, int len)
} }
int int
deccvasc(char *cp, int len, NumericVar *np) deccvasc(char *cp, int len, Numeric *np)
{ {
char *str = strndup(cp, len); /* Numeric_in always converts the complete string */ char *str = strndup(cp, len); /* Numeric_in always converts the complete string */
int ret = 0; int ret = 0;
...@@ -1575,25 +1574,25 @@ deccvasc(char *cp, int len, NumericVar *np) ...@@ -1575,25 +1574,25 @@ deccvasc(char *cp, int len, NumericVar *np)
} }
int int
deccvdbl(double dbl, NumericVar *np) deccvdbl(double dbl, Numeric *np)
{ {
return(PGTYPESnumeric_dton(dbl, np)); return(PGTYPESnumeric_dton(dbl, np));
} }
int int
deccvint(int in, NumericVar *np) deccvint(int in, Numeric *np)
{ {
return(PGTYPESnumeric_iton(in, np)); return(PGTYPESnumeric_iton(in, np));
} }
int int
deccvlong(long lng, NumericVar *np) deccvlong(long lng, Numeric *np)
{ {
return(PGTYPESnumeric_lton(lng, np)); return(PGTYPESnumeric_lton(lng, np));
} }
int int
decdiv(NumericVar *n1, NumericVar *n2, NumericVar *n3) decdiv(Numeric *n1, Numeric *n2, Numeric *n3)
{ {
int i = PGTYPESnumeric_div(n1, n2, n3), ret = 0; int i = PGTYPESnumeric_div(n1, n2, n3), ret = 0;
...@@ -1612,7 +1611,7 @@ decdiv(NumericVar *n1, NumericVar *n2, NumericVar *n3) ...@@ -1612,7 +1611,7 @@ decdiv(NumericVar *n1, NumericVar *n2, NumericVar *n3)
} }
int int
decmul(NumericVar *n1, NumericVar *n2, NumericVar *n3) decmul(Numeric *n1, Numeric *n2, Numeric *n3)
{ {
int i = PGTYPESnumeric_mul(n1, n2, n3), ret = 0; int i = PGTYPESnumeric_mul(n1, n2, n3), ret = 0;
...@@ -1629,7 +1628,7 @@ decmul(NumericVar *n1, NumericVar *n2, NumericVar *n3) ...@@ -1629,7 +1628,7 @@ decmul(NumericVar *n1, NumericVar *n2, NumericVar *n3)
} }
int int
decsub(NumericVar *n1, NumericVar *n2, NumericVar *n3) decsub(Numeric *n1, Numeric *n2, Numeric *n3)
{ {
int i = PGTYPESnumeric_sub(n1, n2, n3), ret = 0; int i = PGTYPESnumeric_sub(n1, n2, n3), ret = 0;
...@@ -1646,7 +1645,7 @@ decsub(NumericVar *n1, NumericVar *n2, NumericVar *n3) ...@@ -1646,7 +1645,7 @@ decsub(NumericVar *n1, NumericVar *n2, NumericVar *n3)
} }
int int
dectoasc(NumericVar *np, char *cp, int len, int right) dectoasc(Numeric *np, char *cp, int len, int right)
{ {
char *str; char *str;
...@@ -1666,13 +1665,13 @@ dectoasc(NumericVar *np, char *cp, int len, int right) ...@@ -1666,13 +1665,13 @@ dectoasc(NumericVar *np, char *cp, int len, int right)
} }
int int
dectodbl(NumericVar *np, double *dblp) dectodbl(Numeric *np, double *dblp)
{ {
return(PGTYPESnumeric_ntod(np, dblp)); return(PGTYPESnumeric_ntod(np, dblp));
} }
int int
dectoint(NumericVar *np, int *ip) dectoint(Numeric *np, int *ip)
{ {
int ret = PGTYPESnumeric_ntoi(np, ip); int ret = PGTYPESnumeric_ntoi(np, ip);
...@@ -1683,7 +1682,7 @@ dectoint(NumericVar *np, int *ip) ...@@ -1683,7 +1682,7 @@ dectoint(NumericVar *np, int *ip)
} }
int int
dectolong(NumericVar *np, long *lngp) dectolong(Numeric *np, long *lngp)
{ {
int ret = PGTYPESnumeric_ntol(np, lngp); int ret = PGTYPESnumeric_ntol(np, lngp);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "extern.h" #include "extern.h"
#include "pgtypes_error.h" #include "pgtypes_error.h"
#include "pgtypes_timestamp.h" #include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
#include "datetime.h" #include "datetime.h"
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -368,7 +369,7 @@ dtcvasc (char *str, Timestamp *ts) ...@@ -368,7 +369,7 @@ dtcvasc (char *str, Timestamp *ts)
} }
int int
dtsub (Timestamp *ts1, Timestamp *ts2, Timestamp *iv) dtsub (Timestamp *ts1, Timestamp *ts2, Interval *iv)
{ {
return 0; return 0;
} }
...@@ -386,7 +387,29 @@ dttofmtasc (Timestamp *ts, char *output, int str_len, char *fmtstr) ...@@ -386,7 +387,29 @@ dttofmtasc (Timestamp *ts, char *output, int str_len, char *fmtstr)
} }
int int
intoasc(Timestamp *i, char *str) 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; return 0;
} }
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.63 2003/03/18 10:46:39 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.64 2003/03/27 14:29:17 meskes Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */ /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
...@@ -157,7 +157,8 @@ main(int argc, char *const argv[]) ...@@ -157,7 +157,8 @@ main(int argc, char *const argv[])
if (strcmp(optarg, "INFORMIX") == 0) if (strcmp(optarg, "INFORMIX") == 0)
{ {
compat = ECPG_COMPAT_INFORMIX; compat = ECPG_COMPAT_INFORMIX;
add_preprocessor_define("dec_t=NumericVar"); add_preprocessor_define("dec_t=Numeric");
add_preprocessor_define("intrvl_t=Interval");
} }
else else
{ {
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.214 2003/03/21 14:17:47 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.215 2003/03/27 14:29:17 meskes Exp $ */
/* Copyright comment */ /* Copyright comment */
%{ %{
...@@ -4258,8 +4258,8 @@ single_vt_type: common_type ...@@ -4258,8 +4258,8 @@ single_vt_type: common_type
} }
else if (strcmp($1, "interval") == 0) else if (strcmp($1, "interval") == 0)
{ {
$$.type_enum = ECPGt_timestamp; $$.type_enum = ECPGt_interval;
$$.type_str = make_str("Timestamp"); $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = -1;
$$.type_index = -1; $$.type_index = -1;
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
...@@ -4526,8 +4526,8 @@ var_type: common_type ...@@ -4526,8 +4526,8 @@ var_type: common_type
} }
else if (strcmp($1, "interval") == 0) else if (strcmp($1, "interval") == 0)
{ {
$$.type_enum = ECPGt_timestamp; $$.type_enum = ECPGt_interval;
$$.type_str = make_str("Timestamp"); $$.type_str = EMPTY;
$$.type_dimension = -1; $$.type_dimension = -1;
$$.type_index = -1; $$.type_index = -1;
$$.type_sizeof = NULL; $$.type_sizeof = NULL;
...@@ -4732,9 +4732,21 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer ...@@ -4732,9 +4732,21 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
if (dimension < 0) if (dimension < 0)
$$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("NumericVar"), mm_strdup($2), $4); $$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), $4);
else
$$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), mm_strdup(dim), $4);
break;
case ECPGt_interval:
if (dimension < 0)
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
if (dimension < 0)
$$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), $4);
else else
$$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("NumericVar"), mm_strdup($2), mm_strdup(dim), $4); $$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), mm_strdup(dim), $4);
break; break;
default: default:
......
...@@ -172,6 +172,9 @@ get_type(enum ECPGttype type) ...@@ -172,6 +172,9 @@ get_type(enum ECPGttype type)
case ECPGt_numeric: case ECPGt_numeric:
return ("ECPGt_numeric"); return ("ECPGt_numeric");
break; break;
case ECPGt_interval:
return ("ECPGt_interval");
break;
case ECPGt_descriptor: case ECPGt_descriptor:
return ("ECPGt_descriptor"); return ("ECPGt_descriptor");
break; break;
...@@ -334,7 +337,15 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, ...@@ -334,7 +337,15 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use a pointer here * we have to use a pointer here
*/ */
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name); sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
sprintf(offset, "sizeof(struct NumericVar)"); 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)");
break; break;
case ECPGt_date: case ECPGt_date:
......
#include <stdio.h> #include <stdio.h>
#include <pgtypes_numeric.h> #include <pgtypes_numeric.h>
#include <decimal.h>
int int
main() main()
{ {
char *text="error\n"; char *text="error\n";
NumericVar *value1, *value2, *res; Numeric *value1, *value2, *res;
exec sql begin declare section; exec sql begin declare section;
decimal(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ; decimal(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ;
numeric num;
exec sql end declare section; exec sql end declare section;
double d; double d;
FILE *dbgs; FILE *dbgs;
......
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