Skip to content

Commit 89508a8

Browse files
author
Michael Meskes
committed
More changes to pgtypeslib and set optimization to -O1.
1 parent 5e5c5cd commit 89508a8

File tree

18 files changed

+263
-109
lines changed

18 files changed

+263
-109
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,13 @@ Fri Mar 21 15:13:42 CET 2003
13691369

13701370
- Made sure preprocessor accepts new datatypes.
13711371
- Do not free prepared statements at the end of a transaction.
1372+
1373+
1374+
Thu Mar 27 15:23:58 CET 2003
1375+
1376+
- Some more updates to pgtypeslib.
1377+
- Set optimization to -O1 until I find the reason why code is broken
1378+
with -O2.
13721379
- Set ecpg version to 2.12.0.
13731380
- Set ecpg library to 3.4.2.
13741381
- Set pgtypes library to 1.0.0

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.3 2003/03/27 14:29:17 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -13,6 +13,7 @@
1313
#include "pgtypes_numeric.h"
1414
#include "pgtypes_date.h"
1515
#include "pgtypes_timestamp.h"
16+
#include "pgtypes_interval.h"
1617

1718
bool
1819
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,
100101
unsigned long ures;
101102
double dres;
102103
char *scan_length;
103-
NumericVar *nres;
104+
Numeric *nres;
104105
Date ddres;
105106
Timestamp tres;
107+
Interval *ires;
106108

107109
case ECPGt_short:
108110
case ECPGt_int:
@@ -392,16 +394,39 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
392394
if ((isarray && *scan_length != ',' && *scan_length != '}')
393395
|| (!isarray && *scan_length != '\0')) /* Garbage left */
394396
{
395-
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
397+
ECPGraise(lineno, ECPG_NUMERIC_FORMAT, pval);
396398
return (false);
397399
}
398400
}
399401
else
400402
nres = PGTYPESnumeric_aton("0.0", &scan_length);
401403

402-
PGTYPESnumeric_copy(nres, (NumericVar *)(var + offset * act_tuple));
404+
PGTYPESnumeric_copy(nres, (Numeric *)(var + offset * act_tuple));
403405
break;
404406

407+
case ECPGt_interval:
408+
if (pval)
409+
{
410+
if (isarray && *pval == '"')
411+
ires = PGTYPESinterval_atoi(pval + 1, &scan_length);
412+
else
413+
ires = PGTYPESinterval_atoi(pval, &scan_length);
414+
415+
if (isarray && *scan_length == '"')
416+
scan_length++;
417+
418+
if ((isarray && *scan_length != ',' && *scan_length != '}')
419+
|| (!isarray && *scan_length != '\0')) /* Garbage left */
420+
{
421+
ECPGraise(lineno, ECPG_INTERVAL_FORMAT, pval);
422+
return (false);
423+
}
424+
}
425+
else
426+
ires = PGTYPESinterval_atoi("0 seconds", NULL);
427+
428+
PGTYPESinterval_copy(ires, (Interval *)(var + offset * act_tuple));
429+
break;
405430
case ECPGt_date:
406431
if (pval)
407432
{
@@ -416,7 +441,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
416441
if ((isarray && *scan_length != ',' && *scan_length != '}')
417442
|| (!isarray && *scan_length != '\0')) /* Garbage left */
418443
{
419-
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
444+
ECPGraise(lineno, ECPG_DATE_FORMAT, pval);
420445
return (false);
421446
}
422447

@@ -438,7 +463,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
438463
if ((isarray && *scan_length != ',' && *scan_length != '}')
439464
|| (!isarray && *scan_length != '\0')) /* Garbage left */
440465
{
441-
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
466+
ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, pval);
442467
return (false);
443468
}
444469

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.5 2003/03/25 02:44:36 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.6 2003/03/27 14:29:17 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -29,6 +29,7 @@
2929
#include "pgtypes_numeric.h"
3030
#include "pgtypes_date.h"
3131
#include "pgtypes_timestamp.h"
32+
#include "pgtypes_interval.h"
3233

