Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2e6f975

Browse files
author
Michael Meskes
committed
Started adding date and timestamp.
1 parent 26a6378 commit 2e6f975

22 files changed

+3674
-50
lines changed

src/interfaces/ecpg/ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,10 @@ Sun Mar 16 11:28:01 CET 2003
13601360
- Started with a pgtypes library.
13611361
- Renamed lib directory to ecpglib.
13621362
- Added numerical functions to library and preprocessor.
1363+
1364+
Don Mar 20 16:53:40 CET 2003
1365+
1366+
- Added date/timestamp to library and preprocessor.
13631367
- Set ecpg version to 2.12.0.
13641368
- Set ecpg library to 3.4.2.
13651369
- Set pgtypes library to 1.0.0

src/interfaces/ecpg/ecpglib/data.c

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -11,6 +11,8 @@
1111
#include "extern.h"
1212
#include "sqlca.h"
1313
#include "pgtypes_numeric.h"
14+
#include "pgtypes_date.h"
15+
#include "pgtypes_timestamp.h"
1416

1517
bool
1618
ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
@@ -99,6 +101,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
99101
double dres;
100102
char *scan_length;
101103
NumericVar *nres;
104+
Date ddres;
105+
Timestamp tres;
102106

103107
case ECPGt_short:
104108
case ECPGt_int:
@@ -397,7 +401,51 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
397401

398402
PGTYPESnumeric_copy(nres, (NumericVar *)(var + offset * act_tuple));
399403
break;
404+
405+
case ECPGt_date:
406+
if (pval)
407+
{
408+
if (isarray && *pval == '"')
409+
ddres = PGTYPESdate_atod(pval + 1, &scan_length);
410+
else
411+
ddres = PGTYPESdate_atod(pval, &scan_length);
412+
413+
if (isarray && *scan_length == '"')
414+
scan_length++;
415+
416+
if ((isarray && *scan_length != ',' && *scan_length != '}')
417+
|| (!isarray && *scan_length != '\0')) /* Garbage left */
418+
{
419+
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
420+
return (false);
421+
}
422+
423+
*((Date *)(var + offset * act_tuple)) = ddres;
424+
}
425+
break;
400426

427+
case ECPGt_timestamp:
428+
if (pval)
429+
{
430+
if (isarray && *pval == '"')
431+
tres = PGTYPEStimestamp_atot(pval + 1, &scan_length);
432+
else
433+
tres = PGTYPEStimestamp_atot(pval, &scan_length);
434+
435+
if (isarray && *scan_length == '"')
436+
scan_length++;
437+
438+
if ((isarray && *scan_length != ',' && *scan_length != '}')
439+
|| (!isarray && *scan_length != '\0')) /* Garbage left */
440+
{
441+
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
442+
return (false);
443+
}
444+
445+
*((Timestamp *)(var + offset * act_tuple)) = tres;
446+
}
447+
break;
448+
401449
default:
402450
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type));
403451
return (false);

src/interfaces/ecpg/ecpglib/execute.c

+87-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.3 2003/03/19 16:05:41 petere Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.4 2003/03/20 15:56:50 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -27,6 +27,8 @@
2727
#include "sqlca.h"
2828
#include "sql3types.h"
2929
#include "pgtypes_numeric.h"
30+
#include "pgtypes_date.h"
31+
#include "pgtypes_timestamp.h"
3032

3133
/* variables visible to the programs */
3234
struct sqlca sqlca =
@@ -59,8 +61,7 @@ struct sqlca sqlca =
5961
/* This function returns a newly malloced string that has the \
6062
in the argument quoted with \ and the ' quoted with ' as SQL92 says.
6163
*/
62-
static
63-
char *
64+
static char *
6465
quote_postgres(char *arg, int lineno)
6566
{
6667
char *res = (char *) ECPGalloc(2 * strlen(arg) + 3, lineno);
@@ -876,6 +877,89 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
876877
free(str);
877878
}
878879
break;
880+
881+
case ECPGt_date:
882+
{
883+
char *str = NULL;
884+
int slen;
885+
886+
if (var->arrsize > 1)
887+
{
888+
for (element = 0; element < var->arrsize; element++)
889+
{
890+
str = PGTYPESdate_dtoa(*(Date *)((var + var->offset * element)->value));
891+
slen = strlen (str);
892+
893+
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
894+
return false;
895+
896+
if (!element)
897+
strcpy(mallocedval, "'{");
898+
899+
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
900+
strcpy(mallocedval + strlen(mallocedval), ",");
901+
}
902+
strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
903+
}
904+
else
905+
{
906+
str = PGTYPESdate_dtoa(*(Date *)(var->value));
907+
slen = strlen (str);
908+
909+
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
910+
return false;
911+
912+
strncpy(mallocedval, str , slen);
913+
mallocedval[slen] = '\0';
914+
}
915+
916+
*tobeinserted_p = mallocedval;
917+
*malloced_p = true;
918+
free(str);
919+
}
920+
break;
921+
922+
case ECPGt_timestamp:
923+
{
924+
char *str = NULL;
925+
int slen;
926+
927+
if (var->arrsize > 1)
928+
{
929+
for (element = 0; element < var->arrsize; element++)
930+
{
931+
str = PGTYPEStimestamp_ttoa(*(Timestamp *)((var + var->offset * element)->value));
932+
slen = strlen (str);
933+
934+
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
935+
return false;
936+
937+
if (!element)
938+
strcpy(mallocedval, "'{");
939+
940+
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
941+
strcpy(mallocedval + strlen(mallocedval), ",");
942+
}
943+
strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
944+
}
945+
else
946+
{
947+
str = PGTYPEStimestamp_ttoa(*(Timestamp *)(var->value));
948+
slen = strlen (str);
949+
950+
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
951+
return false;
952+
953+
strncpy(mallocedval, str , slen);
954+
mallocedval[slen] = '\0';
955+
}
956+
957+
*tobeinserted_p = mallocedval;
958+
*malloced_p = true;
959+
free(str);
960+
}
961+
break;
962+
879963
default:
880964
/* Not implemented yet */
881965
ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *) ECPGtype_name(var->type));

