Changeset: cc38ed15c4b3 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cc38ed15c4b3 Modified Files: sql/backends/monet5/sql.c sql/backends/monet5/sql.h sql/backends/monet5/sql.mal sql/backends/monet5/sql_scenario.c Branch: Oct2014 Log Message:
fix upgrade code. Make sure we recreate the views which depend on the dropped/recreated table returning functions. diffs (128 lines): diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c --- a/sql/backends/monet5/sql.c +++ b/sql/backends/monet5/sql.c @@ -916,25 +916,60 @@ UPGcreate_func(Client cntxt, MalBlkPtr m { mvc *sql = NULL; str msg = MAL_SUCCEED; - str func = *getArgReference_str(stk, pci, 1); + str sname = *getArgReference_str(stk, pci, 1), osname; + str func = *getArgReference_str(stk, pci, 2); stmt *s; if ((msg = getSQLContext(cntxt, mb, &sql, NULL)) != NULL) return msg; if ((msg = checkSQLContext(cntxt)) != NULL) return msg; + osname = cur_schema(sql)->base.name; + mvc_set_schema(sql, sname); s = sql_parse(sql, sa_create(), func, 0); if (s && s->type == st_catalog) { char *schema = ((stmt*)s->op1->op4.lval->h->data)->op4.aval->data.val.sval; sql_func *func = (sql_func*)((stmt*)s->op1->op4.lval->t->data)->op4.aval->data.val.pval; msg = create_func(sql, schema, func); + mvc_set_schema(sql, osname); } else { + mvc_set_schema(sql, osname); throw(SQL, "sql.catalog", "function creation failed '%s'", func); } return msg; } +str +UPGcreate_view(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + mvc *sql = NULL; + str msg = MAL_SUCCEED; + str sname = *getArgReference_str(stk, pci, 1), osname; + str view = *getArgReference_str(stk, pci, 2); + stmt *s; + + if ((msg = getSQLContext(cntxt, mb, &sql, NULL)) != NULL) + return msg; + if ((msg = checkSQLContext(cntxt)) != NULL) + return msg; + osname = cur_schema(sql)->base.name; + mvc_set_schema(sql, sname); + s = sql_parse(sql, sa_create(), view, 0); + if (s && s->type == st_catalog) { + char *schema = ((stmt*)s->op1->op4.lval->h->data)->op4.aval->data.val.sval; + sql_table *v = (sql_table*)((stmt*)s->op1->op4.lval->h->next->data)->op4.aval->data.val.pval; + int temp = ((stmt*)s->op1->op4.lval->t->data)->op4.aval->data.val.ival; + + msg = create_table_or_view(sql, schema, v, temp); + mvc_set_schema(sql, osname); + } else { + mvc_set_schema(sql, osname); + throw(SQL, "sql.catalog", "view creation failed '%s'", view); + } + return msg; +} + static char * create_trigger(mvc *sql, char *sname, char *tname, char *triggername, int time, int orientation, int event, char *old_name, char *new_name, char *condition, char *query) { diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h --- a/sql/backends/monet5/sql.h +++ b/sql/backends/monet5/sql.h @@ -111,6 +111,7 @@ sql5_export str mvc_drop_declared_tables sql5_export str UPGdrop_func(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str UPGcreate_func(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +sql5_export str UPGcreate_view(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str mvc_affected_rows_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str mvc_export_result_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal --- a/sql/backends/monet5/sql.mal +++ b/sql/backends/monet5/sql.mal @@ -309,10 +309,14 @@ pattern drop_func_upgrade_oct2014(id:int address UPGdrop_func comment "Drop the function identified by id, needed for the Oct2014 upgrade"; -pattern create_func_upgrade_oct2014(f:str) :int +pattern create_func_upgrade_oct2014(sname:str,f:str) :int address UPGcreate_func comment "Create the function described by f, needed for the Oct2014 upgrade"; +pattern create_view_upgrade_oct2014(sname:str,v:str) :int +address UPGcreate_view +comment "Create the view described by f, needed for the Oct2014 upgrade"; + pattern exportHead{unsafe}(s:streams, res_id:int) :void address mvc_export_head_wrap comment "Export a result (in order) to stream s"; diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -1094,17 +1094,26 @@ sql_update_oct2014(Client c) pos += snprintf(buf + pos, bufsize - pos, "delete from _tables where name like '#%%';\n"); /* all UNION functions need to be drop and recreated */ - pos += snprintf(buf + pos, bufsize - pos, "create table upgradeOct2014 as (select * from functions where type = 5 and language <> 0) with data;\n"); + /* keep views depending on UNION funcs */ + + pos += snprintf(buf + pos, bufsize - pos, "create table upgradeOct2014_views as (select s.name, t.query from tables t, schemas s where s.id = t.schema_id and t.id in (select d.depend_id from dependencies d where d.id in (select f.id from functions f where f.type = 5 and f.language <> 0) and d.depend_type = 5)) with data;\n"); + pos += snprintf(buf + pos, bufsize - pos, "create table upgradeOct2014 as (select s.name, f.func, f.id from functions f, schemas s where s.id = f.schema_id and f.type = 5 and f.language <> 0) with data;\n"); pos += snprintf(buf + pos, bufsize - pos, "create table upgradeOct2014_changes (c bigint);\n"); pos += snprintf(buf + pos, bufsize - pos, "create function drop_func_upgrade_oct2014( id integer ) returns int external name sql.drop_func_upgrade_oct2014;\n"); pos += snprintf(buf + pos, bufsize - pos, "insert into upgradeOct2014_changes select drop_func_upgrade_oct2014(id) from upgradeOct2014;\n"); pos += snprintf(buf + pos, bufsize - pos, "drop function drop_func_upgrade_oct2014;\n"); - pos += snprintf(buf + pos, bufsize - pos, "create function create_func_upgrade_oct2014( f string ) returns int external name sql.create_func_upgrade_oct2014;\n"); - pos += snprintf(buf + pos, bufsize - pos, "insert into upgradeOct2014_changes select create_func_upgrade_oct2014(func) from upgradeOct2014;\n"); + pos += snprintf(buf + pos, bufsize - pos, "create function create_func_upgrade_oct2014( sname string, f string ) returns int external name sql.create_func_upgrade_oct2014;\n"); + pos += snprintf(buf + pos, bufsize - pos, "insert into upgradeOct2014_changes select create_func_upgrade_oct2014(name, func) from upgradeOct2014;\n"); pos += snprintf(buf + pos, bufsize - pos, "drop function create_func_upgrade_oct2014;\n"); + /* recreate views depending on union funcs */ + pos += snprintf(buf + pos, bufsize - pos, "create function create_view_upgrade_oct2014( sname string, f string ) returns int external name sql.create_view_upgrade_oct2014;\n"); + pos += snprintf(buf + pos, bufsize - pos, "insert into upgradeOct2014_changes select create_view_upgrade_oct2014(name, query) from upgradeOct2014_views;\n"); + pos += snprintf(buf + pos, bufsize - pos, "drop function create_view_upgrade_oct2014;\n"); + + pos += snprintf(buf + pos, bufsize - pos, "drop table upgradeOct2014_views;\n"); pos += snprintf(buf + pos, bufsize - pos, "drop table upgradeOct2014_changes;\n"); pos += snprintf(buf + pos, bufsize - pos, "drop table upgradeOct2014;\n"); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list