3334
/* variables visible to the programs */
3435
struct sqlca sqlca =
@@ -846,7 +847,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
846847
{
847848
for (element = 0; element < var->arrsize; element++)
848849
{
849-
str = PGTYPESnumeric_ntoa((NumericVar *)((var + var->offset * element)->value));
850+
str = PGTYPESnumeric_ntoa((Numeric *)((var + var->offset * element)->value));
850851
slen = strlen (str);
851852

852853
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
@@ -862,7 +863,48 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
862863
}
863864
else
864865
{
865-
str = PGTYPESnumeric_ntoa((NumericVar *)(var->value));
866+
str = PGTYPESnumeric_ntoa((Numeric *)(var->value));
867+
slen = strlen (str);
868+
869+
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
870+
return false;
871+
872+
strncpy(mallocedval, str , slen);
873+
mallocedval[slen] = '\0';
874+
}
875+
876+
*tobeinserted_p = mallocedval;
877+
*malloced_p = true;
878+
free(str);
879+
}
880+
break;
881+
882+
case ECPGt_interval:
883+
{
884+
char *str = NULL;
885+
int slen;
886+
887+
if (var->arrsize > 1)
888+
{
889+
for (element = 0; element < var->arrsize; element++)
890+
{
891+
str = PGTYPESinterval_itoa((Interval *)((var + var->offset * element)->value));
892+
slen = strlen (str);
893+
894+
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
895+
return false;
896+
897+
if (!element)
898+
strcpy(mallocedval, "'{");
899+
900+
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
901+
strcpy(mallocedval + strlen(mallocedval), ",");
902+
}
903+
strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
904+
}
905+
else
906+
{
907+
str = PGTYPESinterval_itoa((Interval *)(var->value));
866908
slen = strlen (str);
867909

868910
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))

src/interfaces/ecpg/ecpglib/typename.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.3 2003/03/27 14:29:17 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -53,6 +53,8 @@ ECPGtype_name(enum ECPGttype typ)
5353
return "date";
5454
case ECPGt_timestamp:
5555
return "timestamp";
56+
case ECPGt_interval:
57+
return "interval";
5658
default:
5759
abort();
5860
}

src/interfaces/ecpg/include/datetime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include <pgtypes_timestamp.h>
2+
#include <pgtypes_interval.h>
23

34
#ifndef dtime_t
45
#define dtime_t Timestamp
56
#endif /* dtime_t */
67

78
#ifndef intrvl_t
8-
#define intrvl_t Timestamp
9+
#define intrvl_t Interval
910
#endif /* intrvl_t */
1011

1112
extern void dtcurrent (dtime_t *);

src/interfaces/ecpg/include/decimal.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#include <pgtypes_numeric.h>
22

33
#ifndef dec_t
4-
#define dec_t NumericVar
4+
#define dec_t Numeric
55
#endif /* dec_t */
66

7-
int decadd(dec_t *, NumericVar *, NumericVar *);
8-
int deccmp(dec_t *, NumericVar *);
9-
void deccopy(dec_t *, NumericVar *);
7+
int decadd(dec_t *, Numeric *, Numeric *);
8+
int deccmp(dec_t *, Numeric *);
9+
void deccopy(dec_t *, Numeric *);
1010
int deccvasc(char *, int, dec_t *);
1111
int deccvdbl(double, dec_t *);
1212
int deccvint(int, dec_t *);
1313
int deccvlong(long, dec_t *);
14-
int decdiv(dec_t *, NumericVar *, NumericVar *);
15-
int decmul(dec_t *, NumericVar *, NumericVar *);
16-
int decsub(dec_t *, NumericVar *, NumericVar *);
14+
int decdiv(dec_t *, Numeric *, Numeric *);
15+
int decmul(dec_t *, Numeric *, Numeric *);
16+
int decsub(dec_t *, Numeric *, Numeric *);
1717
int dectoasc(dec_t *, char *, int, int);
1818
int dectodbl(dec_t *, double *);
1919
int dectoint(dec_t *, int *);

src/interfaces/ecpg/include/ecpgerrno.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
#define ECPG_INT_FORMAT -204
2121
#define ECPG_UINT_FORMAT -205
2222
#define ECPG_FLOAT_FORMAT -206
23-
#define ECPG_CONVERT_BOOL -207
24-
#define ECPG_EMPTY -208
25-
#define ECPG_MISSING_INDICATOR -209
26-
#define ECPG_NO_ARRAY -210
27-
#define ECPG_DATA_NOT_ARRAY -211
28-
#define ECPG_ARRAY_INSERT -212
23+
#define ECPG_NUMERIC_FORMAT -207
24+
#define ECPG_INTERVAL_FORMAT -208
25+
#define ECPG_DATE_FORMAT -209
26+
#define ECPG_TIMESTAMP_FORMAT -210
27+
#define ECPG_CONVERT_BOOL -211
28+
#define ECPG_EMPTY -212
29+
#define ECPG_MISSING_INDICATOR -213
30+
#define ECPG_NO_ARRAY -214
31+
#define ECPG_DATA_NOT_ARRAY -215
32+
#define ECPG_ARRAY_INSERT -216
2933

3034
#define ECPG_NO_CONN -220
3135
#define ECPG_NOT_CONN -221

src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ enum ECPGttype
5454
ECPGt_descriptor, /* sql descriptor, no C variable */
5555
ECPGt_numeric,
5656
ECPGt_date,
57-
ECPGt_timestamp
57+
ECPGt_timestamp,
58+
ECPGt_interval
5859
};
5960

