Changeset: 24aa42eeb40b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=24aa42eeb40b
Modified Files:
        sql/server/rel_psm.c
        
sql/test/BugTracker-2012/Tests/type_resolution_error_in_SQL_procedural_code.Bug-3143.stable.err
        sql/test/bugs/Tests/emili.stable.err
Branch: default
Log Message:

allow if (select ..) then expressions.


diffs (100 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
@@ -218,10 +218,15 @@ psm_if_then_else( mvc *sql, sql_subtype 
                n = n->next;
                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: No SELECT 
statements allowed within the IF condition");
+               if (sql->session->status || !cond || !ifstmts) 
                        return NULL;
+               if (rel) {
+                       sql_exp *er = exp_rel(sql, rel);
+                       list *b = sa_list(sql->sa);
+
+                       append(b, er);
+                       append(b, exp_if(sql->sa, cond, ifstmts, elsestmts));
+                       return b;
                }
                return append(sa_list(sql->sa), exp_if( sql->sa, cond, ifstmts, 
elsestmts));
        } else { /* else */
@@ -249,10 +254,15 @@ rel_psm_if_then_else( mvc *sql, sql_subt
                ifstmts = sequential_block(sql, res, restypelist, n->data.lval, 
NULL, is_func);
                n = n->next;
                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");
+               if (sql->session->status || !cond || !ifstmts) 
                        return NULL;
+               if (rel) {
+                       sql_exp *er = exp_rel(sql, rel);
+                       list *b = sa_list(sql->sa);
+
+                       append(b, er);
+                       append(b, exp_if(sql->sa, cond, ifstmts, elsestmts));
+                       return exp_rel(sql, rel_psm_block(sql->sa, b));
                }
                return exp_if( sql->sa, cond, ifstmts, elsestmts);
        }
diff --git 
a/sql/test/BugTracker-2012/Tests/type_resolution_error_in_SQL_procedural_code.Bug-3143.stable.err
 
b/sql/test/BugTracker-2012/Tests/type_resolution_error_in_SQL_procedural_code.Bug-3143.stable.err
--- 
a/sql/test/BugTracker-2012/Tests/type_resolution_error_in_SQL_procedural_code.Bug-3143.stable.err
+++ 
b/sql/test/BugTracker-2012/Tests/type_resolution_error_in_SQL_procedural_code.Bug-3143.stable.err
@@ -29,21 +29,6 @@ stderr of test 'type_resolution_error_in
 # 16:19:02 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=niels" 
"--port=33753"
 # 16:19:02 >  
 
-MAPI  = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
-QUERY = CREATE PROCEDURE enrich_b()
-        BEGIN
-            INSERT INTO sensors(ip, location, kind,value)
-                SELECT ip, substring(location,0,3), kind, value FROM istream;
-            IF (SELECT count(*) FROM area ) = 0
-            THEN
-                INSERT INTO area SELECT ip, substring(location,0,3) FROM
-        istream;
-            END IF;
-        END;
-ERROR = !IF THEN ELSE: No SELECT statements allowed within the IF condition
-MAPI  = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
-QUERY = drop procedure enrich_b();
-ERROR = !DROP PROCEDURE: no such procedure 'enrich_b' ()
 
 
 # 15:17:52 >  
diff --git a/sql/test/bugs/Tests/emili.stable.err 
b/sql/test/bugs/Tests/emili.stable.err
--- a/sql/test/bugs/Tests/emili.stable.err
+++ b/sql/test/bugs/Tests/emili.stable.err
@@ -28,30 +28,6 @@ stderr of test 'emili` in directory 'sql
 # 19:14:59 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-15106" "--port=32975"
 # 19:14:59 >  
 
-MAPI  = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
-QUERY = CREATE PROCEDURE enrich2()
-        BEGIN
-             INSERT INTO sensors(ip, location, kind,value)
-                 SELECT ip, substring(location,0,3), kind, value FROM istream;
-             IF (SELECT count(*) FROM area ) = 0
-             THEN
-                 INSERT INTO area SELECT ip, substring(location,0,3) FROM 
istream;
-             END IF;
-        END;
-ERROR = !IF THEN ELSE: No SELECT statements allowed within the IF condition
-MAPI  = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
-QUERY = CREATE PROCEDURE enrich3()
-        BEGIN
-             DECLARE cnt INTEGER;
-             SET cnt = (SELECT count(*) FROM area ) ;
-             INSERT INTO sensors(ip, location, kind,value)
-                 SELECT ip, substring(location,0,3), kind, value FROM istream;
-             IF cnt = 0
-             THEN
-                 INSERT INTO area SELECT ip, substring(location,0,3) FROM 
istream;
-             END IF;
-        END;
-ERROR = !current transaction is aborted (please ROLLBACK)
 
 # 19:14:59 >  
 # 19:14:59 >  "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to