Changeset: f1ba1a569594 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f1ba1a569594
Modified Files:
        sql/backends/monet5/sql.mx
        sql/server/sql_atom.c
        sql/server/sql_mvc.h
        sql/test/BugDay_2005-10-06_2.9.3/Tests/set_types.SF-932360.stable.out
        sql/test/BugTracker-2011/Tests/sqltables.Bug-2921.stable.out
Branch: Dec2011
Log Message:

fixed problem with timezone setting

added truncing of decimals in atom_cast


diffs (113 lines):

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
@@ -5510,8 +5510,9 @@ second_interval_@1( lng *res, @1 *s, int
        case ihour:
                r *= 60;
        case imin:
-               r *= 60000;
+               r *= 60;
        case isec:
+               r *= 1000;
                break;
        default:
                throw(ILLARG, "calc.second_interval","illegal argument");
diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c
--- a/sql/server/sql_atom.c
+++ b/sql/server/sql_atom.c
@@ -652,6 +652,52 @@ atom_cast(atom *a, sql_subtype *tp)
                        }
                        return 1;
                }
+               /* truncating decimals */
+               if (at->type->eclass == EC_DEC && tp->type->eclass == EC_DEC &&
+                   at->type->localtype >= tp->type->localtype &&
+                   at->digits >= tp->digits && 
+                       (at->digits - tp->digits) == (at->scale - tp->scale)) {
+                       lng mul = 1, div = 0, rnd = 0, val = 0;
+
+                       /* fix scale */
+
+                       /* only round when going to a lower scale */
+                       mul = scales[at->scale-tp->scale];
+                       rnd = mul>>1;
+                       div = 1;
+
+                       if (a->data.vtype == TYPE_lng) {
+                               val = a->data.val.lval;
+                       } else if (a->data.vtype == TYPE_int) {
+                               val = a->data.val.ival;
+                       } else if (a->data.vtype == TYPE_sht) {
+                               val = a->data.val.shval;
+                       } else if (a->data.vtype == TYPE_bte) {
+                               val = a->data.val.btval;
+                       }
+
+                       val += rnd;
+                       if (div)
+                               val /= mul;
+                       else
+                               val *= mul;
+
+                       a->tpe = *tp;
+                       a->data.vtype = tp->type->localtype;
+                       if (a->data.vtype == TYPE_lng) {
+                               a->data.val.lval = (int) val;
+                       } else if (a->data.vtype == TYPE_int) {
+                               assert( ((lng) GDK_int_min <= val && val <= 
(lng) GDK_int_max));
+                               a->data.val.ival = (int) val;
+                       } else if (a->data.vtype == TYPE_sht) {
+                               assert( ((lng) GDK_sht_min <= val && val <= 
(lng) GDK_sht_max));
+                               a->data.val.shval = (int) val;
+                       } else if (a->data.vtype == TYPE_bte) {
+                               assert( ((lng) GDK_bte_min <= val && val <= 
(lng) GDK_bte_max));
+                               a->data.val.btval = (int) val;
+                       }
+                       return 1;
+               }
                if (at->type->eclass == EC_NUM && tp->type->eclass == EC_DEC &&
                    at->type->localtype <= tp->type->localtype &&
                    (at->digits <= tp->digits || atom_num_digits(a) <= 
tp->digits) &&
diff --git a/sql/server/sql_mvc.h b/sql/server/sql_mvc.h
--- a/sql/server/sql_mvc.h
+++ b/sql/server/sql_mvc.h
@@ -100,7 +100,7 @@ typedef struct mvc {
        lng last_id;
 
        /* current session variables */
-       int timezone;           /* minutes west of UTC */
+       int timezone;           /* milliseconds west of UTC */
        int cache;              /* some queries should not be cached ! */
        int caching;            /* cache current query ? */
        int history;            /* queries statistics are kept  */
diff --git 
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/set_types.SF-932360.stable.out 
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/set_types.SF-932360.stable.out
--- a/sql/test/BugDay_2005-10-06_2.9.3/Tests/set_types.SF-932360.stable.out
+++ b/sql/test/BugDay_2005-10-06_2.9.3/Tests/set_types.SF-932360.stable.out
@@ -28,12 +28,13 @@ Ready.
 % single_value # name
 % sec_interval # type
 % 0 # length
-[ 60   ]
+[ 60.000       ]
+#select current_timezone;
 % . # table_name
 % single_value # name
 % sec_interval # type
 % 0 # length
-[ 0    ]
+[ 0.000        ]
 
 # 08:23:41 >  
 # 08:23:41 >  Done.
diff --git a/sql/test/BugTracker-2011/Tests/sqltables.Bug-2921.stable.out 
b/sql/test/BugTracker-2011/Tests/sqltables.Bug-2921.stable.out
--- a/sql/test/BugTracker-2011/Tests/sqltables.Bug-2921.stable.out
+++ b/sql/test/BugTracker-2011/Tests/sqltables.Bug-2921.stable.out
@@ -49,7 +49,7 @@ Ready.
 % .e,  .s,     .t,     .,      . # table_name
 % table_cat,   table_schem,    table_name,     table_type,     remarks # name
 % varchar,     varchar,        varchar,        varchar,        varchar # type
-% 27,  3,      7,      16,     0 # length
+% 27,  3,      8,      16,     0 # length
 [ "mTests_test_BugTracker-2011",       "tmp",  "globtemp",     "GLOBAL 
TEMPORARY",     NULL    ]
 [ "mTests_test_BugTracker-2011",       "tmp",  "loctemp",      "LOCAL 
TEMPORARY",      NULL    ]
 #select e."value" as table_cat, s."name" as table_schem, t."name" as 
table_name, case when t."type" = 0 and t."system" = false and t."temporary" = 0 
and s."name" <> 'tmp' then cast('TABLE' as varchar(20)) when t."type" = 0 and 
t."system" = false and t."temporary" = 0 and s."name" = 'tmp' then cast('GLOBAL 
TEMPORARY' as varchar(20)) when t."type" = 0 and t."system" = true and 
t."temporary" = 0 then cast('SYSTEM TABLE' as varchar(20)) when t."type" = 1 
then cast('VIEW' as varchar(20)) when t."type" = 0 and t."system" = false and 
t."temporary" = 1 then cast('LOCAL TEMPORARY' as varchar(20)) else 
cast('INTERNAL TABLE TYPE' as varchar(20)) end as table_type, cast(null as 
varchar(1)) as remarks from sys."schemas" s, sys."tables" t, sys."env"() e 
where s."id" = t."schema_id" and e.name = 'gdk_dbname' and ((t."type" = 0 and 
t."system" = false and t."temporary" = 0 and s."name" = 'tmp')) order by 
table_type, table_schem, table_name;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to