Changeset: 4800f138bea5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4800f138bea5
Modified Files:
        sql/server/rel_dump.c
Branch: Aug2024
Log Message:

backport or/and handling and added brackets for nested infix operators in 
exp2sql.


diffs (63 lines):

diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -2521,6 +2521,11 @@ is_infix(sql_func *f)
                        return true;
                if (f->base.name[0] == '|' && f->base.name[1] == '|')
                        return true;
+               if (f->base.name[0] == 'o' && f->base.name[1] == 'r')
+                       return true;
+       } else if (strlen(f->base.name) == 3) {
+               if (f->base.name[0] == 'a' && f->base.name[1] == 'n' && 
f->base.name[2] == 'd')
+                       return true;
        }
        return false;
 }
@@ -2550,21 +2555,25 @@ exp2sql_dquoted(stream *fout, const char
 
 /* only simple expressions, ie recursive no psm */
 static void
-exp2sql_print(mvc *sql, stream *fout, sql_exp *e)
+exp2sql_print(mvc *sql, stream *fout, sql_exp *e, int depth)
 {
        switch (e->type) {
                case e_func: {
                        sql_subfunc *sf = e->f;
                        list *args = e->l;
                        if (list_length(args) == 2 && is_infix(sf->func)) {
-                               exp2sql_print(sql, fout, args->h->data);
+                               if (depth)
+                                       mnstr_printf(fout, "( " );
+                               exp2sql_print(sql, fout, args->h->data, 
depth+1);
                                mnstr_printf(fout, " %s ", sf->func->base.name);
-                               exp2sql_print(sql, fout, args->h->next->data);
+                               exp2sql_print(sql, fout, args->h->next->data, 
depth+1);
+                               if (depth)
+                                       mnstr_printf(fout, " )" );
                        } else {
                                exp2sql_dquoted(fout, NULL, 
sf->func->base.name, "(");
                                if (args)
                                        for (node *n = args->h; n; n = n->next) 
{
-                                               exp2sql_print(sql, fout, 
n->data);
+                                               exp2sql_print(sql, fout, 
n->data, depth+1);
                                                if (n->next)
                                                        mnstr_printf(fout, ", 
");
                                        }
@@ -2576,7 +2585,7 @@ exp2sql_print(mvc *sql, stream *fout, sq
                        break;
                case e_convert:
                        mnstr_printf(fout, "CAST (" );
-                       exp2sql_print(sql, fout, e->l);
+                       exp2sql_print(sql, fout, e->l, depth+1);
                        mnstr_printf(fout, "AS %s)", 
sql_subtype_string(sql->sa, exp_subtype(e)));
                        break;
                case e_atom:
@@ -2604,7 +2613,7 @@ exp2sql( mvc *sql, sql_exp *exp)
        if(s == NULL)
                goto cleanup;
 
-       exp2sql_print(sql, s, exp);
+       exp2sql_print(sql, s, exp, 0);
 
        res = buffer_get_buf(b);
 
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to