Added missing constuctor/destructor for interval and date.
authorMichael Meskes <meskes@postgresql.org>
Thu, 14 Sep 2006 08:02:38 +0000 (08:02 +0000)
committerMichael Meskes <meskes@postgresql.org>
Thu, 14 Sep 2006 08:02:38 +0000 (08:02 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/include/pgtypes_date.h
src/interfaces/ecpg/include/pgtypes_interval.h
src/interfaces/ecpg/pgtypeslib/datetime.c
src/interfaces/ecpg/pgtypeslib/interval.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.stdout
src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc

index 6f698f4cbd8816cbac04ac3287b0e955391a37fd..5e4524e791a429a7fb8ab5fb26e8d135296a6be1 100644 (file)
@@ -2144,5 +2144,10 @@ Tu 5. Sep 11:49:08 CEST 2006
        - Fixed port number setting in regression suite.
        - Added some interval checks to regression suite.
        - Started to cleanup complex tests.
+
+Th 14. Sep 09:47:03 CEST 2006
+
+       - Completely removed complex tests.
+       - Added missing constuctor/destructor for interval and date.
        - Set ecpg library version to 5.2.
        - Set ecpg version to 4.2.1.
index a9c670b31ad8552bfecaf4f6bb4a2c46cb748440..de65af023c53ac61e96edb15b6b57dae1f758da1 100644 (file)
@@ -12,6 +12,8 @@ extern                "C"
 {
 #endif
 
+extern date *PGTYPESdate_new(void);
+extern void  PGTYPESdate_free(date *);
 extern date PGTYPESdate_from_asc(char *, char **);
 extern char *PGTYPESdate_to_asc(date);
 extern date PGTYPESdate_from_timestamp(timestamp);
index 9f66b77bf13f3f5b819bc5c42262c40aa79a2711..092706b80baaaf3a68f3c434ef27b19c0804d91d 100644 (file)
@@ -49,6 +49,8 @@ extern                "C"
 {
 #endif
 
+extern interval *PGTYPESinterval_new(void);
+extern void PGTYPESinterval_free(interval *);
 extern interval *PGTYPESinterval_from_asc(char *, char **);
 extern char *PGTYPESinterval_to_asc(interval *);
 extern int     PGTYPESinterval_copy(interval *, interval *);
index ae2207161fa4db14b8ad2b716ef4456d90b9cad1..01ad6b77aa9ea302db1aed9353d378a5965452d4 100644 (file)
 #include "pgtypes_error.h"
 #include "pgtypes_date.h"
 
+date *
+PGTYPESdate_new(void)
+{
+       date *result;
+       result = (date *) pgtypes_alloc(sizeof(date));
+       /* result can be NULL if we run out of memory */
+       return result;
+}
+
+void
+PGTYPESdate_free(date *d)
+{
+       free(d);
+}
+
 date
 PGTYPESdate_from_timestamp(timestamp dt)
 {
index 2ef8b7fcab0de8a5bfce8f071241e4e60e654531..1685f7c7bdb5f6c6db2fb9dc91b625ff88f26aa7 100644 (file)
@@ -753,6 +753,21 @@ tm2interval(struct tm * tm, fsec_t fsec, interval * span)
        return 0;
 }      /* tm2interval() */
 
+interval *
+PGTYPESinterval_new(void)
+{
+       interval *result;
+       result = (interval *) pgtypes_alloc(sizeof(interval));
+       /* result can be NULL if we run out of memory */
+       return result;
+}
+
+void
+PGTYPESinterval_free(interval *intvl)
+{
+       free(intvl);
+}
+
 interval *
 PGTYPESinterval_from_asc(char *str, char **endptr)
 {
index c92f354ec4585f1a6192ba000a8f721881e544dd..e5388b6fa8da5cc4044dced3978f9e0b47c2da42 100644 (file)
@@ -70,6 +70,7 @@ main(void)
                  
                 
                 
+                
        
 #line 51 "dt_test2.pgc"
  date  date1    ;
@@ -82,8 +83,11 @@ main(void)
  
 #line 54 "dt_test2.pgc"
  interval * i1    ;
-/* exec sql end declare section */
 #line 55 "dt_test2.pgc"
+ date * dc    ;
+/* exec sql end declare section */
+#line 56 "dt_test2.pgc"
 
 
        int i, j;
@@ -98,9 +102,12 @@ main(void)
        free(text);
 
        date1 = PGTYPESdate_from_timestamp(ts1);
-       text = PGTYPESdate_to_asc(date1);
+       dc = PGTYPESdate_new();
+       *dc = date1;
+       text = PGTYPESdate_to_asc(*dc);
        printf("Date of timestamp: %s\n", text);
        free(text);
+       PGTYPESdate_free(dc);
 
        for (i = 0; dates[i]; i++)
        {
@@ -139,6 +146,7 @@ main(void)
 
        for (i = 0; intervals[i]; i++)
        {
+               interval *ic;
                i1 = PGTYPESinterval_from_asc(intervals[i], &endptr);
                if (*endptr)
                        printf("endptr set to %s\n", endptr);
@@ -153,6 +161,13 @@ main(void)
                text = PGTYPESinterval_to_asc(i1);
                printf("interval[%d]: %s\n", i, text ? text : "-");
                free(text);
+
+               ic = PGTYPESinterval_new();
+               PGTYPESinterval_copy(i1, ic);
+               text = PGTYPESinterval_to_asc(i1);
+               printf("interval_copy[%d]: %s\n", i, text ? text : "-");
+               free(text);
+               PGTYPESinterval_free(ic);
        }
 
        return (0);
index 1a40893aed7c28efbbf3afd0b2aa23f7e2214c26..24e9d26dfeb7744e88e52cf1508b12df3e734828 100644 (file)
@@ -88,9 +88,15 @@ TS[19,0]: 0099-01-08 00:04:00 BC
 TS[19,1]: 0099-01-08 01:59:00 BC
 TS[19,2]: 0099-01-08 13:24:40 BC
 interval[0]: @ 1 min
+interval_copy[0]: @ 1 min
 interval[1]: @ 1 day 12 hours 59 mins 10 secs
+interval_copy[1]: @ 1 day 12 hours 59 mins 10 secs
 interval[2]: @ 2 days 12 hours 59 mins 10 secs
+interval_copy[2]: @ 2 days 12 hours 59 mins 10 secs
 interval[3]: @ 1 day 12 hours 59 mins 10 secs
+interval_copy[3]: @ 1 day 12 hours 59 mins 10 secs
 interval[4]: @ 1 day 1 hour 1 min 1 sec
+interval_copy[4]: @ 1 day 1 hour 1 min 1 sec
 interval[5]: @ 1 year 59 mins
+interval_copy[5]: @ 1 year 59 mins
 Error parsing interval 6
index 09a95f7aba9a5f2a02a833c87d72b01061a0ba69..08d1d6c412f53706724178277d12db3443e739be 100644 (file)
@@ -52,6 +52,7 @@ main(void)
                timestamp ts1, ts2;
                char *text;
                interval *i1;
+               date *dc;
        exec sql end declare section;
 
        int i, j;
@@ -66,9 +67,12 @@ main(void)
        free(text);
 
        date1 = PGTYPESdate_from_timestamp(ts1);
-       text = PGTYPESdate_to_asc(date1);
+       dc = PGTYPESdate_new();
+       *dc = date1;
+       text = PGTYPESdate_to_asc(*dc);
        printf("Date of timestamp: %s\n", text);
        free(text);
+       PGTYPESdate_free(dc);
 
        for (i = 0; dates[i]; i++)
        {
@@ -107,6 +111,7 @@ main(void)
 
        for (i = 0; intervals[i]; i++)
        {
+               interval *ic;
                i1 = PGTYPESinterval_from_asc(intervals[i], &endptr);
                if (*endptr)
                        printf("endptr set to %s\n", endptr);
@@ -121,6 +126,13 @@ main(void)
                text = PGTYPESinterval_to_asc(i1);
                printf("interval[%d]: %s\n", i, text ? text : "-");
                free(text);
+
+               ic = PGTYPESinterval_new();
+               PGTYPESinterval_copy(i1, ic);
+               text = PGTYPESinterval_to_asc(i1);
+               printf("interval_copy[%d]: %s\n", i, text ? text : "-");
+               free(text);
+               PGTYPESinterval_free(ic);
        }
 
        return (0);