Changeset: 67a09201ec2a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=67a09201ec2a
Modified Files:
        sql/backends/monet5/sql_upgrades.c
        sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out
        sql/test/testdb-upgrade/Tests/upgrade.stable.out
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
Branch: default
Log Message:

Split upgrade code in general and geom parts.


diffs (198 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
@@ -1117,20 +1117,18 @@ sql_update_jul2015(Client c)
 }
 
 static str
-sql_update_dec2015(Client c, int olddb)
+sql_update_jun2016(Client c)
 {
        size_t bufsize = 25000, pos = 0;
        char *buf = GDKmalloc(bufsize), *err = NULL;
        mvc *sql = ((backend*) c->sqlcontext)->mvc;
        ValRecord *schvar = stack_get_var(sql, "current_schema");
        char *schema = NULL;
-       geomsqlfix_fptr fixfunc;
 
        if (schvar)
                schema = strdup(schvar->val.sval);
        pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n");
 
-       /* insert upgrade code here */
 #if 0
        pos += snprintf(buf + pos, bufsize - pos, "drop procedure 
profiler_openstream(host string, port int);");
        pos += snprintf(buf + pos, bufsize - pos, "drop procedure 
profiler_stethoscope(ticks int);");
@@ -1204,18 +1202,41 @@ sql_update_dec2015(Client c, int olddb)
        pos += snprintf(buf + pos, bufsize - pos,
                        "insert into sys.systemfunctions (select id from 
sys.functions where name = 'storage' and schema_id = (select id from 
sys.schemas where name = 'sys') and id not in (select function_id from 
sys.systemfunctions));\n");
 
-       if ((fixfunc = geomsqlfix_get()) != NULL) {
-               str geomupgrade;
-               size_t gbufsize;
-
-               geomupgrade = (*fixfunc)(olddb);
-               gbufsize = strlen(geomupgrade) + 1;
-               buf = GDKrealloc(buf, bufsize + gbufsize);
-               bufsize += gbufsize;
-               pos += snprintf(buf + pos, bufsize - pos, "%s", geomupgrade);
-               GDKfree(geomupgrade);
+       if (schema) {
+               pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
+               free(schema);
        }
 
+       assert(pos < bufsize);
+       printf("Running database upgrade commands:\n%s\n", buf);
+       err = SQLstatementIntern(c, &buf, "update", 1, 0, NULL);
+       GDKfree(buf);
+       return err;             /* usually MAL_SUCCEED */
+}
+
+static str
+sql_update_geom(Client c, int olddb)
+{
+       size_t bufsize, pos = 0;
+       char *buf, *err = NULL;
+       char *geomupgrade;
+       mvc *sql = ((backend*) c->sqlcontext)->mvc;
+       ValRecord *schvar = stack_get_var(sql, "current_schema");
+       char *schema = NULL;
+       geomsqlfix_fptr fixfunc;
+
+       if ((fixfunc = geomsqlfix_get()) == NULL)
+               return NULL;
+
+       if (schvar)
+               schema = strdup(schvar->val.sval);
+
+       geomupgrade = (*fixfunc)(olddb);
+       bufsize = strlen(geomupgrade) + 512;
+       buf = GDKmalloc(bufsize);
+       pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n");
+       pos += snprintf(buf + pos, bufsize - pos, "%s", geomupgrade);
+       GDKfree(geomupgrade);
        if (schema) {
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
                free(schema);
@@ -1291,19 +1312,28 @@ SQLupgrades(Client c, mvc *m)
                }
        }
 
-       /* If the point type exists, but the geometry type does not exist
-        * any more at the "sys" schema (i.e., the first part of the upgrade has
-        * been completed succesfully), then move on to the second part */
-       if (find_sql_type(mvc_bind_schema(m, "sys"), "point") && 
-          (find_sql_type(mvc_bind_schema(m, "sys"), "geometry") == NULL)) {
-               if ((err = sql_update_dec2015(c, 1)) != NULL) {
+       sql_find_subtype(&tp, "clob", 0, 0);
+       if (!sql_bind_func(m->sa, mvc_bind_schema(m, "sys"), "storage", &tp, 
NULL, F_UNION)) {
+               if ((err = sql_update_jun2016(c)) !=NULL) {
                        fprintf(stderr, "!%s\n", err);
                        GDKfree(err);
                }
-       } else if (geomsqlfix_get() != NULL && 
+       }
+
+       /* If the point type exists, but the geometry type does not
+        * exist any more at the "sys" schema (i.e., the first part of
+        * the upgrade has been completed succesfully), then move on
+        * to the second part */
+       if (find_sql_type(mvc_bind_schema(m, "sys"), "point") &&
+          (find_sql_type(mvc_bind_schema(m, "sys"), "geometry") == NULL)) {
+               if ((err = sql_update_geom(c, 1)) != NULL) {
+                       fprintf(stderr, "!%s\n", err);
+                       GDKfree(err);
+               }
+       } else if (geomsqlfix_get() != NULL &&
                   !sql_find_subtype(&tp, "geometry", 0, 0)) {
                // the geom module is loaded but the database is not 
geom-enabled
-               if ((err = sql_update_dec2015(c, 0)) != NULL) {
+               if ((err = sql_update_geom(c, 0)) != NULL) {
                        fprintf(stderr, "!%s\n", err);
                        GDKfree(err);
                }
diff --git a/sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out 
b/sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out
--- a/sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out
+++ b/sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out
@@ -81,6 +81,10 @@ returns table (
 )
 external name sql."storage";
 insert into sys.systemfunctions (select id from sys.functions where name = 
'storage' and schema_id = (select id from sys.schemas where name = 'sys') and 
id not in (select function_id from sys.systemfunctions));
+set schema "testschema";
+
+Running database upgrade commands:
+set schema "sys";
 drop function "mbr";
 drop function "mbroverlaps";
 drop function "geomfromtext";
diff --git a/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out 
b/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
--- a/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
+++ b/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
@@ -78,6 +78,10 @@ returns table (
 )
 external name sql."storage";
 insert into sys.systemfunctions (select id from sys.functions where name = 
'storage' and schema_id = (select id from sys.schemas where name = 'sys') and 
id not in (select function_id from sys.systemfunctions));
+set schema "testschema";
+
+Running database upgrade commands:
+set schema "sys";
 drop function "mbr";
 drop function "mbroverlaps";
 drop function "geomfromtext";
diff --git a/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128 
b/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
--- a/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
+++ b/sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
@@ -123,6 +123,10 @@ returns table (
 )
 external name sql."storage";
 insert into sys.systemfunctions (select id from sys.functions where name = 
'storage' and schema_id = (select id from sys.schemas where name = 'sys') and 
id not in (select function_id from sys.systemfunctions));
+set schema "testschema";
+
+Running database upgrade commands:
+set schema "sys";
 drop function "mbr";
 drop function "mbroverlaps";
 drop function "geomfromtext";
diff --git a/sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out 
b/sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out
--- a/sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out
+++ b/sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out
@@ -83,6 +83,10 @@ returns table (
 )
 external name sql."storage";
 insert into sys.systemfunctions (select id from sys.functions where name = 
'storage' and schema_id = (select id from sys.schemas where name = 'sys') and 
id not in (select function_id from sys.systemfunctions));
+set schema "testschema";
+
+Running database upgrade commands:
+set schema "sys";
 drop function "mbr";
 drop function "mbroverlaps";
 drop function "geomfromtext";
diff --git a/sql/test/testdb-upgrade/Tests/upgrade.stable.out 
b/sql/test/testdb-upgrade/Tests/upgrade.stable.out
--- a/sql/test/testdb-upgrade/Tests/upgrade.stable.out
+++ b/sql/test/testdb-upgrade/Tests/upgrade.stable.out
@@ -75,6 +75,10 @@ returns table (
 )
 external name sql."storage";
 insert into sys.systemfunctions (select id from sys.functions where name = 
'storage' and schema_id = (select id from sys.schemas where name = 'sys') and 
id not in (select function_id from sys.systemfunctions));
+set schema "testschema";
+
+Running database upgrade commands:
+set schema "sys";
 drop function "mbr";
 drop function "mbroverlaps";
 drop function "geomfromtext";
diff --git a/sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128 
b/sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
--- a/sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
+++ b/sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
@@ -120,6 +120,10 @@ returns table (
 )
 external name sql."storage";
 insert into sys.systemfunctions (select id from sys.functions where name = 
'storage' and schema_id = (select id from sys.schemas where name = 'sys') and 
id not in (select function_id from sys.systemfunctions));
+set schema "testschema";
+
+Running database upgrade commands:
+set schema "sys";
 drop function "mbr";
 drop function "mbroverlaps";
 drop function "geomfromtext";
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to