src/interfaces/ecpg/ecpglib/typename.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.2 2003/03/20 15:56:50 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -49,6 +49,10 @@ ECPGtype_name(enum ECPGttype typ)
4949
return "char";
5050
case ECPGt_numeric:
5151
return "numeric";
52+
case ECPGt_date:
53+
return "date";
54+
case ECPGt_timestamp:
55+
return "timestamp";
5256
default:
5357
abort();
5458
}

src/interfaces/ecpg/include/decimal.h

+10
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22

33
#ifndef dec_t
44
#define dec_t NumericVar
5+
6+
#define CSHORTTYPE 0
7+
#define CMONEYTYPE 0
8+
#define CCHARTYPE 0
9+
#define CDECIMALTYPE 0
10+
#define CINTTYPE 0
11+
#define CDATETYPE 0
12+
#define CDOUBLETYPE 0
13+
#define CLONGTYPE 0
14+
515
#endif /* dec_t */

src/interfaces/ecpg/include/ecpgtype.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ enum ECPGttype
5252
ECPGt_NO_INDICATOR, /* no indicator */
5353
ECPGt_long_long, ECPGt_unsigned_long_long,
5454
ECPGt_descriptor, /* sql descriptor, no C variable */
55-
ECPGt_numeric
55+
ECPGt_numeric,
56+
ECPGt_date,
57+
ECPGt_timestamp
5658
};
5759

5860
/* descriptor items */
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef PGTYPES_DATETIME
2+
#define PGTYPES_DATETIME
3+
4+
#define Date long
5+
6+
extern Date PGTYPESdate_atod(char *, char **);
7+
extern char *PGTYPESdate_dtoa(Date);
8+
extern int PGTYPESdate_julmdy(Date, int*);
9+
extern int PGTYPESdate_mdyjul(int*, Date *);
10+
extern int PGTYPESdate_day(Date);
11+
12+
#endif /* PGTYPES_DATETIME */

src/interfaces/ecpg/include/pgtypes_error.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
#define PGTYPES_BAD_NUMERIC 202
33
#define PGTYPES_DIVIDE_ZERO 203
44

5-
#define PGTYPES_BAD_DATE 300
5+
#define PGTYPES_BAD_DATE 210
6+
7+
#define PGTYPES_BAD_TIMESTAMP 220
68

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef PGTYPES_TIMESTAMP
2+
#define PGTYPES_TIMESTAMP
3+
4+
#ifdef HAVE_INT64_TIMESTAMP
5+
typedef int64 Timestamp;
6+
typedef int64 TimestampTz;
7+
8+
#else
9+
typedef double Timestamp;
10+
typedef double TimestampTz;
11+
#endif
12+
13+
extern Timestamp PGTYPEStimestamp_atot(char *, char **);
14+
extern char *PGTYPEStimestamp_ttoa(Timestamp);
15+
16+
#endif /* PGTYPES_TIMESTAMP */

src/interfaces/ecpg/pgtypeslib/Makefile

+2-2
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.1 2003/03/16 10:42:54 meskes Exp $
7+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.2 2003/03/20 15:56:50 meskes Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -18,7 +18,7 @@ SO_MINOR_VERSION= 0.0
1818

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

21-
OBJS= numeric.o
21+
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o
2222

2323
all: all-lib
2424

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <errno.h>
2+
3+
#include "extern.h"
4+
5+
char *
6+
pgtypes_alloc(long size)
7+
{
8+
char *new = (char *) calloc(1L, size);
9+
10+
if (!new)
11+
{
12+
errno = ENOMEM;
13+
return NULL;
14+
}
15+
16+
memset(new, '\0', size);
17+
return (new);
18+
}
19+
20+
char *
21+
pgtypes_strdup(char *str)
22+
{
23+
char *new = (char *) strdup(str);
24+
25+
if (!new)
26+
errno = ENOMEM;
27+
return (new);
28+
}
29+

0 commit comments

Comments
 (0)