Changeset: 1ee4a27c1126 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1ee4a27c1126
Modified Files:
        sql/common/sql_types.c
        sql/server/rel_psm.c
        sql/server/rel_select.c
        sql/test/BugTracker-2012/Tests/timestamp_minus_date.Bug-2977.stable.err
        
sql/test/BugTracker-2012/Tests/type_resolution_error_in_SQL_procedural_code.Bug-3143.stable.err
Branch: Oct2012
Log Message:

fixed bugs 2977 and 3143

return errors in psm when we don't expect select statements (solves 3143)

Give proper error when a function isn't found and don't allow converts from
date into second intervals. (solves 2977)


diffs (155 lines):

diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -100,7 +100,7 @@ static int convert_matrix[EC_MAX][EC_MAX
 /* EC_DEC */   { 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
 /* EC_FLT */   { 0, 0, 0, 1, 1, 0, 1, 3, 1, 1, 0, 0, 0, 0 },
 /* EC_TIME */  { 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0 },
-/* EC_DATE */  { 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 3, 0 },
+/* EC_DATE */  { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 3, 0 },
 /* EC_TSTAMP */        { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
 /* EC_EXTERNAL*/{ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
 };
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
@@ -227,8 +227,11 @@ psm_if_then_else( mvc *sql, sql_subtype 
                n = n->next;
                elsestmts = psm_if_then_else( sql, res, n, is_func);
 
-               if (sql->session->status || !cond || !ifstmts || rel) 
+               if (sql->session->status || !cond || !ifstmts || rel) {
+                       if (rel)
+                               return sql_error(sql, 02, "IF THEN: No SELECT 
statements allowed within the IF condition");
                        return NULL;
+               }
                return append(sa_list(sql->sa), exp_if( sql->sa, cond, ifstmts, 
elsestmts));
        } else { /* else */
                symbol *e = elseif->data.sym;
@@ -255,8 +258,11 @@ rel_psm_if_then_else( mvc *sql, sql_subt
                ifstmts = sequential_block(sql, res, n->data.lval, NULL, 
is_func);
                n = n->next;
                elsestmts = psm_if_then_else( sql, res, n, is_func);
-               if (sql->session->status || !cond || !ifstmts || rel) 
+               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");
                        return NULL;
+               }
                return exp_if( sql->sa, cond, ifstmts, elsestmts);
        }
        return NULL;
@@ -295,8 +301,10 @@ rel_psm_case( mvc *sql, sql_subtype *res
                exp_kind ek = {type_value, card_value, FALSE};
                sql_exp *v = rel_value_exp(sql, &rel, case_value, sql_sel, ek);
 
-               if (!v || rel)
+               if (!v)
                        return NULL;
+               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, 
else_statements, NULL, is_func);
                        if (!else_stmt) 
@@ -311,8 +319,11 @@ 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, 
m->next->data.lval, NULL, is_func)) == NULL ) 
+                          (if_stmts = sequential_block( sql, res, 
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;
+                       }
                        case_stmt = exp_if(sql->sa, cond, if_stmts, NULL);
                        list_append(case_stmts, case_stmt);
                        n = n->next;
@@ -341,8 +352,11 @@ rel_psm_case( mvc *sql, sql_subtype *res
                        sql_exp *case_stmt = NULL;
 
                        if (!cond || rel ||
-                          (if_stmts = sequential_block( sql, res, 
m->next->data.lval, NULL, is_func)) == NULL ) 
+                          (if_stmts = sequential_block( sql, res, 
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;
+                       }
                        case_stmt = exp_if(sql->sa, cond, if_stmts, NULL);
                        list_append(case_stmts, case_stmt);
                        n = n->next;
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -3556,12 +3556,16 @@ rel_binop_(mvc *sql, sql_exp *l, sql_exp
                        if (l && r)
                                return exp_binop(sql->sa, l, r, f);
                }
-       }
-       if (r && l)
-               res = sql_error(sql, 02, "SELECT: no such binary operator 
'%s(%s,%s)'",
-                               fname,
-                               exp_subtype(l)->type->sqlname,
-                               exp_subtype(r)->type->sqlname);
+               /* reset error */
+               sql->session->status = 0;
+               sql->errstr[0] = '\0';
+
+               l = ol;
+               r = or;
+       }
+       res = sql_error(sql, 02, "SELECT: no such binary operator '%s(%s,%s)'", 
fname,
+                       exp_subtype(l)->type->sqlname,
+                       exp_subtype(r)->type->sqlname);
        return res;
 }
 
diff --git 
a/sql/test/BugTracker-2012/Tests/timestamp_minus_date.Bug-2977.stable.err 
b/sql/test/BugTracker-2012/Tests/timestamp_minus_date.Bug-2977.stable.err
--- a/sql/test/BugTracker-2012/Tests/timestamp_minus_date.Bug-2977.stable.err
+++ b/sql/test/BugTracker-2012/Tests/timestamp_minus_date.Bug-2977.stable.err
@@ -29,7 +29,9 @@ stderr of test 'timestamp_minus_date.Bug
 # 13:51:42 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=warsaw" 
"--port=39949"
 # 13:51:42 >  
 
-There should be a error message stating that SQL(-99) does not allow 
arrithmetic between timestamps and dates.
+MAPI  = monetdb@niels:34679
+QUERY = select (cast('1970-01-01 0:00' as timestamp) - cast('1970-01-01' as 
date));
+ERROR = !SELECT: no such binary operator 'sql_sub(timestamp,date)'
 
 # 13:51:43 >  
 # 13:51:43 >  "Done."
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
@@ -25,15 +25,25 @@ stderr of test 'type_resolution_error_in
 # cmdline opt  gdk_dbname = mTests_test_BugTracker-2012
 # cmdline opt  mal_listing = 0
 
-# 15:17:51 >  
-# 15:17:51 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=lyon" 
"--port=35055"
-# 15:17:51 >  
+# 16:19:02 >  
+# 16:19:02 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=niels" 
"--port=33753"
+# 16:19:02 >  
 
-MAPI  = monetdb@lyon:35055
-QUERY = HERE WE SHOULD HAVE A ERROR REPORTING THAT THE CREATION OF enrich_b() 
FAILED;
-
-MAPI  = monetdb@lyon:35055
+MAPI  = monetdb@niels:33753
+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@niels:33753
 QUERY = drop procedure enrich_b();
+ERROR = !DROP PROCEDURE: no such procedure 'enrich_b' ()
 
 
 # 15:17:52 >  
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to