Changeset: dda75e11c0ab for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dda75e11c0ab
Modified Files:
        clients/Tests/MAL-signatures_all.stable.out
        clients/Tests/MAL-signatures_all.stable.out.int128
        clients/Tests/exports.stable.out
        monetdb5/modules/atoms/mtime.c
        monetdb5/modules/atoms/mtime.h
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_bat2time.c
        sql/backends/monet5/sql_gencode.c
Branch: default
Log Message:

add error reporing when converting strings to time(stamp)s with time zone


diffs (truncated from 379 to 300 lines):

diff --git a/clients/Tests/MAL-signatures_all.stable.out 
b/clients/Tests/MAL-signatures_all.stable.out
--- a/clients/Tests/MAL-signatures_all.stable.out
+++ b/clients/Tests/MAL-signatures_all.stable.out
@@ -22924,6 +22924,10 @@ command batcalc.daytime(v:bat[:oid,:dayt
 address batdaytime_2time_daytime;
 comment cast daytime to daytime and check for overflow
 
+command 
batcalc.daytime(v:bat[:oid,:str],digits:int,has_tz:int):bat[:oid,:daytime] 
+address batstr_2time_daytimetz;
+comment cast to daytime and check for overflow
+
 command batcalc.daytime(v:bat[:oid,:str],digits:int):bat[:oid,:daytime] 
 address batstr_2time_daytime;
 comment cast to daytime and check for overflow
@@ -30712,6 +30716,10 @@ command batcalc.timestamp(v:bat[:oid,:ti
 address battimestamp_2time_timestamp;
 comment cast timestamp to timestamp and check for overflow
 
+command 
batcalc.timestamp(v:bat[:oid,:str],digits:int,has_tz:int):bat[:oid,:timestamp] 
+address batstr_2time_timestamptz;
+comment cast to timestamp and check for overflow
+
 command batcalc.timestamp(v:bat[:oid,:str],digits:int):bat[:oid,:timestamp] 
 address batstr_2time_timestamp;
 comment cast to timestamp and check for overflow
@@ -35355,6 +35363,10 @@ command calc.daytime(v:daytime,digits:in
 address daytime_2time_daytime;
 comment cast daytime to daytime and check for overflow
 
+command calc.daytime(v:str,digits:int,has_tz:int):daytime 
+address str_2time_daytimetz;
+comment cast to daytime and check for overflow
+
 command calc.daytime(v:str,digits:int):daytime 
 address str_2time_daytime;
 comment cast to daytime and check for overflow
@@ -37318,6 +37330,10 @@ command calc.timestamp(v:timestamp,digit
 address timestamp_2time_timestamp;
 comment cast timestamp to timestamp and check for overflow
 
+command calc.timestamp(v:str,digits:int,has_tz:int):timestamp 
+address str_2time_timestamptz;
+comment cast to timestamp and check for overflow
+
 command calc.timestamp(v:str,digits:int):timestamp 
 address str_2time_timestamp;
 comment cast to timestamp and check for overflow
diff --git a/clients/Tests/MAL-signatures_all.stable.out.int128 
b/clients/Tests/MAL-signatures_all.stable.out.int128
--- a/clients/Tests/MAL-signatures_all.stable.out.int128
+++ b/clients/Tests/MAL-signatures_all.stable.out.int128
@@ -29463,6 +29463,10 @@ command batcalc.daytime(v:bat[:oid,:dayt
 address batdaytime_2time_daytime;
 comment cast daytime to daytime and check for overflow
 
+command 
batcalc.daytime(v:bat[:oid,:str],digits:int,has_tz:int):bat[:oid,:daytime] 
+address batstr_2time_daytimetz;
+comment cast to daytime and check for overflow
+
 command batcalc.daytime(v:bat[:oid,:str],digits:int):bat[:oid,:daytime] 
 address batstr_2time_daytime;
 comment cast to daytime and check for overflow
@@ -39701,6 +39705,10 @@ command batcalc.timestamp(v:bat[:oid,:ti
 address battimestamp_2time_timestamp;
 comment cast timestamp to timestamp and check for overflow
 
+command 
batcalc.timestamp(v:bat[:oid,:str],digits:int,has_tz:int):bat[:oid,:timestamp] 
+address batstr_2time_timestamptz;
+comment cast to timestamp and check for overflow
+
 command batcalc.timestamp(v:bat[:oid,:str],digits:int):bat[:oid,:timestamp] 
 address batstr_2time_timestamp;
 comment cast to timestamp and check for overflow
@@ -45632,6 +45640,10 @@ command calc.daytime(v:daytime,digits:in
 address daytime_2time_daytime;
 comment cast daytime to daytime and check for overflow
 
+command calc.daytime(v:str,digits:int,has_tz:int):daytime 
+address str_2time_daytimetz;
+comment cast to daytime and check for overflow
+
 command calc.daytime(v:str,digits:int):daytime 
 address str_2time_daytime;
 comment cast to daytime and check for overflow
@@ -48173,6 +48185,10 @@ command calc.timestamp(v:timestamp,digit
 address timestamp_2time_timestamp;
 comment cast timestamp to timestamp and check for overflow
 
+command calc.timestamp(v:str,digits:int,has_tz:int):timestamp 
+address str_2time_timestamptz;
+comment cast to timestamp and check for overflow
+
 command calc.timestamp(v:str,digits:int):timestamp 
 address str_2time_timestamp;
 comment cast to timestamp and check for overflow
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -2711,6 +2711,7 @@ str timestampRef;
 int timestamp_fromstr(const char *buf, int *len, timestamp **ret);
 timestamp *timestamp_nil;
 int timestamp_tostr(str *buf, int *len, const timestamp *val);
+int timestamp_tz_fromstr(const char *buf, int *len, timestamp **ret);
 int timestamp_tz_tostr(str *buf, int *len, const timestamp *val, const tzone 
*timezone);
 str tinterRef;
 str tintersectRef;
diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -810,6 +810,41 @@ timestamp_fromstr(const char *buf, int *
 }
 
 int
+timestamp_tz_fromstr(const char *buf, int *len, timestamp **ret)
+{
+       const char *s = buf;
+       int pos = timestamp_fromstr(s, len, ret);
+       lng offset = 0;
+
+       if (!*ret || *ret == timestamp_nil)
+               return pos;
+
+       s = buf + pos;
+       pos = 0;
+       while (GDKisspace(*s))
+               s++;
+       /* incase of gmt we need to add the time zone */
+       if (fleximatch(s, "gmt", 0) == 3) {
+               s += 3;
+       }
+       if ((s[0] == '-' || s[0] == '+') &&
+               GDKisdigit(s[1]) && GDKisdigit(s[2]) && GDKisdigit(s[pos = 4]) 
&&
+               ((s[3] == ':' && GDKisdigit(s[5])) || GDKisdigit(s[pos = 3]))) {
+               offset = (((s[1] - '0') * (lng) 10 + (s[2] - '0')) * (lng) 60 + 
(s[pos] - '0') * (lng) 10 + (s[pos + 1] - '0')) * (lng) 60000;
+               pos += 2;
+               if (s[0] != '-')
+                       offset = -offset;
+               s += pos;
+       } else {
+               /* if no tzone is specified; work with the local */
+               offset = get_offset(&tzone_local) * (lng) -60000;
+       }
+       MTIMEtimestamp_add(*ret, *ret, &offset);
+       return (int) (s - buf);
+}
+
+
+int
 timestamp_tz_tostr(str *buf, int *len, const timestamp *val, const tzone 
*timezone)
 {
        int len1, len2, big = 128;
diff --git a/monetdb5/modules/atoms/mtime.h b/monetdb5/modules/atoms/mtime.h
--- a/monetdb5/modules/atoms/mtime.h
+++ b/monetdb5/modules/atoms/mtime.h
@@ -114,6 +114,7 @@ mtime_export timestamp *timestamp_nil;
 #define ts_isnil(t)   ((t).days == timestamp_nil->days && (t).msecs == 
timestamp_nil->msecs)
 
 mtime_export int daytime_tz_fromstr(const char *buf, int *len, daytime **ret);
+mtime_export int timestamp_tz_fromstr(const char *buf, int *len, timestamp 
**ret);
 mtime_export str MTIMEcurrent_timestamp(timestamp *t);
 mtime_export str MTIMEcurrent_date(date *d);
 mtime_export str MTIMEcurrent_time(daytime *t);
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3313,7 +3313,7 @@ nil_2time_daytime(daytime *res, const vo
 }
 
 str
-str_2time_daytime(daytime *res, const str *v, const int *digits)
+str_2time_daytimetz(daytime *res, const str *v, const int *digits, int *tz)
 {
        int len = sizeof(daytime), pos;
 
@@ -3321,13 +3321,23 @@ str_2time_daytime(daytime *res, const st
                *res = daytime_nil;
                return MAL_SUCCEED;
        }
-       pos = daytime_fromstr(*v, &len, &res);
-       if (!pos)
+       if (*tz)
+               pos = daytime_tz_fromstr(*v, &len, &res);
+       else
+               pos = daytime_fromstr(*v, &len, &res);
+       if (!pos || pos < (int)strlen(*v))
                throw(SQL, "daytime", "22007!daytime (%s) has incorrect 
format", *v);
        return daytime_2time_daytime(res, res, digits);
 }
 
 str
+str_2time_daytime(daytime *res, const str *v, const int *digits)
+{
+       int zero = 0;
+       return str_2time_daytimetz(res, v, digits, &zero);
+}
+
+str
 timestamp_2_daytime(daytime *res, const timestamp *v, const int *digits)
 {
        int d = (*digits) ? *digits - 1 : 0;
@@ -3379,7 +3389,7 @@ nil_2time_timestamp(timestamp *res, cons
 }
 
 str
-str_2time_timestamp(timestamp *res, const str *v, const int *digits)
+str_2time_timestamptz(timestamp *res, const str *v, const int *digits, int *tz)
 {
        int len = sizeof(timestamp), pos;
 
@@ -3387,13 +3397,23 @@ str_2time_timestamp(timestamp *res, cons
                *res = *timestamp_nil;
                return MAL_SUCCEED;
        }
-       pos = timestamp_fromstr(*v, &len, &res);
-       if (!pos)
+       if (*tz)
+               pos = timestamp_tz_fromstr(*v, &len, &res);
+       else
+               pos = timestamp_fromstr(*v, &len, &res);
+       if (!pos || pos < (int)strlen(*v))
                throw(SQL, "timestamp", "22007!timestamp (%s) has incorrect 
format", *v);
        return timestamp_2time_timestamp(res, res, digits);
 }
 
 str
+str_2time_timestamp(timestamp *res, const str *v, const int *digits)
+{
+       int zero = 0;
+       return str_2time_timestamptz(res, v, digits, &zero);
+}
+
+str
 SQLcst_alpha_cst(dbl *res, const dbl *decl, const dbl *theta)
 {
        dbl s, c1, c2;
diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h
--- a/sql/backends/monet5/sql.h
+++ b/sql/backends/monet5/sql.h
@@ -245,14 +245,18 @@ sql5_export str batnil_2num_hge(bat *res
 sql5_export str nil_2time_timestamp(timestamp *res, const void *v, const int 
*len);
 sql5_export str batnil_2time_timestamp(bat *res, const bat *v, const int *len);
 sql5_export str str_2time_timestamp(timestamp *res, const str *v, const int 
*len);
+sql5_export str str_2time_timestamptz(timestamp *res, const str *v, const int 
*len, int *tz);
 sql5_export str batstr_2time_timestamp(bat *res, const bat *v, const int *len);
+sql5_export str batstr_2time_timestamptz(bat *res, const bat *v, const int 
*len, int *tz);
 sql5_export str timestamp_2time_timestamp(timestamp *res, const timestamp *v, 
const int *len);
 sql5_export str battimestamp_2time_timestamp(bat *res, const bat *v, const int 
*len);
 
 sql5_export str nil_2time_daytime(daytime *res, const void *v, const int *len);
 sql5_export str batnil_2time_daytime(bat *res, const bat *v, const int *len);
 sql5_export str str_2time_daytime(daytime *res, const str *v, const int *len);
+sql5_export str str_2time_daytimetz(daytime *res, const str *v, const int 
*len, int *tz);
 sql5_export str batstr_2time_daytime(bat *res, const bat *v, const int *len);
+sql5_export str batstr_2time_daytimetz(bat *res, const bat *v, const int *len, 
int *tz);
 sql5_export str daytime_2time_daytime(daytime *res, const daytime *v, const 
int *len);
 sql5_export str batdaytime_2time_daytime(bat *res, const bat *v, const int 
*len);
 
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -854,6 +854,9 @@ comment "Cast to timestamp";
 command calc.timestamp( v:str, digits:int ) :timestamp 
 address str_2time_timestamp
 comment "cast to timestamp and check for overflow";
+command calc.timestamp( v:str, digits:int, has_tz:int ) :timestamp 
+address str_2time_timestamptz
+comment "cast to timestamp and check for overflow";
 command calc.timestamp( v:timestamp, digits:int ) :timestamp 
 address timestamp_2time_timestamp
 comment "cast timestamp to timestamp and check for overflow";
@@ -864,6 +867,9 @@ comment "Cast to timestamp";
 command batcalc.timestamp( v:bat[:oid,:str], digits:int ) 
:bat[:oid,:timestamp] 
 address batstr_2time_timestamp
 comment "cast to timestamp and check for overflow";
+command batcalc.timestamp( v:bat[:oid,:str], digits:int, has_tz:int ) 
:bat[:oid,:timestamp] 
+address batstr_2time_timestamptz
+comment "cast to timestamp and check for overflow";
 command batcalc.timestamp( v:bat[:oid,:timestamp], digits:int ) 
:bat[:oid,:timestamp] 
 address battimestamp_2time_timestamp
 comment "cast timestamp to timestamp and check for overflow";
@@ -888,6 +894,9 @@ comment "Cast to daytime";
 command calc.daytime( v:str, digits:int ) :daytime 
 address str_2time_daytime
 comment "cast to daytime and check for overflow";
+command calc.daytime( v:str, digits:int, has_tz:int ) :daytime 
+address str_2time_daytimetz
+comment "cast to daytime and check for overflow";
 command calc.daytime( v:daytime, digits:int ) :daytime 
 address daytime_2time_daytime
 comment "cast daytime to daytime and check for overflow";
@@ -898,6 +907,9 @@ comment "Cast to daytime";
 command batcalc.daytime( v:bat[:oid,:str], digits:int ) :bat[:oid,:daytime] 
 address batstr_2time_daytime
 comment "cast to daytime and check for overflow";
+command batcalc.daytime( v:bat[:oid,:str], digits:int, has_tz:int ) 
:bat[:oid,:daytime] 
+address batstr_2time_daytimetz
+comment "cast to daytime and check for overflow";
 command batcalc.daytime( v:bat[:oid,:daytime], digits:int ) 
:bat[:oid,:daytime] 
 address batdaytime_2time_daytime
 comment "cast daytime to daytime and check for overflow";
diff --git a/sql/backends/monet5/sql_bat2time.c 
b/sql/backends/monet5/sql_bat2time.c
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to