Changeset: ab619c893147 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ab619c893147
Modified Files:
        sql/backends/monet5/sql_cat.c
        sql/server/rel_schema.c
        sql/test/merge-partitions/Tests/mergepart01.stable.err
        sql/test/mergetables/Tests/mergeinit.sql
        sql/test/mergetables/Tests/mergeinit.stable.err
Branch: Apr2019
Log Message:

Cannot add a view into a merge/remote/replica table. This fixes bug 6685.


diffs (78 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
@@ -154,8 +154,10 @@ validate_alter_table_add_table(mvc *sql,
                node *n = cs_find_id(&rmt->members, rpt->base.id);
                const char *errtable = TABLE_TYPE_DESCRIPTION(rmt->type, 
rmt->properties);
 
+               if (isView(rpt))
+                       throw(SQL,call,SQLSTATE(42000) "ALTER TABLE: can't add 
a view into a %s", errtable);
                if (ms->base.id != ps->base.id)
-                       throw(SQL,call,SQLSTATE(42000) "ALTER TABLE: all 
partitions of '%s.%s' must be part of schema '%s'", msname, mtname, msname);
+                       throw(SQL,call,SQLSTATE(42000) "ALTER TABLE: all 
children tables of '%s.%s' must be part of schema '%s'", msname, mtname, 
msname);
                if (n && !update)
                        throw(SQL,call,SQLSTATE(42S02) "ALTER TABLE: table 
'%s.%s' is already part of the %s '%s.%s'", psname, ptname, errtable, msname, 
mtname);
                if (!n && update)
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
@@ -1489,9 +1489,12 @@ sql_alter_table(mvc *sql, dlist *dl, dli
                        if (te->token == SQL_TABLE) {
                                symbol *extra = 
dl->h->next->next->next->data.sym;
 
+                               if (isView(pt))
+                                       return sql_error(sql, 02, 
SQLSTATE(42000) "ALTER TABLE: can't add a view into a %s",
+                                                                        
TABLE_TYPE_DESCRIPTION(t->type, t->properties));
                                if (strcmp(sname, nsname) != 0)
-                                       return sql_error(sql, 02, 
SQLSTATE(42000) "ALTER TABLE: all partitions of '%s.%s' must be part of "
-                                                                        
"schema '%s'", sname, tname, sname);
+                                       return sql_error(sql, 02, 
SQLSTATE(42000) "ALTER TABLE: all children tables of '%s.%s' must be "
+                                                                        "part 
of schema '%s'", sname, tname, sname);
                                if (!extra)
                                        return rel_alter_table(sql->sa, 
DDL_ALTER_TABLE_ADD_TABLE, sname, tname, nsname, ntname, 0);
 
diff --git a/sql/test/merge-partitions/Tests/mergepart01.stable.err 
b/sql/test/merge-partitions/Tests/mergepart01.stable.err
--- a/sql/test/merge-partitions/Tests/mergepart01.stable.err
+++ b/sql/test/merge-partitions/Tests/mergepart01.stable.err
@@ -67,7 +67,7 @@ ERROR = !ALTER TABLE: unable to rename t
 CODE  = 2BM37
 MAPI  = (monetdb) /var/tmp/mtest-19335/.s.monetdb.38088
 QUERY = ALTER TABLE testme ADD TABLE other_schema.subtable1 AS PARTITION 
BETWEEN 4 AND 23; --error, all the tables must belong to the same schema
-ERROR = !ALTER TABLE: all partitions of 'sys.testme' must be part of schema 
'sys'
+ERROR = !ALTER TABLE: all children tables of 'sys.testme' must be part of 
schema 'sys'
 CODE  = 42000
 
 # 17:07:39 >  
diff --git a/sql/test/mergetables/Tests/mergeinit.sql 
b/sql/test/mergetables/Tests/mergeinit.sql
--- a/sql/test/mergetables/Tests/mergeinit.sql
+++ b/sql/test/mergetables/Tests/mergeinit.sql
@@ -1,12 +1,14 @@
 CREATE TABLE part1 ( x double, y double, z double);
 CREATE TABLE part2 ( x double, y double, z double);
+CREATE VIEW wrong as (select cast(1 as double), cast(2 as double), cast(3 as 
double));
 
 CREATE MERGE TABLE complete ( x double, y double, z double);
 
 ALTER TABLE complete ADD TABLE part1;
 ALTER TABLE complete ADD TABLE part2;
-
+ALTER TABLE complete ADD TABLE wrong; --error, cannot add views to a merge 
table
 
 DROP TABLE complete;
 DROP TABLE part1;
 DROP TABLE part2;
+DROP VIEW wrong;
diff --git a/sql/test/mergetables/Tests/mergeinit.stable.err 
b/sql/test/mergetables/Tests/mergeinit.stable.err
--- a/sql/test/mergetables/Tests/mergeinit.stable.err
+++ b/sql/test/mergetables/Tests/mergeinit.stable.err
@@ -30,6 +30,10 @@ stderr of test 'mergeinit` in directory 
 # 16:18:31 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-10817" "--port=39884"
 # 16:18:31 >  
 
+MAPI  = (monetdb) /var/tmp/mtest-3039/.s.monetdb.32377
+QUERY = ALTER TABLE complete ADD TABLE wrong; --error, cannot add views to a 
merge table
+ERROR = !ALTER TABLE: can't add a view into a MERGE TABLE
+CODE  = 42000
 
 # 16:18:31 >  
 # 16:18:31 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to