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
- Made sure preprocessor accepts new datatypes.
- 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 library to 3.4.2.
- 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"
......@@ -13,6 +13,7 @@
#include "pgtypes_numeric.h"
#include "pgtypes_date.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
bool
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;
double dres;
char *scan_length;
NumericVar *nres;
Numeric *nres;
Date ddres;
Timestamp tres;
Interval *ires;
case ECPGt_short:
case ECPGt_int:
......@@ -392,16 +394,39 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
ECPGraise(lineno, ECPG_NUMERIC_FORMAT, pval);
return (false);
}
}
else
nres = PGTYPESnumeric_aton("0.0", &scan_length);
PGTYPESnumeric_copy(nres, (NumericVar *)(var + offset * act_tuple));
PGTYPESnumeric_copy(nres, (Numeric *)(var + offset * act_tuple));
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:
if (pval)
{
......@@ -416,7 +441,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
ECPGraise(lineno, ECPG_DATE_FORMAT, pval);
return (false);
}
......@@ -438,7 +463,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, pval);
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.
......@@ -29,6 +29,7 @@
#include "pgtypes_numeric.h"
#include "pgtypes_date.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
/* variables visible to the programs */
struct sqlca sqlca =
......@@ -846,7 +847,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
{
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);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
......@@ -862,7 +863,48 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
}
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);
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"
......@@ -53,6 +53,8 @@ ECPGtype_name(enum ECPGttype typ)
return "date";
case ECPGt_timestamp:
return "timestamp";
case ECPGt_interval:
return "interval";
default:
abort();
}
......
#include <pgtypes_timestamp.h>
#include <pgtypes_interval.h>
#ifndef dtime_t
#define dtime_t Timestamp
#endif /* dtime_t */
#ifndef intrvl_t
#define intrvl_t Timestamp
#define intrvl_t Interval
#endif /* intrvl_t */
extern void dtcurrent (dtime_t *);
......
#include <pgtypes_numeric.h>
#ifndef dec_t
#define dec_t NumericVar
#define dec_t Numeric
#endif /* dec_t */
int decadd(dec_t *, NumericVar *, NumericVar *);
int deccmp(dec_t *, NumericVar *);
void deccopy(dec_t *, NumericVar *);
int decadd(dec_t *, Numeric *, Numeric *);
int deccmp(dec_t *, Numeric *);
void deccopy(dec_t *, Numeric *);
int deccvasc(char *, int, dec_t *);
int deccvdbl(double, dec_t *);
int deccvint(int, dec_t *);
int deccvlong(long, dec_t *);
int decdiv(dec_t *, NumericVar *, NumericVar *);
int decmul(dec_t *, NumericVar *, NumericVar *);
int decsub(dec_t *, NumericVar *, NumericVar *);
int decdiv(dec_t *, Numeric *, Numeric *);
int decmul(dec_t *, Numeric *, Numeric *);
int decsub(dec_t *, Numeric *, Numeric *);
int dectoasc(dec_t *, char *, int, int);
int dectodbl(dec_t *, double *);
int dectoint(dec_t *, int *);
......
......@@ -20,12 +20,16 @@
#define ECPG_INT_FORMAT -204
#define ECPG_UINT_FORMAT -205
#define ECPG_FLOAT_FORMAT -206
#define ECPG_CONVERT_BOOL -207
#define ECPG_EMPTY -208
#define ECPG_MISSING_INDICATOR -209
#define ECPG_NO_ARRAY -210
#define ECPG_DATA_NOT_ARRAY -211
#define ECPG_ARRAY_INSERT -212
#define ECPG_NUMERIC_FORMAT -207
#define ECPG_INTERVAL_FORMAT -208
#define ECPG_DATE_FORMAT -209
#define ECPG_TIMESTAMP_FORMAT -210
#define ECPG_CONVERT_BOOL -211
#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_NOT_CONN -221
......
......@@ -54,7 +54,8 @@ enum ECPGttype
ECPGt_descriptor, /* sql descriptor, no C variable */
ECPGt_numeric,
ECPGt_date,
ECPGt_timestamp
ECPGt_timestamp,
ECPGt_interval
};
/* 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
#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 struct NumericVar
typedef struct
{
int ndigits; /* number of digits in digits[] - can be 0! */
int weight; /* weight of first digit */
......@@ -11,23 +18,23 @@ typedef struct NumericVar
int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
NumericDigit *buf; /* start of alloc'd space for digits[] */
NumericDigit *digits; /* decimal digits */
} NumericVar;
} Numeric;
NumericVar *PGTYPESnew(void);
void PGTYPESnumeric_free(NumericVar *);
NumericVar *PGTYPESnumeric_aton(char *, char **);
char *PGTYPESnumeric_ntoa(NumericVar *);
int PGTYPESnumeric_add(NumericVar *, NumericVar *, NumericVar *);
int PGTYPESnumeric_sub(NumericVar *, NumericVar *, NumericVar *);
int PGTYPESnumeric_mul(NumericVar *, NumericVar *, NumericVar *);
int PGTYPESnumeric_div(NumericVar *, NumericVar *, NumericVar *);
int PGTYPESnumeric_cmp(NumericVar *, NumericVar *);
int PGTYPESnumeric_iton(signed int, NumericVar *);
int PGTYPESnumeric_lton(signed long int, NumericVar *);
int PGTYPESnumeric_copy(NumericVar *, NumericVar *);
int PGTYPESnumeric_dton(double, NumericVar *);
int PGTYPESnumeric_ntod(NumericVar *, double *);
int PGTYPESnumeric_ntoi(NumericVar *, int *);
int PGTYPESnumeric_ntol(NumericVar *, long *);
Numeric *PGTYPESnew(void);
void PGTYPESnumeric_free(Numeric *);
Numeric *PGTYPESnumeric_aton(char *, char **);
char *PGTYPESnumeric_ntoa(Numeric *);
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_iton(signed int, Numeric *);
int PGTYPESnumeric_lton(signed long int, Numeric *);
int PGTYPESnumeric_copy(Numeric *, Numeric *);
int PGTYPESnumeric_dton(double, Numeric *);
int PGTYPESnumeric_ntod(Numeric *, double *);
int PGTYPESnumeric_ntoi(Numeric *, int *);
int PGTYPESnumeric_ntol(Numeric *, long *);
#endif /* PGTYPES_NUMERIC */
......@@ -4,7 +4,7 @@
#
# 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
SO_MAJOR_VERSION= 1
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
......
#include <errno.h>
#include <stdlib.h>
#include "extern.h"
......
This diff is collapsed.
......@@ -13,6 +13,7 @@
#include "extern.h"
#include "pgtypes_error.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
#include "datetime.h"
#ifdef HAVE_INT64_TIMESTAMP
......@@ -368,7 +369,7 @@ dtcvasc (char *str, Timestamp *ts)
}
int
dtsub (Timestamp *ts1, Timestamp *ts2, Timestamp *iv)
dtsub (Timestamp *ts1, Timestamp *ts2, Interval *iv)
{
return 0;
}
......@@ -386,8 +387,30 @@ dttofmtasc (Timestamp *ts, char *output, int str_len, char *fmtstr)
}
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;
}
/* $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. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
......@@ -157,7 +157,8 @@ main(int argc, char *const argv[])
if (strcmp(optarg, "INFORMIX") == 0)
{
compat = ECPG_COMPAT_INFORMIX;
add_preprocessor_define("dec_t=NumericVar");
add_preprocessor_define("dec_t=Numeric");
add_preprocessor_define("intrvl_t=Interval");
}
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 */
%{
......@@ -4258,8 +4258,8 @@ single_vt_type: common_type
}
else if (strcmp($1, "interval") == 0)
{
$$.type_enum = ECPGt_timestamp;
$$.type_str = make_str("Timestamp");
$$.type_enum = ECPGt_interval;
$$.type_str = EMPTY;
$$.type_dimension = -1;
$$.type_index = -1;
$$.type_sizeof = NULL;
......@@ -4526,8 +4526,8 @@ var_type: common_type
}
else if (strcmp($1, "interval") == 0)
{
$$.type_enum = ECPGt_timestamp;
$$.type_str = make_str("Timestamp");
$$.type_enum = ECPGt_interval;
$$.type_str = EMPTY;
$$.type_dimension = -1;
$$.type_index = -1;
$$.type_sizeof = NULL;
......@@ -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);
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
$$ = 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;
default:
......
......@@ -172,6 +172,9 @@ get_type(enum ECPGttype type)
case ECPGt_numeric:
return ("ECPGt_numeric");
break;
case ECPGt_interval:
return ("ECPGt_interval");
break;
case ECPGt_descriptor:
return ("ECPGt_descriptor");
break;
......@@ -334,7 +337,15 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use a pointer here
*/
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;
case ECPGt_date:
......
#include <stdio.h>
#include <pgtypes_numeric.h>
#include <decimal.h>
int
main()
{
char *text="error\n";
NumericVar *value1, *value2, *res;
Numeric *value1, *value2, *res;
exec sql begin declare section;
decimal(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ;
numeric num;
exec sql end declare section;
double d;
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