Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e6f975

Browse files
author
Michael Meskes
committed
Started adding date and timestamp.
1 parent26a6378 commit2e6f975

File tree

22 files changed

+3674
-50
lines changed

22 files changed

+3674
-50
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
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

Lines changed: 49 additions & 1 deletion
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(constPGresult*results,intact_tuple,intact_field,intlineno,
@@ -99,6 +101,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
99101
doubledres;
100102
char*scan_length;
101103
NumericVar*nres;
104+
Dateddres;
105+
Timestamptres;
102106

103107
caseECPGt_short:
104108
caseECPGt_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+
caseECPGt_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+
caseECPGt_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

Lines changed: 87 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.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
structsqlcasqlca=
@@ -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+
staticchar*
6465
quote_postgres(char*arg,intlineno)
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+
caseECPGt_date:
882+
{
883+
char*str=NULL;
884+
intslen;
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+
caseECPGt_timestamp:
923+
{
924+
char*str=NULL;
925+
intslen;
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

Lines changed: 5 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.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
caseECPGt_numeric:
5151
return"numeric";
52+
caseECPGt_date:
53+
return"date";
54+
caseECPGt_timestamp:
55+
return"timestamp";
5256
default:
5357
abort();
5458
}

‎src/interfaces/ecpg/include/decimal.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22

33
#ifndefdec_t
44
#definedec_t NumericVar
5+
6+
#defineCSHORTTYPE 0
7+
#defineCMONEYTYPE 0
8+
#defineCCHARTYPE 0
9+
#defineCDECIMALTYPE 0
10+
#defineCINTTYPE 0
11+
#defineCDATETYPE 0
12+
#defineCDOUBLETYPE 0
13+
#defineCLONGTYPE 0
14+
515
#endif/* dec_t */

‎src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 3 additions & 1 deletion
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 */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndefPGTYPES_DATETIME
2+
#definePGTYPES_DATETIME
3+
4+
#defineDate long
5+
6+
externDatePGTYPESdate_atod(char*,char**);
7+
externchar*PGTYPESdate_dtoa(Date);
8+
externintPGTYPESdate_julmdy(Date,int*);
9+
externintPGTYPESdate_mdyjul(int*,Date*);
10+
externintPGTYPESdate_day(Date);
11+
12+
#endif/* PGTYPES_DATETIME */

‎src/interfaces/ecpg/include/pgtypes_error.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
#definePGTYPES_BAD_NUMERIC202
33
#definePGTYPES_DIVIDE_ZERO203
44

5-
#definePGTYPES_BAD_DATE300
5+
#definePGTYPES_BAD_DATE210
6+
7+
#definePGTYPES_BAD_TIMESTAMP220
68

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndefPGTYPES_TIMESTAMP
2+
#definePGTYPES_TIMESTAMP
3+
4+
#ifdefHAVE_INT64_TIMESTAMP
5+
typedefint64Timestamp;
6+
typedefint64TimestampTz;
7+
8+
#else
9+
typedefdoubleTimestamp;
10+
typedefdoubleTimestampTz;
11+
#endif
12+
13+
externTimestampPGTYPEStimestamp_atot(char*,char**);
14+
externchar*PGTYPEStimestamp_ttoa(Timestamp);
15+
16+
#endif/* PGTYPES_TIMESTAMP */

‎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.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
overrideCPPFLAGS := -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

Lines changed: 29 additions & 0 deletions
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(longsize)
7+
{
8+
char*new= (char*)calloc(1L,size);
9+
10+
if (!new)
11+
{
12+
errno=ENOMEM;
13+
returnNULL;
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)

[8]ページ先頭

©2009-2025 Movatter.jp