Changeset: 2d9beef3e6f5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2d9beef3e6f5
Modified Files:
        monetdb5/modules/atoms/mtime.mx
        sql/backends/monet5/sql.mx
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_result.mx
        sql/common/sql_types.c
        sql/common/sql_types.h
        sql/server/rel_select.c
        sql/server/sql_datetime.c
        sql/server/sql_datetime.h
        sql/server/sql_env.c
        sql/server/sql_parser.y
        
sql/test/BugDay_2005-11-09_2.9.3/Tests/interval_on_time_stamp.SF-1080488.stable.out
        
sql/test/BugDay_2005-12-19_2.9.3/Tests/cast_interval.SF.1280682.stable.out
        
sql/test/BugDay_2005-12-19_2.9.3/Tests/interval_times_int.SF-1281996.stable.out
        sql/test/BugTracker-2010/Tests/between-timestamp.Bug-2718.stable.out
        sql/test/BugTracker/Tests/cast_interval2time.SF-1488247.stable.out
        
sql/test/BugTracker/Tests/inserting_invalid_timestamp.SF-1363557.stable.err
        sql/test/Dump/Tests/dump.stable.out
        sql/test/bugs/Tests/interval_convert_bugs-sf-1274077-1274085.stable.out
Branch: Aug2011
Log Message:

changes/fixes
        interval seconds now stores milli - seconds
        handle sub-second fractions

