Changeset: 97692de4df91 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=97692de4df91
Modified Files:
        sql/backends/monet5/sql_upgrades.c
Branch: default
Log Message:

It now also really calls sql_remove_environment_func() when the 
sys.environment() function exists.


diffs (52 lines):

diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -1036,25 +1036,32 @@ sql_update_default_geom(Client c, mvc *s
 }
 
 static str
-sql_remove_environment_func(Client c)
+sql_remove_environment_func(Client c, mvc *sql)
 {
+       sql_schema *s = NULL;
+       sql_table *t = NULL;
        size_t bufsize = 1000, pos = 0;
        char *buf = GDKmalloc(bufsize), *err = NULL;
        if (buf== NULL)
                throw(SQL, "sql_remove_environment_func", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
 
+       /* because issueing sql: "drop view sys.environment cascade;" fails 
with with error: !SQLException:sql.drop_view:42000!DROP VIEW: cannot drop 
system view 'environment'
+          we need to drop the system view using internal function: 
mvc_drop_table() */
+       s = mvc_bind_schema(sql, "sys");
+       t = mvc_bind_table(sql, s, "environment");
+       mvc_drop_table(sql, s, t, 1);   // drop the system view: 
sys.environment cascade
+
        pos += snprintf(buf + pos, bufsize - pos,
-                       "drop view sys.environment cascade;\n"
-                       "drop function sys.environment() cascade\n"
+                       "drop function sys.environment() cascade;\n"
                        "create view sys.environment as select * from 
sys.env();\n"
                        "GRANT SELECT ON sys.environment TO PUBLIC;\n"
-                       "update sys._tables set system = true where name = 
'environment' and schema_id in (select id from schemas where name = 'sys');\n");
+                       "update sys._tables set system = true where system = 
false and name = 'environment' and schema_id in (select id from schemas where 
name = 'sys');\n");
 
        pos += snprintf(buf + pos, bufsize - pos,
                        "delete from sys.systemfunctions where function_id not 
in (select id from sys.functions);\n");
 
        assert(pos < bufsize);
-       printf("Running database upgrade commands:\n%s\n", buf);
+       printf("Running database upgrade commands:\ndrop view sys.environment 
cascade;\n%s\n", buf);
        err = SQLstatementIntern(c, &buf, "update", 1, 0, NULL);
        GDKfree(buf);
        return err;             /* usually MAL_SUCCEED */
@@ -1176,8 +1183,8 @@ SQLupgrades(Client c, mvc *m)
                }
        }
 
-       if (sql_bind_func(m->sa, s, "environment", NULL, NULL, F_FUNC)) {
-               if ((err = sql_remove_environment_func(c)) != NULL) {
+       if (sql_bind_func_(m->sa, s, "environment", NULL, F_UNION)) {
+               if ((err = sql_remove_environment_func(c, m)) != NULL) {
                        fprintf(stderr, "!%s\n", err);
                        freeException(err);
                }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to