Changeset: 86825c1a26ff for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=86825c1a26ff
Modified Files:
        sql/backends/monet5/sql_cat.c
        sql/server/rel_psm.c
        sql/server/rel_schema.c
        sql/test/Tests/ifexists-views.sql
        testing/Mtest.py.in
Branch: linear-hashing
Log Message:

Merged with Nov2019


diffs (263 lines):

diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -462,13 +462,13 @@ static char *
 drop_trigger(mvc *sql, char *sname, char *tname, int if_exists)
 {
        sql_trigger *tri = NULL;
-       sql_schema *s = NULL;
+       sql_schema *s = cur_schema(sql);
 
-       if (sname && !(s = mvc_bind_schema(sql, sname)))
+       if (sname && !(s = mvc_bind_schema(sql, sname))) {
+               if (if_exists)
+                       return MAL_SUCCEED;
                throw(SQL,"sql.drop_trigger",SQLSTATE(3F000) "DROP TRIGGER: no 
such schema '%s'", sname);
-       if (!s)
-               s = cur_schema(sql);
-       assert(s);
+       }
        if (!mvc_schema_privs(sql, s))
                throw(SQL,"sql.drop_trigger",SQLSTATE(3F000) "DROP TRIGGER: 
access denied for %s to schema '%s'", stack_get_string(sql, "current_user"), 
s->base.name);
 
@@ -485,14 +485,15 @@ drop_trigger(mvc *sql, char *sname, char
 static char *
 drop_table(mvc *sql, char *sname, char *tname, int drop_action, int if_exists)
 {
-       sql_schema *s = NULL;
+       sql_schema *s = cur_schema(sql);
        sql_table *t = NULL;
        node *n;
 
-       if (sname && !(s = mvc_bind_schema(sql, sname)))
+       if (sname && !(s = mvc_bind_schema(sql, sname))) {
+               if (if_exists)
+                       return MAL_SUCCEED;
                throw(SQL,"sql.drop_table",SQLSTATE(3F000) "DROP TABLE: no such 
schema '%s'", sname);
-       if (!s)
-               s = cur_schema(sql);
+       }
        t = mvc_bind_table(sql, s, tname);
        if (!t && !sname) {
                s = tmp_schema(sql);
@@ -540,21 +541,20 @@ static char *
 drop_view(mvc *sql, char *sname, char *tname, int drop_action, int if_exists)
 {
        sql_table *t = NULL;
-       sql_schema *ss = NULL;
+       sql_schema *ss = cur_schema(sql);
 
-       if (sname != NULL && (ss = mvc_bind_schema(sql, sname)) == NULL)
+       if (sname && !(ss = mvc_bind_schema(sql, sname))) {
+               if (if_exists)
+                       return MAL_SUCCEED;
                throw(SQL,"sql.dropview", SQLSTATE(3F000) "DROP VIEW: no such 
schema '%s'", sname);
-
-       if (ss == NULL)
-               ss = cur_schema(sql);
+       }
 
        t = mvc_bind_table(sql, ss, tname);
        if (!mvc_schema_privs(sql, ss) && !(isTempSchema(ss) && t && 
t->persistence == SQL_LOCAL_TEMP)) {
                throw(SQL,"sql.dropview", SQLSTATE(42000) "DROP VIEW: access 
denied for %s to schema '%s'", stack_get_string(sql, "current_user"), 
ss->base.name);
        } else if (!t) {
-               if (if_exists){
+               if (if_exists)
                        return MAL_SUCCEED;
-               }
                throw(SQL,"sql.drop_view",SQLSTATE(42S02) "DROP VIEW: unknown 
view '%s'", tname);
        } else if (!isView(t)) {
                throw(SQL,"sql.drop_view", SQLSTATE(42000) "DROP VIEW: unable 
to drop view '%s': is a table", tname);
@@ -709,7 +709,7 @@ drop_seq(mvc *sql, char *sname, char *na
 static str
 drop_func(mvc *sql, char *sname, char *name, sqlid fid, sql_ftype type, int 
action)
 {
-       sql_schema *s = NULL;
+       sql_schema *s = cur_schema(sql);
        char is_aggr = (type == F_AGGR);
        char is_func = (type != F_PROC);
        char *F = is_aggr ? "AGGREGATE" : (is_func ? "FUNCTION" : "PROCEDURE");
@@ -717,10 +717,11 @@ drop_func(mvc *sql, char *sname, char *n
        char *KF = type == F_FILT ? "FILTER " : type == F_UNION ? "UNION " : "";
        char *kf = type == F_FILT ? "filter " : type == F_UNION ? "union " : "";
 
-       if (sname && !(s = mvc_bind_schema(sql, sname)))
+       if (sname && !(s = mvc_bind_schema(sql, sname))) {
+               if (fid == -2) /* if exists option */
+                       return MAL_SUCCEED;
                throw(SQL,"sql.drop_func", SQLSTATE(3F000) "DROP %s%s: no such 
schema '%s'", KF, F, sname);
-       if (!s)
-               s = cur_schema(sql);
+       }
        if (fid >= 0) {
                node *n = find_sql_func_node(s, fid);
                if (n) {
@@ -735,9 +736,9 @@ drop_func(mvc *sql, char *sname, char *n
                        if (mvc_drop_func(sql, s, func, action))
                                throw(SQL,"sql.drop_func", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                }
-       } else if (fid == -2) { //if exists option
+       } else if (fid == -2) { /* if exists option */
                return MAL_SUCCEED;
-       } else { //fid == -1
+       } else { /* fid == -1 */
                node *n = NULL;
                list *list_func = schema_bind_func(sql, s, name, type);
                int res;
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
@@ -1106,30 +1106,32 @@ rel_drop_func(mvc *sql, dlist *qname, dl
 {
        const char *name = qname_table(qname);
        const char *sname = qname_schema(qname);
-       sql_schema *s = NULL;
+       sql_schema *s = cur_schema(sql);
        sql_func *func = NULL;
 
        char is_aggr = (type == F_AGGR);
        char is_func = (type != F_PROC);
        char *F = is_aggr?"AGGREGATE":(is_func?"FUNCTION":"PROCEDURE");
        char *KF = type==F_FILT?"FILTER ": type==F_UNION?"UNION ": "";
-
-       if (sname && !(s = mvc_bind_schema(sql, sname)))
-               return sql_error(sql, 02, SQLSTATE(3F000) "DROP %s%s: no such 
schema '%s'", KF, F, sname);
+       char *f = is_aggr?"aggregate":(is_func?"function":"procedure");
+       char *kf = type==F_FILT?"filter ": type==F_UNION?"union ": "";
 
-       if (s == NULL) 
-               s =  cur_schema(sql);
-       
-       func = resolve_func(sql, s, name, typelist, type, "DROP", if_exists);
+       if (sname && !(s = mvc_bind_schema(sql, sname))) {
+               if (!if_exists)
+                       return sql_error(sql, 02, SQLSTATE(3F000) "DROP %s%s: 
no such schema '%s'", KF, F, sname);
+       }
+
+       if (s)
+               func = resolve_func(sql, s, name, typelist, type, "DROP", 
if_exists);
        if (!func && !sname) {
                s = tmp_schema(sql);
                func = resolve_func(sql, s, name, typelist, type, "DROP", 
if_exists);
        }
-       if (func)
+       if (func && s)
                return rel_drop_function(sql->sa, s->base.name, name, 
func->base.id, type, drop_action);
-       else if(if_exists && !sql->session->status)
-               return rel_drop_function(sql->sa, s->base.name, name, -2, type, 
drop_action);
-       return NULL;
+       if (if_exists)
+               return rel_drop_function(sql->sa, sname, name, -2, type, 
drop_action);
+       return sql_error(sql, 02, SQLSTATE(42000) "DROP %s%s: %s%s %s not 
found", KF, F, kf, f, name);
 }
 
 static sql_rel* 
@@ -1358,11 +1360,11 @@ drop_trigger(mvc *sql, dlist *qname, int
        const char *tname = qname_table(qname);
        sql_schema *ss = cur_schema(sql);
 
-       if (!sname)
-               sname = ss->base.name;
-
-       if (sname && !(ss = mvc_bind_schema(sql, sname)))
+       if (sname && !(ss = mvc_bind_schema(sql, sname))) {
+               if (if_exists)
+                       return rel_drop_trigger(sql, sname, tname, if_exists);
                return sql_error(sql, 02, SQLSTATE(3F000) "DROP TRIGGER: no 
such schema '%s'", sname);
+       }
 
        if (!mvc_schema_privs(sql, ss)) 
                return sql_error(sql, 02, SQLSTATE(3F000) "DROP TRIGGER: access 
denied for %s to schema '%s'", stack_get_string(sql, "current_user"), 
ss->base.name);
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -1053,12 +1053,10 @@ rel_create_table(sql_query *query, sql_s
                sname = s->base.name;
 
        if (mvc_bind_table(sql, s, name)) {
-               if (if_not_exists) {
+               char *cd = (temp == SQL_DECLARED_TABLE)?"DECLARE":"CREATE";
+               if (if_not_exists)
                        return rel_psm_block(sql->sa, new_exp_list(sql->sa));
-               } else {
-                       char *cd = (temp == 
SQL_DECLARED_TABLE)?"DECLARE":"CREATE";
-                       return sql_error(sql, 02, SQLSTATE(42S01) "%s TABLE: 
name '%s' already in use", cd, name);
-               }
+               return sql_error(sql, 02, SQLSTATE(42S01) "%s TABLE: name '%s' 
already in use", cd, name);
        } else if (temp != SQL_DECLARED_TABLE && (!mvc_schema_privs(sql, s) && 
!(isTempSchema(s) && temp == SQL_LOCAL_TEMP))){
                return sql_error(sql, 02, SQLSTATE(42000) "CREATE TABLE: 
insufficient privileges for user '%s' in schema '%s'", stack_get_string(sql, 
"current_user"), s->base.name);
        } else if (table_elements_or_subquery->token == SQL_CREATE_TABLE) {
@@ -1375,24 +1373,17 @@ rel_create_schema(sql_query *query, dlis
        char *auth = schema_auth(auth_name);
        sqlid auth_id = sql->role_id;
 
-       if (auth && (auth_id = sql_find_auth(sql, auth)) < 0) {
-               sql_error(sql, 02, SQLSTATE(28000) "CREATE SCHEMA: no such 
authorization '%s'", auth);
-               return NULL;
-       }
-       if (sql->user_id != USER_MONETDB && sql->role_id != ROLE_SYSADMIN) {
-               sql_error(sql, 02, SQLSTATE(42000) "CREATE SCHEMA: insufficient 
privileges for user '%s'", stack_get_string(sql, "current_user"));
-               return NULL;
-       }
+       if (auth && (auth_id = sql_find_auth(sql, auth)) < 0)
+               return sql_error(sql, 02, SQLSTATE(28000) "CREATE SCHEMA: no 
such authorization '%s'", auth);
+       if (sql->user_id != USER_MONETDB && sql->role_id != ROLE_SYSADMIN)
+               return sql_error(sql, 02, SQLSTATE(42000) "CREATE SCHEMA: 
insufficient privileges for user '%s'", stack_get_string(sql, "current_user"));
        if (!name) 
                name = auth;
        assert(name);
        if (mvc_bind_schema(sql, name)) {
-               if (!if_not_exists) {
-                       sql_error(sql, 02, SQLSTATE(3F000) "CREATE SCHEMA: name 
'%s' already in use", name);
-                       return NULL;
-               } else {
-                       return rel_psm_block(sql->sa, new_exp_list(sql->sa));
-               }
+               if (!if_not_exists)
+                       return sql_error(sql, 02, SQLSTATE(3F000) "CREATE 
SCHEMA: name '%s' already in use", name);
+               return rel_psm_block(sql->sa, new_exp_list(sql->sa));
        } else {
                sql_schema *os = sql->session->schema;
                dnode *n;
@@ -1452,7 +1443,7 @@ sql_alter_table(sql_query *query, dlist 
        if ((t = mvc_bind_table(sql, s, tname)) == NULL) {
                if (mvc_bind_table(sql, mvc_bind_schema(sql, "tmp"), tname) != 
NULL) 
                        return sql_error(sql, 02, SQLSTATE(42S02) "ALTER TABLE: 
not supported on TEMPORARY table '%s'", tname);
-               if(if_exists)
+               if (if_exists)
                        return rel_psm_block(sql->sa, new_exp_list(sql->sa));
                return sql_error(sql, 02, SQLSTATE(42S02) "ALTER TABLE: no such 
table '%s' in schema '%s'", tname, s->base.name);
        } else {
diff --git a/sql/test/Tests/ifexists-views.sql 
b/sql/test/Tests/ifexists-views.sql
--- a/sql/test/Tests/ifexists-views.sql
+++ b/sql/test/Tests/ifexists-views.sql
@@ -14,4 +14,9 @@ DROP VIEW IF EXISTS view2;
 DROP VIEW view2; -- should fail
 SELECT * FROM view2; -- should fail
 
+DROP FUNCTION IF EXISTS "idontexist"."idontexist"();
+DROP FUNCTION IF EXISTS "idontexist"."idontexist"(INT);
+DROP FUNCTION IF EXISTS "sys"."idontexist"();
+DROP FUNCTION IF EXISTS "sys"."idontexist"(INT);
+
 DROP TABLE tab0;
diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -2867,12 +2867,15 @@ class ServerClass:
         return self.proc.poll()
 
     def terminate(self):
+        self.timer.cancel()
+        t = Timer(60, killProc, args = [self.proc, self.errfile, self.cmd])
+        t.start()
         if os.name == 'nt':
             self.proc.send_signal(signal.CTRL_BREAK_EVENT)
         else:
             self.proc.terminate()
         self.proc.wait()
-        self.timer.cancel()
+        t.cancel()
         self.code = returnCode(self.proc, self.errfile)
 
     def LaunchIt(self):
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to