OSDN Git Service

date, interval and timestamp data should be quoted.
authorMichael Meskes <meskes@postgresql.org>
Fri, 4 Jul 2003 12:00:52 +0000 (12:00 +0000)
committerMichael Meskes <meskes@postgresql.org>
Fri, 4 Jul 2003 12:00:52 +0000 (12:00 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/pgtypeslib/datetime.c
src/interfaces/ecpg/test/dt_test.pgc

index fff7d13..2fc29e7 100644 (file)
@@ -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
index 87d5285..ec6be71 100644 (file)
@@ -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)))
index 9811571..d9ca870 100644 (file)
@@ -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));
index a5eb7cc..515ea35 100644 (file)
@@ -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 */