Changeset: 3d106269871b for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3d106269871b 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 Branch: Jul2015 Log Message:
Add missing epoch functions in upgrade. diffs (126 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 @@ -1615,6 +1615,62 @@ sql_update_jul2015(Client c) return err; /* usually MAL_SUCCEED */ } +static str +sql_update_epoch(Client c, mvc *m) +{ + size_t bufsize = 1000, 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; + sql_subtype tp; + int n = 0; + + if (schvar) + schema = strdup(schvar->val.sval); + pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n"); + + sql_find_subtype(&tp, "bigint", 0, 0); + if (!sql_bind_func(m->sa, mvc_bind_schema(m, "sys"), "epoch", &tp, NULL, F_FUNC)) { + n++; + pos += snprintf(buf + pos, bufsize - pos, "\ +create function sys.\"epoch\"(sec BIGINT) returns TIMESTAMP external name timestamp.\"epoch\";\n"); + } + sql_find_subtype(&tp, "int", 0, 0); + if (!sql_bind_func(m->sa, mvc_bind_schema(m, "sys"), "epoch", &tp, NULL, F_FUNC)) { + n++; + pos += snprintf(buf + pos, bufsize - pos, "\ +create function sys.\"epoch\"(sec INT) returns TIMESTAMP external name timestamp.\"epoch\";\n"); + } + sql_find_subtype(&tp, "timestamp", 0, 0); + if (!sql_bind_func(m->sa, mvc_bind_schema(m, "sys"), "epoch", &tp, NULL, F_FUNC)) { + n++; + pos += snprintf(buf + pos, bufsize - pos, "\ +create function sys.\"epoch\"(ts TIMESTAMP) returns INT external name timestamp.\"epoch\";\n"); + } + sql_find_subtype(&tp, "timestamptz", 0, 0); + if (!sql_bind_func(m->sa, mvc_bind_schema(m, "sys"), "epoch", &tp, NULL, F_FUNC)) { + n++; + pos += snprintf(buf + pos, bufsize - pos, "\ +create function sys.\"epoch\"(ts TIMESTAMP WITH TIME ZONE) returns INT external name timestamp.\"epoch\";\n"); + } + pos += snprintf(buf + pos, bufsize - pos, + "insert into sys.systemfunctions (select id from sys.functions where name = 'epoch' and schema_id = (select id from sys.schemas where name = 'sys') and id not in (select function_id from sys.systemfunctions));\n"); + + if (schema) { + pos += snprintf(buf + pos, bufsize - pos, "set schema \"%s\";\n", schema); + free(schema); + } + + assert(pos < bufsize); + if (n) { + printf("Running database upgrade commands:\n%s\n", buf); + err = SQLstatementIntern(c, &buf, "update", 1, 0, NULL); + } + GDKfree(buf); + return err; /* usually MAL_SUCCEED */ +} + void SQLupgrades(Client c, mvc *m) { @@ -1713,4 +1769,10 @@ SQLupgrades(Client c, mvc *m) GDKfree(err); } } + + /* add missing epoch functions */ + if ((err = sql_update_epoch(c, m)) != 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 @@ -22,6 +22,12 @@ stdout of test 'upgrade` in directory 's # MonetDB/R module loaded Ready. +Running database upgrade commands: +set schema "sys"; +create function sys."epoch"(sec INT) returns TIMESTAMP external name timestamp."epoch"; +create function sys."epoch"(ts TIMESTAMP) returns INT external name timestamp."epoch"; +insert into sys.systemfunctions (select id from sys.functions where name = 'epoch' and schema_id = (select id from sys.schemas where name = 'sys') and id not in (select function_id from sys.systemfunctions)); +set schema "testschema"; # 15:45:53 > # 15:45:53 > "/usr/bin/python2" "upgrade.SQL.py" "upgrade" 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 @@ -19,6 +19,12 @@ stdout of test 'upgrade` in directory 's # MonetDB/SQL module loaded Ready. +Running database upgrade commands: +set schema "sys"; +create function sys."epoch"(sec INT) returns TIMESTAMP external name timestamp."epoch"; +create function sys."epoch"(ts TIMESTAMP) returns INT external name timestamp."epoch"; +insert into sys.systemfunctions (select id from sys.functions where name = 'epoch' and schema_id = (select id from sys.schemas where name = 'sys') and id not in (select function_id from sys.systemfunctions)); +set schema "testschema"; # 14:30:34 > # 14:30:34 > "/usr/bin/python2" "upgrade.SQL.py" "upgrade" 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 @@ -64,6 +64,13 @@ insert into sys.types values(7609, 'hge' update sys.types set digits = 18 where systemname = 'lng' and sqlname = 'decimal'; set schema "testschema"; +Running database upgrade commands: +set schema "sys"; +create function sys."epoch"(sec INT) returns TIMESTAMP external name timestamp."epoch"; +create function sys."epoch"(ts TIMESTAMP) returns INT external name timestamp."epoch"; +insert into sys.systemfunctions (select id from sys.functions where name = 'epoch' and schema_id = (select id from sys.schemas where name = 'sys') and id not in (select function_id from sys.systemfunctions)); +set schema "testschema"; + # 12:48:11 > # 12:48:11 > "/usr/bin/python2" "upgrade.SQL.py" "upgrade" _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list