Update of /cvsroot/monetdb/sql/src/common
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22656

Modified Files:
        sql_types.mx 
Log Message:
cleanup of scale fixing in functions


U sql_types.mx
Index: sql_types.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/common/sql_types.mx,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- sql_types.mx        30 May 2008 09:30:56 -0000      1.106
+++ sql_types.mx        20 Jun 2008 20:55:44 -0000      1.107
@@ -122,7 +122,7 @@
 extern sql_func *sql_create_func3(char *name, char *mod, char *imp, sql_type 
*tpe1, sql_type *tpe2, sql_type *tpe3, sql_type *res, int scale_fixing);
 extern sql_func *sql_create_func4(char *name, char *mod, char *imp, sql_type 
*tpe1, sql_type *tpe2, sql_type *tpe3, sql_type *tpe4, sql_type *res, int 
scale_fixing);
 
-extern sql_func *sql_create_func_(char *name, char *mod, char *imp, list *ops, 
sql_subtype *res, bit side_effect, bit aggr);
+extern sql_func *sql_create_func_(char *name, char *mod, char *imp, list *ops, 
sql_subtype *res, bit side_effect, bit aggr, int fix_scale);
 
 extern sql_func *sql_create_sqlfunc(char *name, char *imp, list *ops, 
sql_subtype *res);
 
@@ -779,12 +779,15 @@
 
                                sql_ref_init(&(fres->ref));
                                fres->func = f;
