From c7fddd30726e314b037d8b788de561f8dbe14e0d Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Fri, 4 Jul 2003 12:00:52 +0000 Subject: [PATCH] date, interval and timestamp data should be quoted. --- src/interfaces/ecpg/ChangeLog | 4 ++++ src/interfaces/ecpg/ecpglib/execute.c | 14 +++++++------- src/interfaces/ecpg/pgtypeslib/datetime.c | 2 +- src/interfaces/ecpg/test/dt_test.pgc | 10 ++++++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index fff7d1301a..2fc29e7537 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1546,6 +1546,10 @@ Wed Jul 2 09:45:59 CEST 2003 - Fixed initialization bug in compatlib. - Added postgres_fe.h to all files in pgtypeslib. + +Fri Jul 4 13:51:11 CEST 2003 + + - date, interval and timestamp data should be quoted. - Set ecpg version to 3.0.0 - Set ecpg library to 4.0.0 - Set pgtypes library to 1.0.0 diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 87d528533d..ec6be71fa7 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.15 2003/07/04 11:30:48 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.16 2003/07/04 12:00:52 meskes Exp $ */ /* * The aim is to get a simpler inteface to the database routines. @@ -885,7 +885,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, { for (element = 0; element < var->arrsize; element++) { - str = PGTYPESinterval_to_asc((Interval *)((var + var->offset * element)->value)); + str = quote_postgres(PGTYPESinterval_to_asc((Interval *)((var + var->offset * element)->value)), stmt->lineno); slen = strlen (str); if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno))) @@ -901,7 +901,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, } else { - str = PGTYPESinterval_to_asc((Interval *)(var->value)); + str = quote_postgres(PGTYPESinterval_to_asc((Interval *)(var->value)), stmt->lineno); slen = strlen (str); if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno))) @@ -926,7 +926,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, { for (element = 0; element < var->arrsize; element++) { - str = PGTYPESdate_to_asc(*(Date *)((var + var->offset * element)->value)); + str = quote_postgres(PGTYPESdate_to_asc(*(Date *)((var + var->offset * element)->value)), stmt->lineno); slen = strlen (str); if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno))) @@ -942,7 +942,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, } else { - str = PGTYPESdate_to_asc(*(Date *)(var->value)); + str = quote_postgres(PGTYPESdate_to_asc(*(Date *)(var->value)), stmt->lineno); slen = strlen (str); if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno))) @@ -967,7 +967,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, { for (element = 0; element < var->arrsize; element++) { - str = PGTYPEStimestamp_to_asc(*(Timestamp *)((var + var->offset * element)->value)); + str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *)((var + var->offset * element)->value)), stmt->lineno); slen = strlen (str); if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno))) @@ -983,7 +983,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, } else { - str = PGTYPEStimestamp_to_asc(*(Timestamp *)(var->value)); + str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *)(var->value)), stmt->lineno); slen = strlen (str); if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno))) diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c index 9811571afc..d9ca870873 100644 --- a/src/interfaces/ecpg/pgtypeslib/datetime.c +++ b/src/interfaces/ecpg/pgtypeslib/datetime.c @@ -87,7 +87,7 @@ PGTYPESdate_to_asc(Date dDate) { struct tm tt, *tm = &tt; char buf[MAXDATELEN + 1]; - int DateStyle=0; + int DateStyle=1; bool EuroDates = FALSE; j2date((dDate + date2j(2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday)); diff --git a/src/interfaces/ecpg/test/dt_test.pgc b/src/interfaces/ecpg/test/dt_test.pgc index a5eb7cce9b..515ea35aac 100644 --- a/src/interfaces/ecpg/test/dt_test.pgc +++ b/src/interfaces/ecpg/test/dt_test.pgc @@ -17,6 +17,8 @@ main() Date date2; int mdy[3] = { 4, 19, 1998 }; char *fmt, *out, *in; + char *d1 = "Mon Jan 17 1966"; + char *t1 = "2000-7-12 17:34:29"; FILE *dbgs; @@ -25,8 +27,12 @@ main() exec sql whenever sqlerror do sqlprint(); exec sql connect to mm; exec sql create table date_test (d date, ts timestamp, iv interval); + exec sql set datestyle to iso; - exec sql insert into date_test(d, ts, iv) values ('Mon Jan 17 1966', '2000-7-12 17:34:29', now()-'Mon Jan 17 1966'); + date1 = PGTYPESdate_from_asc(d1, NULL); + ts1 = PGTYPEStimestamp_from_asc(t1, NULL); + + exec sql insert into date_test(d, ts, iv) values (:date1, :ts1, now()-'Mon Jan 17 1966'); exec sql select * into :date1, :ts1 , :iv1 from date_test; @@ -38,7 +44,7 @@ main() text = PGTYPESinterval_to_asc(&iv1); printf ("interval: %s\n", text); - + PGTYPESdate_mdyjul(mdy, &date2); printf("m: %d, d: %d, y: %d\n", mdy[0], mdy[1], mdy[2]); /* reset */