6061
/* descriptor items */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef PGTYPES_INTERVAL
2+
#define PGTYPES_INTERVAL
3+
4+
#include <pgtypes_timestamp.h>
5+
6+
typedef struct
7+
{
8+
#ifdef HAVE_INT64_TIMESTAMP
9+
int64 time; /* all time units other than months and years */
10+
#else
11+
double time; /* all time units other than months and years */
12+
#endif
13+
long month; /* months and years, after time for alignment */
14+
} Interval;
15+
16+
extern Interval *PGTYPESinterval_atoi(char *, char **);
17+
extern char *PGTYPESinterval_itoa(Interval *);
18+
extern int PGTYPESinterval_copy(Interval *, Interval *);
19+
20+
#endif /* PGTYPES_INTERVAL */
Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#ifndef PGTYPES_NUMERIC
22
#define PGTYPES_NUMERIC
33

4+
#define NUMERIC_POS 0x0000
5+
#define NUMERIC_NEG 0x4000
6+
#define NUMERIC_MAX_PRECISION 1000
7+
#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
8+
#define NUMERIC_MIN_DISPLAY_SCALE 0
9+
#define NUMERIC_MIN_SIG_DIGITS 16
10+
411
typedef unsigned char NumericDigit;
5-
typedef struct NumericVar
12+
typedef struct
613
{
714
int ndigits; /* number of digits in digits[] - can be 0! */
815
int weight; /* weight of first digit */
@@ -11,23 +18,23 @@ typedef struct NumericVar
1118
int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
1219
NumericDigit *buf; /* start of alloc'd space for digits[] */
1320
NumericDigit *digits; /* decimal digits */
14-
} NumericVar;
21+
} Numeric;
1522

16-
NumericVar *PGTYPESnew(void);
17-
void PGTYPESnumeric_free(NumericVar *);
18-
NumericVar *PGTYPESnumeric_aton(char *, char **);
19-
char *PGTYPESnumeric_ntoa(NumericVar *);
20-
int PGTYPESnumeric_add(NumericVar *, NumericVar *, NumericVar *);
21-
int PGTYPESnumeric_sub(NumericVar *, NumericVar *, NumericVar *);
22-
int PGTYPESnumeric_mul(NumericVar *, NumericVar *, NumericVar *);
23-
int PGTYPESnumeric_div(NumericVar *, NumericVar *, NumericVar *);
24-
int PGTYPESnumeric_cmp(NumericVar *, NumericVar *);
25-
int PGTYPESnumeric_iton(signed int, NumericVar *);
26-
int PGTYPESnumeric_lton(signed long int, NumericVar *);
27-
int PGTYPESnumeric_copy(NumericVar *, NumericVar *);
28-
int PGTYPESnumeric_dton(double, NumericVar *);
29-
int PGTYPESnumeric_ntod(NumericVar *, double *);
30-
int PGTYPESnumeric_ntoi(NumericVar *, int *);
31-
int PGTYPESnumeric_ntol(NumericVar *, long *);
23+
Numeric *PGTYPESnew(void);
24+
void PGTYPESnumeric_free(Numeric *);
25+
Numeric *PGTYPESnumeric_aton(char *, char **);
26+
char *PGTYPESnumeric_ntoa(Numeric *);
27+
int PGTYPESnumeric_add(Numeric *, Numeric *, Numeric *);
28+
int PGTYPESnumeric_sub(Numeric *, Numeric *, Numeric *);
29+
int PGTYPESnumeric_mul(Numeric *, Numeric *, Numeric *);
30+
int PGTYPESnumeric_div(Numeric *, Numeric *, Numeric *);
31+
int PGTYPESnumeric_cmp(Numeric *, Numeric *);
32+
int PGTYPESnumeric_iton(signed int, Numeric *);
33+
int PGTYPESnumeric_lton(signed long int, Numeric *);
34+
int PGTYPESnumeric_copy(Numeric *, Numeric *);
35+
int PGTYPESnumeric_dton(double, Numeric *);
36+
int PGTYPESnumeric_ntod(Numeric *, double *);
37+
int PGTYPESnumeric_ntoi(Numeric *, int *);
38+
int PGTYPESnumeric_ntol(Numeric *, long *);
3239

3340
#endif /* PGTYPES_NUMERIC */

src/interfaces/ecpg/pgtypeslib/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.2 2003/03/20 15:56:50 meskes Exp $
7+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.3 2003/03/27 14:29:17 meskes Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -16,7 +16,7 @@ NAME= pgtypes
1616
SO_MAJOR_VERSION= 1
1717
SO_MINOR_VERSION= 0.0
1818

19-
override CPPFLAGS := -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS)
19+
override CPPFLAGS := -O1 -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS)
2020

2121
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o
2222

src/interfaces/ecpg/pgtypeslib/common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <errno.h>
2-
#include <stdlib.h>
32

43
#include "extern.h"
54

0 commit comments

Comments
 (0)