-                               for (n = ops->h; n; n = n->next) {
-                                       sql_subtype *a = n->data;
+                               /* fix the scale */
+                               if (f->fix_scale > SCALE_NONE) {
+                                       for (n = ops->h; n; n = n->next) {
+                                               sql_subtype *a = n->data;
 
-                                       /* same scale as the input */
-                                       if (a && a->scale > scale)
-                                               scale = a->scale;
+                                               /* same scale as the input */
+                                               if (a && a->scale > scale)
+                                                       scale = a->scale;
+                                       }
                                }
                                /* same type as the first input */
                                if (f->res.type->eclass == EC_ANY) {
@@ -1088,11 +1091,11 @@
                list_append(l, create_arg(NULL, sql_create_subtype(tpe, 0, 0)));
        assert(res);
        sql_init_subtype(&sres, res, 0, 0);
-       return sql_create_func_(name, mod, imp, l, &sres, FALSE, TRUE);
+       return sql_create_func_(name, mod, imp, l, &sres, FALSE, TRUE, 
SCALE_NONE);
 }
 
 sql_func *
-sql_create_func(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *res, int scale_fixing)
+sql_create_func(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *res, int fix_scale)
 {
        list *l = list_create((fdestroy) &arg_destroy);
        sql_subtype sres;
@@ -1102,12 +1105,12 @@
        if (tpe2)
                list_append(l,create_arg(NULL, sql_create_subtype(tpe2, 0, 0)));
 
-       sql_init_subtype(&sres, res, 0, scale_fixing);
-       return sql_create_func_(name, mod, imp, l, &sres, FALSE, FALSE);
+       sql_init_subtype(&sres, res, 0, 0);
+       return sql_create_func_(name, mod, imp, l, &sres, FALSE, FALSE, 
fix_scale);
 }
 
 sql_func *
-sql_create_funcSE(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *res, int scale_fixing)
+sql_create_funcSE(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *res, int fix_scale)
 {
        list *l = list_create((fdestroy) &arg_destroy);
        sql_subtype sres;
@@ -1117,13 +1120,13 @@
        if (tpe2)
                list_append(l,create_arg(NULL, sql_create_subtype(tpe2, 0, 0)));
 
-       sql_init_subtype(&sres, res, 0, scale_fixing);
-       return sql_create_func_(name, mod, imp, l, &sres, TRUE, FALSE);
+       sql_init_subtype(&sres, res, 0, 0);
+       return sql_create_func_(name, mod, imp, l, &sres, TRUE, FALSE, 
fix_scale);
 }
 
 
 sql_func *
-sql_create_func3(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *tpe3, sql_type *res, int scale_fixing)
+sql_create_func3(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *tpe3, sql_type *res, int fix_scale)
 {
        list *l = list_create((fdestroy) &arg_destroy);
        sql_subtype sres;
@@ -1132,12 +1135,12 @@
        list_append(l, create_arg(NULL, sql_create_subtype(tpe2, 0, 0)));
        list_append(l, create_arg(NULL, sql_create_subtype(tpe3, 0, 0)));
 
-       sql_init_subtype(&sres, res, 0, scale_fixing);
-       return sql_create_func_(name, mod, imp, l, &sres, FALSE, FALSE);
+       sql_init_subtype(&sres, res, 0, 0);
+       return sql_create_func_(name, mod, imp, l, &sres, FALSE, FALSE, 
fix_scale);
 }
 
 sql_func *
-sql_create_func4(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *tpe3, sql_type *tpe4, sql_type *res, int scale_fixing)
+sql_create_func4(char *name, char *mod, char *imp, sql_type *tpe1, sql_type 
*tpe2, sql_type *tpe3, sql_type *tpe4, sql_type *res, int fix_scale)
 {
        list *l = list_create((fdestroy) &arg_destroy);
        sql_subtype sres;
@@ -1147,13 +1150,13 @@
        list_append(l, create_arg(NULL, sql_create_subtype(tpe3, 0, 0)));
        list_append(l, create_arg(NULL, sql_create_subtype(tpe4, 0, 0)));
 
-       sql_init_subtype(&sres, res, 0, scale_fixing);
-       return sql_create_func_(name, mod, imp, l, &sres, FALSE, FALSE);
+       sql_init_subtype(&sres, res, 0, 0);
+       return sql_create_func_(name, mod, imp, l, &sres, FALSE, FALSE, 
fix_scale);
 }
 
 
 sql_func *
-sql_create_func_(char *name, char *mod, char *imp, list *ops, sql_subtype 
*res, bit side_effect, bit aggr)
+sql_create_func_(char *name, char *mod, char *imp, list *ops, sql_subtype 
*res, bit side_effect, bit aggr, int fix_scale)
 {
        sql_func *t = NEW(sql_func);
 
@@ -1173,6 +1176,7 @@
        t->sql = 0;
        t->aggr = aggr;
        t->side_effect = side_effect;
+       t->fix_scale = fix_scale;
        t->s = NULL;
        if (aggr)
                list_append(aggrs, t);
@@ -1319,7 +1323,7 @@
        sql_create_aggr("max", "aggr", "max", ANY, ANY);
        sql_create_func("sql_min", "calc", "min", ANY, ANY, ANY, SCALE_FIX);
        sql_create_func("sql_max", "calc", "max", ANY, ANY, ANY, SCALE_FIX);
-       sql_create_func3("ifthenelse", "calc", "ifthenelse", BIT, ANY, ANY, 
ANY, SCALE_NONE);
+       sql_create_func3("ifthenelse", "calc", "ifthenelse", BIT, ANY, ANY, 
ANY, SCALE_FIX);
 
        /* sum for numerical and decimals */
        for (t = numerical+1; t < floats; t += 4) {
@@ -1405,7 +1409,7 @@
        }
 
        for (t = decimals; t < dates; t++) 
-               sql_create_func("round", "sql", "round", *t, BTE, *t, 
SCALE_NONE);
+               sql_create_func("round", "sql", "round", *t, BTE, *t, INOUT);
 
        for (t = numerical; t < end; t++) {
                sql_type **u;
@@ -1462,13 +1466,13 @@
        sql_create_func("sql_sub", "mtime", "diff", DTE, DTE, INT, SCALE_FIX);
        sql_create_func("sql_sub", "mtime", "diff", TMESTAMP, TMESTAMP, LNG, 
SCALE_FIX);
 
-       sql_create_func("sql_add", "mtime", "date_add_sec_interval", DTE, 
SECINT, DTE, SCALE_FIX);
-       sql_create_func("sql_add", "mtime", "addmonths", DTE, MONINT, DTE, 
SCALE_FIX);
-       sql_create_func("sql_add", "mtime", "timestamp_add_sec_interval", 
TMESTAMP, SECINT, TMESTAMP, SCALE_FIX);
-       sql_create_func("sql_add", "mtime", "addmonths", TMESTAMP, MONINT, 
TMESTAMP, SCALE_FIX);
-       sql_create_func("sql_add", "mtime", "timestamp_add_sec_interval", 
TMESTAMPTZ, SECINT, TMESTAMPTZ, SCALE_FIX);
-       sql_create_func("sql_add", "mtime", "addmonths", TMESTAMPTZ, MONINT, 
TMESTAMPTZ, SCALE_FIX);
-       sql_create_func("sql_add", "mtime", "time_add_sec_interval", TME, 
SECINT, TME, SCALE_FIX);
+       sql_create_func("sql_add", "mtime", "date_add_sec_interval", DTE, 
SECINT, DTE, SCALE_NONE);
+       sql_create_func("sql_add", "mtime", "addmonths", DTE, MONINT, DTE, 
SCALE_NONE);
+       sql_create_func("sql_add", "mtime", "timestamp_add_sec_interval", 
TMESTAMP, SECINT, TMESTAMP, SCALE_NONE);
+       sql_create_func("sql_add", "mtime", "addmonths", TMESTAMP, MONINT, 
TMESTAMP, SCALE_NONE);
+       sql_create_func("sql_add", "mtime", "timestamp_add_sec_interval", 
TMESTAMPTZ, SECINT, TMESTAMPTZ, SCALE_NONE);
+       sql_create_func("sql_add", "mtime", "addmonths", TMESTAMPTZ, MONINT, 
TMESTAMPTZ, SCALE_NONE);
+       sql_create_func("sql_add", "mtime", "time_add_sec_interval", TME, 
SECINT, TME, SCALE_NONE);
        sql_create_func("local_timezone", "mtime", "local_timezone", NULL, 
NULL, SECINT, SCALE_FIX);
 
        sql_create_func("year", "mtime", "year", DTE, NULL, INT, SCALE_FIX);
@@ -1544,7 +1548,7 @@
                { sql_subtype sres;
                sql_init_subtype(&sres, INT, 0, 0);
                sql_create_func_("levenshtein", "txtsim", "levenshtein",
-                                list_append(list_append (list_append 
(list_append(list_append(list_create((fdestroy) &arg_destroy), create_arg(NULL, 
sql_create_subtype(*t, 0, 0))), create_arg(NULL, sql_create_subtype(*t, 0, 
0))), create_arg(NULL, sql_create_subtype(INT, 0, 0))), create_arg(NULL, 
sql_create_subtype(INT, 0, 0))), create_arg(NULL, sql_create_subtype(INT, 0, 
0))), &sres, FALSE, FALSE);
+                                list_append(list_append (list_append 
(list_append(list_append(list_create((fdestroy) &arg_destroy), create_arg(NULL, 
sql_create_subtype(*t, 0, 0))), create_arg(NULL, sql_create_subtype(*t, 0, 
0))), create_arg(NULL, sql_create_subtype(INT, 0, 0))), create_arg(NULL, 
sql_create_subtype(INT, 0, 0))), create_arg(NULL, sql_create_subtype(INT, 0, 
0))), &sres, FALSE, FALSE, SCALE_FIX);
                }
        }
 }


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to