Changeset: d4af5c3d7cb1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d4af5c3d7cb1
Modified Files:
        sql/server/rel_schema.c
        sql/test/Tests/comment-on-table.sql
        sql/test/Tests/comment-on-table.stable.err
        sql/test/Tests/comment-on-table.stable.out
        sql/test/Tests/comment-on-view.stable.err
Branch: comment-on
Log Message:

Forbid commenting on temporary tables

This would require having a tmp.comments as well and always
inserting in the right one, which adds complexity and test
cases and is just not worth it.


diffs (196 lines):

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
@@ -1967,6 +1967,27 @@ rel_alter_user(sql_allocator *sa, char *
        return rel;
 }
 
+static sql_schema*
+current_or_designated_schema(mvc *sql, char *name) {
+       sql_schema *s;
+
+       if (!name)
+               return cur_schema(sql);
+
+       s = mvc_bind_schema(sql, name);
+       if (!s) {
+               sql_error(sql, 02, "3F000!COMMENT ON:no such schema: %s", name);
+               return NULL;
+       }
+
+       if (strcmp(s->base.name, "tmp") == 0) {
+               sql_error(sql, 2, "3F000!COMMENT ON tmp object not allowed");
+               return NULL;
+       }
+
+       return s;
+}
+
 static sqlid
 rel_find_designated_schema(mvc *sql, symbol *sym) {
        char *sname;
@@ -1985,19 +2006,14 @@ static sqlid
 rel_find_designated_table(mvc *sql, symbol *sym) {
        dlist *qname;
        sql_schema *s;
-       char *sname;
        char *tname;
        sql_table *t;
        int want_table = sym->token == SQL_TABLE;
 
        assert(sym->type == type_list);
        qname = sym->data.lval;
-       s = cur_schema(sql);
-       sname = qname_schema(qname);
-       if (sname && !(s = mvc_bind_schema(sql, sname))) {
-               sql_error(sql, 02, "3F000!COMMENT ON:no such schema: %s", 
sname);
+       if (!(s = current_or_designated_schema(sql, qname_schema(qname))))
                return 0;
-       }
        tname = qname_table(qname);
        t = mvc_bind_table(sql, s, tname);
        if (t && !want_table == !isKindOfTable(t))      /* comparing booleans 
can be tricky */
@@ -2033,11 +2049,8 @@ rel_find_designated_column(mvc *sql, sym
                assert(colname->h->next->next->type == type_string);
                cname = colname->h->next->next->data.sval;
        }
-       s = cur_schema(sql);
-       if (sname && !(s = mvc_bind_schema(sql, sname))) {
-               sql_error(sql, 02, "3F000!COMMENT ON:no such schema: %s", 
sname);
+       if (!(s = current_or_designated_schema(sql, sname)))
                return 0;
-       }
        if (!(t = mvc_bind_table(sql, s, tname))) {
                sql_error(sql, 02, "42S02!COMMENT ON:no such table: %s.%s", 
s->base.name, tname);
                return 0;
@@ -2053,18 +2066,13 @@ static sqlid
 rel_find_designated_index(mvc *sql, symbol *sym) {
        dlist *qname;
        sql_schema *s;
-       char *sname;
        char *iname;
        sql_idx *idx;
 
        assert(sym->type == type_list);
        qname = sym->data.lval;
-       s = cur_schema(sql);
-       sname = qname_schema(qname);
-       if (sname && !(s = mvc_bind_schema(sql, sname))) {
-               sql_error(sql, 02, "3F000!COMMENT ON:no such schema: %s", 
sname);
+       if (!(s = current_or_designated_schema(sql, qname_schema(qname))))
                return 0;
-       }
        iname = qname_table(qname);
        idx = mvc_bind_idx(sql, s, iname);
        if (idx)
@@ -2081,18 +2089,13 @@ rel_find_designated_sequence(mvc *sql, s
        (void)sym;
        dlist *qname;
        sql_schema *s;
-       char *sname;
        char *seqname;
        sql_sequence *seq;
 
        assert(sym->type == type_list);
        qname = sym->data.lval;
-       s = cur_schema(sql);
-       sname = qname_schema(qname);
-       if (sname && !(s = mvc_bind_schema(sql, sname))) {
-               sql_error(sql, 02, "42000!COMMENT ON:no such schema: %s", 
sname);
+       if (!(s = current_or_designated_schema(sql, qname_schema(qname))))
                return 0;
-       }
        seqname = qname_table(qname);
        seq = find_sql_sequence(s, seqname);
        if (seq)
@@ -2112,7 +2115,6 @@ rel_find_designated_routine(mvc *sql, sy
        dlist *qname;
        dlist *typelist;
        int func_type;
-       char *sname;
        sql_schema *s;
        char *fname;
        sql_func *func;
@@ -2125,12 +2127,8 @@ rel_find_designated_routine(mvc *sql, sy
        typelist = designator->h->next->data.lval;
        func_type = designator->h->next->next->data.i_val;
 
-       s = cur_schema(sql);
-       sname = qname_schema(qname);
-       if (sname && !(s = mvc_bind_schema(sql, sname))) {
-               sql_error(sql, 02, "3F000!COMMENT ON:no such schema: %s", 
sname);
+       if (!(s = current_or_designated_schema(sql, qname_schema(qname))))
                return 0;
-       }
 
        fname = qname_func(qname);
        func = resolve_func(sql, s, fname, typelist, func_type, "COMMENT");
diff --git a/sql/test/Tests/comment-on-table.sql 
b/sql/test/Tests/comment-on-table.sql
--- a/sql/test/Tests/comment-on-table.sql
+++ b/sql/test/Tests/comment-on-table.sql
@@ -72,3 +72,12 @@ COMMENT ON TABLE rem IS 'remote table';
 CREATE MERGE TABLE mrg (i INT);
 COMMENT ON TABLE mrg IS 'merge table';
 SELECT * FROM new_comments();
+DROP TABLE rem;
+DROP TABLE mrg;
+SELECT * FROM new_comments();
+
+-- commenting on temporary tables is forbidden
+CREATE TEMPORARY TABLE banana (i INT);
+COMMENT ON TABLE tmp.banana IS 'temp table';
+COMMENT ON COLUMN tmp.banana.i IS 'temp table column';
+SELECT * FROM new_comments();
diff --git a/sql/test/Tests/comment-on-table.stable.err 
b/sql/test/Tests/comment-on-table.stable.err
--- a/sql/test/Tests/comment-on-table.stable.err
+++ b/sql/test/Tests/comment-on-table.stable.err
@@ -30,6 +30,14 @@ stderr of test 'comment-on-table` in dir
 MAPI  = (monetdb) /var/tmp/mtest-29570/.s.monetdb.39712
 QUERY = COMMENT ON VIEW sch.tab IS 'a mistake';
 ERROR = !COMMENT ON:no such view: sch.tab
+CODE  = 42S02
+MAPI  = (monetdb) /var/tmp/mtest-46582/.s.monetdb.36762
+QUERY = COMMENT ON TABLE tmp.banana IS 'temp table';
+ERROR = !COMMENT ON tmp object not allowed
+CODE  = 3F000
+MAPI  = (monetdb) /var/tmp/mtest-46582/.s.monetdb.36762
+QUERY = COMMENT ON COLUMN tmp.banana.i IS 'temp table column';
+ERROR = !COMMENT ON tmp object not allowed
 CODE  = 3F000
 
 # 11:31:42 >  
diff --git a/sql/test/Tests/comment-on-table.stable.out 
b/sql/test/Tests/comment-on-table.stable.out
--- a/sql/test/Tests/comment-on-table.stable.out
+++ b/sql/test/Tests/comment-on-table.stable.out
@@ -121,6 +121,19 @@ Ready.
 % 3,   12,     12 # length
 [ "rem",       "REMOTE TABLE", "remote table"  ]
 [ "mrg",       "MERGE TABLE",  "merge table"   ]
+#DROP TABLE rem;
+#DROP TABLE mrg;
+#SELECT * FROM new_comments();
+% .L1, .L1,    .L1 # table_name
+% name,        source, remark # name
+% varchar,     varchar,        clob # type
+% 0,   0,      0 # length
+#CREATE TEMPORARY TABLE banana (i INT);
+#SELECT * FROM new_comments();
+% .L1, .L1,    .L1 # table_name
+% name,        source, remark # name
+% varchar,     varchar,        clob # type
+% 0,   0,      0 # length
 
 # 14:25:22 >  
 # 14:25:22 >  "Done."
diff --git a/sql/test/Tests/comment-on-view.stable.err 
b/sql/test/Tests/comment-on-view.stable.err
--- a/sql/test/Tests/comment-on-view.stable.err
+++ b/sql/test/Tests/comment-on-view.stable.err
@@ -31,7 +31,7 @@ stderr of test 'comment-on-view` in dire
 MAPI  = (monetdb) /var/tmp/mtest-29646/.s.monetdb.36441
 QUERY = COMMENT ON TABLE vivi is 'a mistake';
 ERROR = !COMMENT ON:no such table: sch.vivi
-CODE  = 3F000
+CODE  = 42S02
 
 # 16:43:54 >  
 # 16:43:54 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to