TIME, TIMESTAMP and INTERVAL (second) have time precision
time defaults to 0 (ie not smaller than seconds)
timestamp and interval default to 6 but monet only supports 3 (ie allways
3 zero's at the end)

fixes bug 2873 and old feature request 2415


diffs (truncated from 999 to 300 lines):

diff --git a/monetdb5/modules/atoms/mtime.mx b/monetdb5/modules/atoms/mtime.mx
--- a/monetdb5/modules/atoms/mtime.mx
+++ b/monetdb5/modules/atoms/mtime.mx
@@ -417,19 +417,19 @@ module mtime;
 command date_sub_sec_interval(t:date,s:int):date 
 address MTIMEdate_sub_sec_interval_wrap
 comment "Subtract seconds from a date";
-command date_sub_sec_interval(t:date,s:lng):date 
-address MTIMEdate_sub_sec_interval_lng_wrap;
+command date_sub_msec_interval(t:date,ms:lng):date 
+address MTIMEdate_sub_msec_interval_lng_wrap;
 
 command date_add_sec_interval(t:date,s:int):date 
 address MTIMEdate_add_sec_interval_wrap
 comment "Add seconds to a date";
-command date_add_sec_interval(t:date,s:lng):date 
-address MTIMEdate_add_sec_interval_lng_wrap;
-
-command timestamp_sub_sec_interval(t:timestamp,s:lng):timestamp 
-address MTIMEtimestamp_sub_sec_interval_lng_wrap;
-command timestamp_add_sec_interval(t:timestamp,s:lng):timestamp 
-address MTIMEtimestamp_add_sec_interval_lng_wrap;
+command date_add_msec_interval(t:date,ms:lng):date 
+address MTIMEdate_add_msec_interval_lng_wrap;
+
+command timestamp_sub_msec_interval(t:timestamp,ms:lng):timestamp 
+address MTIMEtimestamp_sub_msec_interval_lng_wrap;
+command timestamp_add_msec_interval(t:timestamp,ms:lng):timestamp 
+address MTIMEtimestamp_add_msec_interval_lng_wrap;
 
 command timestamp_sub_month_interval(t:timestamp,s:int):timestamp 
 address MTIMEtimestamp_sub_month_interval_wrap
@@ -440,11 +440,11 @@ comment "Add months to a timestamp";
 command timestamp(t:timestamp):timestamp
 address MTIMEtimestamp2timestamp;
 
-command time_sub_sec_interval(t:daytime,s:lng):daytime 
-address MTIMEtime_sub_sec_interval_wrap
+command time_sub_msec_interval(t:daytime,ms:lng):daytime 
+address MTIMEtime_sub_msec_interval_wrap
 comment "Subtract seconds from a time";
-command time_add_sec_interval(t:daytime,s:lng):daytime 
-address MTIMEtime_add_sec_interval_wrap
+command time_add_msec_interval(t:daytime,ms:lng):daytime 
+address MTIMEtime_add_msec_interval_wrap
 comment "Add seconds to a time";
 
 command date_add_month_interval(t:date,s:int):date 
@@ -774,13 +774,13 @@ command year(months:int):int
 address MTIMEsql_year;
 command month(months:int):int
 address MTIMEsql_month;
-command day(secs:lng):lng
+command day(msecs:lng):lng
 address MTIMEsql_day;
-command hours(secs:lng):int
+command hours(msecs:lng):int
 address MTIMEsql_hours;
-command minutes(secs:lng):int
+command minutes(msecs:lng):int
 address MTIMEsql_minutes;
-command seconds(secs:lng):int
+command seconds(msecs:lng):int
 address MTIMEsql_seconds;
 
 command msec{unsafe}():lng 
@@ -1044,16 +1044,16 @@ mtime_export str MTIMEtzone_extract_star
 mtime_export str MTIMEtzone_extract_end(rule *ret, tzone *t);
 mtime_export str MTIMEtzone_extract_minutes(int *ret, tzone *t);
 mtime_export str MTIMEdate_sub_sec_interval_wrap(date *ret, date *t, int *sec);
-mtime_export str MTIMEdate_sub_sec_interval_lng_wrap(date *ret, date *t, lng 
*sec);
+mtime_export str MTIMEdate_sub_msec_interval_lng_wrap(date *ret, date *t, lng 
*msec);
 mtime_export str MTIMEdate_add_sec_interval_wrap(date *ret, date *t, int *sec);
-mtime_export str MTIMEdate_add_sec_interval_lng_wrap(date *ret, date *t, lng 
*sec);
+mtime_export str MTIMEdate_add_msec_interval_lng_wrap(date *ret, date *t, lng 
*msec);
 mtime_export str MTIMEdate_add_month_interval_wrap(date *ret, date *t, int 
*months);
-mtime_export str MTIMEtimestamp_add_sec_interval_lng_wrap(timestamp *ret, 
timestamp *t, lng *sec);
-mtime_export str MTIMEtimestamp_sub_sec_interval_lng_wrap(timestamp *ret, 
timestamp *t, lng *sec);
+mtime_export str MTIMEtimestamp_add_msec_interval_lng_wrap(timestamp *ret, 
timestamp *t, lng *msec);
+mtime_export str MTIMEtimestamp_sub_msec_interval_lng_wrap(timestamp *ret, 
timestamp *t, lng *msec);
 mtime_export str MTIMEtimestamp_sub_month_interval_wrap(timestamp *ret, 
timestamp *t, int *months);
 mtime_export str MTIMEtimestamp_add_month_interval_wrap(timestamp *ret, 
timestamp *t, int *months);
-mtime_export str MTIMEtime_sub_sec_interval_wrap(daytime *ret, daytime *t, lng 
*sec);
-mtime_export str MTIMEtime_add_sec_interval_wrap(daytime *ret, daytime *t, lng 
*sec);
+mtime_export str MTIMEtime_sub_msec_interval_wrap(daytime *ret, daytime *t, 
lng *msec);
+mtime_export str MTIMEtime_add_msec_interval_wrap(daytime *ret, daytime *t, 
lng *msec);
 mtime_export str MTIMEcompute_rule_foryear(date *ret, rule *val, int *year);
 mtime_export str MTIMEtzone_tostr(str *s, tzone *ret);
 mtime_export str MTIMEtzone_fromstr(tzone *ret, str *s);
@@ -2663,10 +2663,10 @@ date_sub_sec_interval_wrap(date *ret, da
        return GDK_SUCCEED;
 }
 static inline int
-date_sub_sec_interval_lng_wrap(date *ret, date *t, lng *sec)
+date_sub_msec_interval_lng_wrap(date *ret, date *t, lng *msec)
 {
-       if (*sec > 0) {
-               int delta = (int) -(*sec / 86400);
+       if (*msec > 0) {
+               int delta = (int) -(*msec / 86400000);
 
                return date_adddays(ret, t, &delta);
        }
@@ -2686,10 +2686,10 @@ date_add_sec_interval_wrap(date *ret, da
        return GDK_SUCCEED;
 }
 static inline int
-date_add_sec_interval_lng_wrap(date *ret, date *t, lng *sec)
+date_add_msec_interval_lng_wrap(date *ret, date *t, lng *msec)
 {
-       if (*sec > 0) {
-               int delta = (int) (*sec / 86400);
+       if (*msec > 0) {
+               int delta = (int) (*msec / 86400000);
 
                return date_adddays(ret, t, &delta);
        }
@@ -3628,9 +3628,9 @@ MTIMEdate_sub_sec_interval_wrap(date *re
        return MAL_SUCCEED;
 }
 str
-MTIMEdate_sub_sec_interval_lng_wrap(date *ret, date *t, lng *sec)
+MTIMEdate_sub_msec_interval_lng_wrap(date *ret, date *t, lng *msec)
 {
-       date_sub_sec_interval_lng_wrap(ret, t, sec);
+       date_sub_msec_interval_lng_wrap(ret, t, msec);
        return MAL_SUCCEED;
 }
 
@@ -3641,24 +3641,23 @@ MTIMEdate_add_sec_interval_wrap(date *re
        return MAL_SUCCEED;
 }
 str
-MTIMEdate_add_sec_interval_lng_wrap(date *ret, date *t, lng *sec)
+MTIMEdate_add_msec_interval_lng_wrap(date *ret, date *t, lng *msec)
 {
-       date_add_sec_interval_lng_wrap(ret, t, sec);
+       date_add_msec_interval_lng_wrap(ret, t, msec);
        return MAL_SUCCEED;
 }
 
 str
-MTIMEtimestamp_add_sec_interval_lng_wrap(timestamp *ret, timestamp *t, lng 
*sec)
+MTIMEtimestamp_add_msec_interval_lng_wrap(timestamp *ret, timestamp *t, lng 
*msec)
 {
-       lng msec= *sec *1000;
-       timestamp_add(ret, t, &msec);
+       timestamp_add(ret, t, msec);
        return MAL_SUCCEED;
 }
 str
-MTIMEtimestamp_sub_sec_interval_lng_wrap(timestamp *ret, timestamp *t, lng 
*sec)
+MTIMEtimestamp_sub_msec_interval_lng_wrap(timestamp *ret, timestamp *t, lng 
*msec)
 {
-       lng msec= *sec * -1000;
-       timestamp_add(ret, t, &msec);
+       lng Msec= *msec * -1;
+       timestamp_add(ret, t, &Msec);
        return MAL_SUCCEED;
 }
 str
@@ -3686,16 +3685,16 @@ MTIMEtimestamp_sub_month_interval_wrap(t
 }
 
 str
-MTIMEtime_add_sec_interval_wrap(daytime *ret, daytime *t, lng *seconds)
+MTIMEtime_add_msec_interval_wrap(daytime *ret, daytime *t, lng *mseconds)
 {
-       lng s= 1000 * *seconds;
+       lng s= *mseconds;
        daytime_add(ret, t, &s);
        return MAL_SUCCEED;
 }
 str
-MTIMEtime_sub_sec_interval_wrap(daytime *ret, daytime *t, lng *seconds)
+MTIMEtime_sub_msec_interval_wrap(daytime *ret, daytime *t, lng *mseconds)
 {
-       lng s= -1000 * *seconds;
+       lng s= -1 * *mseconds;
        daytime_add(ret, t, &s);
        return MAL_SUCCEED;
 }
@@ -3995,25 +3994,25 @@ MTIMEsql_month(int *ret, int *t)
 str
 MTIMEsql_day(lng *ret, lng *t)
 {
-       *ret= (*t/86400);
+       *ret= (*t/86400000);
        return MAL_SUCCEED;
 }
 str
 MTIMEsql_hours(int *ret, lng *t)
 {
-       *ret= (int)( (*t % 86400)/3600);
+       *ret= (int)( (*t % 86400000)/3600000);
        return MAL_SUCCEED;
 }
 str
 MTIMEsql_minutes(int *ret, lng *t)
 {
-       *ret= (int)( (*t %3600)/60);
+       *ret= (int)( (*t %3600000)/60000);
        return MAL_SUCCEED;
 }
 str
 MTIMEsql_seconds(int *ret, lng *t)
 {
-       *ret= (int)(*t %60);
+       *ret= (int)( (*t %60000)/1000);
        return MAL_SUCCEED;
 }
 
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -619,6 +619,31 @@ comment "cast to dec(@1) and check for o
 @:mal_cast(int)@
 @:mal_cast(lng)@
 
+@= mal_casttime
+command calc.@1( v:str ) :@1 
+address str_2_@1
+comment "Cast to @1";
+command calc.@1( v:str, digits:int ) :@1 
+address str_2time_@1
+comment "cast to @1 and check for overflow";
+command calc.@1( v:@1, digits:int ) :@1 
+address @1_2time_@1
+comment "cast @1 to @1 and check for overflow";
+
+command batcalc.@1( v:bat[:oid,:str] ) :bat[:oid,:@1] 
+address batstr_2_@1
+comment "Cast to @1";
+command batcalc.@1( v:bat[:oid,:str], digits:int ) :bat[:oid,:@1] 
+address batstr_2time_@1
+comment "cast to @1 and check for overflow";
+command batcalc.@1( v:bat[:oid,:@1], digits:int ) :bat[:oid,:@1] 
+address bat@1_2time_@1
+comment "cast @1 to @1 and check for overflow";
+@
+@mal
+@:mal_casttime(timestamp)@
+@:mal_casttime(daytime)@
+
 @= mal_castfromstr
 command calc.@1( v:str ) :@1 
 address str_2_@1
@@ -634,8 +659,6 @@ comment "cast @1 to str";
 @:mal_castfromstr(wrd)@
 @:mal_castfromstr(flt)@
 @:mal_castfromstr(dbl)@
-@:mal_castfromstr(timestamp)@
-@:mal_castfromstr(daytime)@
 @:mal_castfromstr(date)@
 @:mal_castfromstr(sqlblob)@
 
@@ -1261,6 +1284,16 @@ sql5_export str batstr_2num_@1( int *res
 @:round_export(int)@
 @:round_export(wrd)@
 @:round_export(lng)@
+
+@= cast_time
+sql5_export str str_2time_@1( @1 *res, str *v, int *len );
+sql5_export str batstr_2time_@1( int *res, int *v, int *len );
+sql5_export str @1_2time_@1( @1 *res, @1 *v, int *len );
+sql5_export str bat@1_2time_@1( int *res, int *v, int *len );
+@
+@h
+@:cast_time(timestamp)@
+@:cast_time(daytime)@
 @= cast_export
 sql5_export str str_2_@1( @3 *res, str *val );
 sql5_export str batstr_2_@1( int *res, int *val );
@@ -1305,6 +1338,7 @@ sql5_export str second_interval_@1( lng 
 @:c_interval_export(wrd)@
 @:c_interval_export(lng)@
 @:c_interval_export(daytime)@
+sql5_export str second_interval_2_daytime( daytime *res, lng *s, int *d);
 @= simpleupcast_export
 sql5_export str @2_2_@1( @1 *res, @2 *v );
 sql5_export str bat@2_2_@1( int *res, int *v );
@@ -4028,6 +4062,114 @@ batstr_2num_@1( int *res, int *bid, int 
 @:round(wrd)@
 @:round(lng)@
 
+str
+daytime_2time_daytime( daytime *res, daytime *v, int *digits )
+{
+       int d = (*digits)?*digits-1:0;
+
+       /* correct fraction */
+       *res = *v;
+       if (d < 3) {
+               *res /= scales[3-d];
+               *res *= scales[3-d];
+       }
+       return MAL_SUCCEED;
+}
+
+str
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to