Changeset: bc4923c9aad2 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bc4923c9aad2
Added Files:
        sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.sql
        sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.err
        sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.out
Modified Files:
        sql/server/rel_psm.c
        sql/test/BugTracker-2015/Tests/All
Branch: Oct2014
Log Message:

properly pass restypelist to ifthenelse/while and case statements


diffs (271 lines):

diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -183,7 +183,7 @@ rel_psm_declare_table(mvc *sql, dnode *n
    support for LEAVE and ITERATE (sql multi-level break and continue)
  */
 static sql_exp * 
-rel_psm_while_do( mvc *sql, sql_subtype *res, dnode *w, int is_func )
+rel_psm_while_do( mvc *sql, sql_subtype *res, list *restypelist, dnode *w, int 
is_func )
 {
        if (!w)
                return NULL;
@@ -195,7 +195,7 @@ rel_psm_while_do( mvc *sql, sql_subtype 
 
                cond = rel_logical_value_exp(sql, &rel, n->data.sym, sql_sel); 
                n = n->next;
-               whilestmts = sequential_block(sql, res, NULL, n->data.lval, 
n->next->data.sval, is_func);
+               whilestmts = sequential_block(sql, res, restypelist, 
n->data.lval, n->next->data.sval, is_func);
 
                if (sql->session->status || !cond || !whilestmts || rel) 
                        return NULL;
@@ -211,7 +211,7 @@ rel_psm_while_do( mvc *sql, sql_subtype 
    end if
  */
 static list * 
-psm_if_then_else( mvc *sql, sql_subtype *res, dnode *elseif, int is_func)
+psm_if_then_else( mvc *sql, sql_subtype *res, list *restypelist, dnode 
*elseif, int is_func)
 {
        if (!elseif)
                return NULL;
@@ -224,9 +224,9 @@ psm_if_then_else( mvc *sql, sql_subtype 
 
                cond = rel_logical_value_exp(sql, &rel, n->data.sym, sql_sel); 
                n = n->next;
-               ifstmts = sequential_block(sql, res, NULL, n->data.lval, NULL, 
is_func);
+               ifstmts = sequential_block(sql, res, restypelist, n->data.lval, 
NULL, is_func);
                n = n->next;
-               elsestmts = psm_if_then_else( sql, res, n, is_func);
+               elsestmts = psm_if_then_else( sql, res, restypelist, n, 
is_func);
 
                if (sql->session->status || !cond || !ifstmts || rel) {
                        if (rel)
@@ -239,12 +239,12 @@ psm_if_then_else( mvc *sql, sql_subtype 
 
                if (e==NULL || (e->token != SQL_ELSE))
                        return NULL;
-               return sequential_block( sql, res, NULL, e->data.lval, NULL, 
is_func);
+               return sequential_block( sql, res, restypelist, e->data.lval, 
NULL, is_func);
        }
 }
 
 static sql_exp * 
-rel_psm_if_then_else( mvc *sql, sql_subtype *res, dnode *elseif, int is_func)
+rel_psm_if_then_else( mvc *sql, sql_subtype *res, list *restypelist, dnode 
*elseif, int is_func)
 {
        if (!elseif)
                return NULL;
@@ -256,9 +256,9 @@ rel_psm_if_then_else( mvc *sql, sql_subt
 
                cond = rel_logical_value_exp(sql, &rel, n->data.sym, sql_sel); 
                n = n->next;
-               ifstmts = sequential_block(sql, res, NULL, n->data.lval, NULL, 
is_func);
+               ifstmts = sequential_block(sql, res, restypelist, n->data.lval, 
NULL, is_func);
                n = n->next;
-               elsestmts = psm_if_then_else( sql, res, n, is_func);
+               elsestmts = psm_if_then_else( sql, res, restypelist, n, 
is_func);
                if (sql->session->status || !cond || !ifstmts || rel) {
                        if (rel)
                                return sql_error(sql, 02, "IF THEN ELSE: No 
SELECT statements allowed within the IF condition");
@@ -284,7 +284,7 @@ rel_psm_if_then_else( mvc *sql, sql_subt
        END CASE
  */
 static list * 
-rel_psm_case( mvc *sql, sql_subtype *res, dnode *case_when, int is_func )
+rel_psm_case( mvc *sql, sql_subtype *res, list *restypelist, dnode *case_when, 
int is_func )
 {
        list *case_stmts = sa_list(sql->sa);
 
@@ -307,7 +307,7 @@ rel_psm_case( mvc *sql, sql_subtype *res
                if (rel)
                        return sql_error(sql, 02, "CASE: No SELECT statements 
allowed within the CASE condition");
                if (else_statements) {
-                       else_stmt = sequential_block( sql, res, NULL, 
else_statements, NULL, is_func);
+                       else_stmt = sequential_block( sql, res, restypelist, 
else_statements, NULL, is_func);
                        if (!else_stmt) 
                                return NULL;
                }
@@ -320,7 +320,7 @@ rel_psm_case( mvc *sql, sql_subtype *res
 
                        if (!when_value || rel ||
                           (cond = rel_binop_(sql, v, when_value, NULL, "=", 
card_value)) == NULL || 
-                          (if_stmts = sequential_block( sql, res, NULL, 
m->next->data.lval, NULL, is_func)) == NULL ) {
+                          (if_stmts = sequential_block( sql, res, restypelist, 
m->next->data.lval, NULL, is_func)) == NULL ) {
                                if (rel)
                                        return sql_error(sql, 02, "CASE: No 
SELECT statements allowed within the CASE condition");
                                return NULL;
@@ -340,7 +340,7 @@ rel_psm_case( mvc *sql, sql_subtype *res
                list *else_stmt = NULL;
 
                if (else_statements) {
-                       else_stmt = sequential_block( sql, res, NULL, 
else_statements, NULL, is_func);
+                       else_stmt = sequential_block( sql, res, restypelist, 
else_statements, NULL, is_func);
                        if (!else_stmt) 
                                return NULL;
                }
@@ -353,7 +353,7 @@ rel_psm_case( mvc *sql, sql_subtype *res
                        sql_exp *case_stmt = NULL;
 
                        if (!cond || rel ||
-                          (if_stmts = sequential_block( sql, res, NULL, 
m->next->data.lval, NULL, is_func)) == NULL ) {
+                          (if_stmts = sequential_block( sql, res, restypelist, 
m->next->data.lval, NULL, is_func)) == NULL ) {
                                if (rel)
                                        return sql_error(sql, 02, "CASE: No 
SELECT statements allowed within the CASE condition");
                                return NULL;
@@ -384,9 +384,9 @@ rel_psm_return( mvc *sql, sql_subtype *r
        res = rel_value_exp2(sql, &rel, return_sym, sql_sel, ek, &is_last);
        if (!res)
                return NULL;
-       if (ek.card != card_relation && (!res || 
+       if (ek.card != card_relation && (!res || !restype ||
                (res = rel_check_type(sql, restype, res, type_equal)) == NULL))
-               return NULL;
+               return (!restype)?sql_error(sql, 02, "RETURN: return type does 
not match"):NULL;
        else if (ek.card == card_relation && !rel)
                return NULL;
        
@@ -553,13 +553,13 @@ sequential_block (mvc *sql, sql_subtype 
                        res = rel_psm_declare_table(sql, s->data.lval->h);
                        break;
                case SQL_WHILE:
-                       res = rel_psm_while_do(sql, restype, s->data.lval->h, 
is_func);
+                       res = rel_psm_while_do(sql, restype, restypelist, 
s->data.lval->h, is_func);
                        break;
                case SQL_IF:
-                       res = rel_psm_if_then_else(sql, restype, 
s->data.lval->h, is_func);
+                       res = rel_psm_if_then_else(sql, restype, restypelist, 
s->data.lval->h, is_func);
                        break;
                case SQL_CASE:
-                       reslist = rel_psm_case(sql, restype, s->data.lval->h, 
is_func);
+                       reslist = rel_psm_case(sql, restype, restypelist, 
s->data.lval->h, is_func);
                        break;
                case SQL_CALL:
                        res = rel_psm_call(sql, s->data.sym);
@@ -575,6 +575,7 @@ sequential_block (mvc *sql, sql_subtype 
                                        res = sql_error(sql, 01, 
                                                "Statement after return");
                                } else {
+                                       res = NULL;
                                        reslist = rel_psm_return(sql, restype, 
restypelist, s->data.sym);
                                }
                        }
diff --git a/sql/test/BugTracker-2015/Tests/All 
b/sql/test/BugTracker-2015/Tests/All
--- a/sql/test/BugTracker-2015/Tests/All
+++ b/sql/test/BugTracker-2015/Tests/All
@@ -23,3 +23,4 @@ project_rewrite.Bug-3693_2
 alias.Bug-3704
 case_aggr.Bug-3705
 assertHead.Bug-3706
+ifthenelse.Bug-3699
diff --git a/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.sql 
b/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.sql
@@ -0,0 +1,12 @@
+create table quotes( sdate timestamp);
+CREATE FUNCTION test_quotes(a string) RETURNS table(SOMEFIELD date)
+BEGIN  
+       IF a is NULL THEN
+               return table( select cast(sdate as date) from quotes limit 10);
+       ELSE 
+               return table( select cast(sdate as date) from quotes limit 10);
+       END IF;
+END;
+select * from test_quotes('test') as x;
+drop function test_quotes;
+drop table quotes;
diff --git a/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.err 
b/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.err
@@ -0,0 +1,37 @@
+stderr of test 'ifthenelse.Bug-3699` in directory 'sql/test/BugTracker-2015` 
itself:
+
+
+# 07:44:02 >  
+# 07:44:02 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=33259" "--set" 
"mapi_usock=/var/tmp/mtest-2555/.s.monetdb.33259" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2015"
 "--set" "mal_listing=0" "--set" "embedded_r=yes"
+# 07:44:02 >  
+
+# builtin opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 33259
+# cmdline opt  mapi_usock = /var/tmp/mtest-2555/.s.monetdb.33259
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2015
+# cmdline opt  mal_listing = 0
+# cmdline opt  embedded_r = yes
+# cmdline opt  gdk_debug = 536870922
+
+# 07:44:02 >  
+# 07:44:02 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-2555" "--port=33259"
+# 07:44:02 >  
+
+
+# 07:44:02 >  
+# 07:44:02 >  "Done."
+# 07:44:02 >  
+
diff --git a/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.out 
b/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2015/Tests/ifthenelse.Bug-3699.stable.out
@@ -0,0 +1,48 @@
+stdout of test 'ifthenelse.Bug-3699` in directory 'sql/test/BugTracker-2015` 
itself:
+
+
+# 07:44:02 >  
+# 07:44:02 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=33259" "--set" 
"mapi_usock=/var/tmp/mtest-2555/.s.monetdb.33259" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2015"
 "--set" "mal_listing=0" "--set" "embedded_r=yes"
+# 07:44:02 >  
+
+# MonetDB 5 server v11.19.10
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2015', using 4 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically 
linked
+# Found 7.333 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://localhost.nes.nl:33259/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-2555/.s.monetdb.33259
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+# MonetDB/R   module loaded
+
+Ready.
+
+# 07:44:02 >  
+# 07:44:02 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-2555" "--port=33259"
+# 07:44:02 >  
+
+#create table quotes( sdate timestamp);
+#CREATE FUNCTION test_quotes(a string) RETURNS table(SOMEFIELD date)
+#BEGIN 
+#      IF a is NULL THEN
+#              return table( select cast(sdate as date) from quotes limit 10);
+#      ELSE 
+#              return table( select cast(sdate as date) from quotes limit 10);
+#      END IF;
+#END;
+#select * from test_quotes('test') as x;
+% .x # table_name
+% somefield # name
+% date # type
+% 10 # length
+#drop function test_quotes;
+#drop table quotes;
+
+# 07:44:02 >  
+# 07:44:02 >  "Done."
+# 07:44:02 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to