Changeset: c381ac083667 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c381ac083667
Modified Files:
sql/backends/monet5/sql_scenario.c
sql/backends/monet5/sql_upgrades.c
sql/backends/monet5/sql_upgrades.h
sql/scripts/99_system.sql
Branch: default
Log Message:
Merge with Nov2019
diffs (truncated from 389 to 300 lines):
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
@@ -507,8 +507,8 @@ SQLinit(Client c)
slash_2_dir_sep(path);
fullname = MSP_locate_sqlscript(path, 1);
if (fullname) {
- str filename = fullname;
- str p, n, newmsg= MAL_SUCCEED;
+ str filename = fullname, p, n;
+
fprintf(stdout, "# SQL catalog created, loading sql
scripts once\n");
do {
stream *fd = NULL;
@@ -531,31 +531,40 @@ SQLinit(Client c)
sz = getFileSize(fd);
if (sz > (size_t) 1 << 29) {
close_stream(fd);
- newmsg = createException(MAL,
"createdb", SQLSTATE(42000) "File %s too large to process", filename);
+ msg = createException(MAL,
"createdb", SQLSTATE(42000) "File %s too large to process", filename);
} else {
bstream *bfd = NULL;
- if((bfd = bstream_create(fd, sz
== 0 ? (size_t) (128 * BLOCK) : sz)) == NULL) {
+ if ((bfd = bstream_create(fd,
sz == 0 ? (size_t) (128 * BLOCK) : sz)) == NULL) {
close_stream(fd);
- newmsg =
createException(MAL, "createdb", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ msg =
createException(MAL, "createdb", SQLSTATE(HY001) MAL_MALLOC_FAIL);
} else {
if (bstream_next(bfd)
>= 0)
- newmsg =
SQLstatementIntern(c, &bfd->buf, "sql.init", TRUE, FALSE, NULL);
+ msg =
SQLstatementIntern(c, &bfd->buf, "sql.init", TRUE, FALSE, NULL);
bstream_destroy(bfd);
}
}
- if (m->sa)
- sa_destroy(m->sa);
- m->sa = NULL;
- if (newmsg){
- fprintf(stderr,"%s",newmsg);
- freeException(newmsg);
- }
- }
- } while (p);
+ } else
+ msg = createException(MAL, "createdb",
SQLSTATE(HY001) "Couldn't open file %s", filename);
+ } while (p && msg == MAL_SUCCEED);
GDKfree(fullname);
} else
- fprintf(stderr, "!could not read createdb.sql\n");
+ msg = createException(MAL, "createdb", SQLSTATE(HY001)
"Could not read createdb.sql");
+
+ /* Commit after all the startup scripts have been processed */
+ assert(m->session->tr->active);
+ if (mvc_status(m) < 0 || msg)
+ other = mvc_rollback(m, 0, NULL, false);
+ else
+ other = mvc_commit(m, 0, NULL, false);
+
+ if (other && !msg) /* 'msg' variable might be set or not, as
well as 'other'. Throw the earliest one */
+ msg = other;
+ else if (other)
+ freeException(other);
+
+ if (msg)
+ fprintf(stderr, "%s", msg);
#endif
} else { /* handle upgrades */
if (!m->sa)
@@ -564,10 +573,10 @@ SQLinit(Client c)
msg = createException(MAL, "createdb", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
} else if (maybeupgrade) {
if ((msg = SQLtrans(m)) == MAL_SUCCEED) {
- SQLupgrades(c,m);
+ int res = SQLupgrades(c, m);
/* Commit at the end of the upgrade */
assert(m->session->tr->active);
- if (mvc_status(m) < 0)
+ if (mvc_status(m) < 0 || res)
msg = mvc_rollback(m, 0, NULL, false);
else
msg = mvc_commit(m, 0, NULL, false);
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
@@ -2385,7 +2385,7 @@ sql_update_default(Client c, mvc *sql, c
return err; /* usually MAL_SUCCEED */
}
-void
+int
SQLupgrades(Client c, mvc *m)
{
sql_subtype tp;
@@ -2395,26 +2395,28 @@ SQLupgrades(Client c, mvc *m)
sql_table *t;
sql_column *col;
bool systabfixed = false;
+ int res = 0;
if (!prev_schema) {
fprintf(stderr, "!Allocation failure while running SQL
upgrades\n");
- return;
+ res = -1;
}
#ifdef HAVE_HGE
- if (have_hge) {
+ if (!res && have_hge) {
sql_find_subtype(&tp, "hugeint", 0, 0);
if (!sql_bind_aggr(m->sa, s, "var_pop", &tp)) {
if ((err = sql_update_hugeint(c, m, prev_schema,
&systabfixed)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
}
#endif
f = sql_bind_func_(m->sa, s, "env", NULL, F_UNION);
- if (f && sql_privilege(m, ROLE_PUBLIC, f->func->base.id, PRIV_EXECUTE,
0) != PRIV_EXECUTE) {
+ if (!res && f && sql_privilege(m, ROLE_PUBLIC, f->func->base.id,
PRIV_EXECUTE, 0) != PRIV_EXECUTE) {
sql_table *privs = find_sql_table(s, "privileges");
int pub = ROLE_PUBLIC, p = PRIV_EXECUTE, zero = 0;
@@ -2425,14 +2427,15 @@ SQLupgrades(Client c, mvc *m)
* 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(s, "point") != NULL) {
+ if (!res && find_sql_type(s, "point") != NULL) {
/* type sys.point exists: this is an old geom-enabled
* database */
if ((err = sql_update_geom(c, m, 1, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
- } else if (geomsqlfix_get() != NULL) {
+ } else if (!res && geomsqlfix_get() != NULL) {
/* the geom module is loaded... */
sql_find_subtype(&tp, "clob", 0, 0);
if (!sql_bind_func(m->sa, s, "st_wkttosql",
@@ -2441,65 +2444,74 @@ SQLupgrades(Client c, mvc *m)
if ((err = sql_update_geom(c, m, 0, prev_schema)) !=
NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
}
- if (mvc_bind_table(m, s, "function_languages") == NULL) {
+ if (!res && mvc_bind_table(m, s, "function_languages") == NULL) {
if ((err = sql_update_jul2017(c, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
- if ((err = sql_update_jul2017_sp2(c)) != NULL) {
+ if (!res && (err = sql_update_jul2017_sp2(c)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
- if ((err = sql_update_jul2017_sp3(c, m, prev_schema, &systabfixed)) !=
NULL) {
+ if (!res && (err = sql_update_jul2017_sp3(c, m, prev_schema,
&systabfixed)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
- if ((t = mvc_bind_table(m, s, "geometry_columns")) != NULL &&
+ if (!res && (t = mvc_bind_table(m, s, "geometry_columns")) != NULL &&
(col = mvc_bind_column(m, t, "coord_dimension")) != NULL &&
strcmp(col->type.type->sqlname, "int") != 0) {
if ((err = sql_update_mar2018_geom(c, t, prev_schema)) != NULL)
{
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
- if (mvc_bind_schema(m, "wlc") == NULL &&
+ if (!res && mvc_bind_schema(m, "wlc") == NULL &&
!sql_bind_func(m->sa, s, "master", NULL, NULL, F_PROC)) {
if ((err = sql_update_mar2018(c, m, prev_schema, &systabfixed))
!= NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
#ifdef HAVE_NETCDF
if (mvc_bind_table(m, s, "netcdf_files") != NULL &&
(err = sql_update_mar2018_netcdf(c, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
#endif
#ifdef HAVE_SAMTOOLS
if ((err = sql_update_mar2018_samtools(c, m, prev_schema)) !=
NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
#endif
}
- if (sql_bind_func(m->sa, s, "dependencies_functions_os_triggers", NULL,
NULL, F_UNION)) {
+ if (!res && sql_bind_func(m->sa, s,
"dependencies_functions_os_triggers", NULL, NULL, F_UNION)) {
if ((err = sql_update_mar2018_sp1(c, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
- if (mvc_bind_table(m, s, "ids") != NULL) {
+ if (!res && mvc_bind_table(m, s, "ids") != NULL) {
/* determine if sys.ids needs to be updated (only the version
of Mar2018) */
char * qry = "select id from sys._tables where name = 'ids' and
query like '% tmp.keys k join sys._tables% tmp.idxs i join sys._tables%
tmp.triggers g join sys._tables% ';";
res_table *output = NULL;
@@ -2507,6 +2519,7 @@ SQLupgrades(Client c, mvc *m)
if (err) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
} else {
BAT *b = BATdescriptor(output->cols[0].b);
if (b) {
@@ -2515,6 +2528,7 @@ SQLupgrades(Client c, mvc *m)
if ((err =
sql_replace_Mar2018_ids_view(c, m, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
BBPunfix(b->batCacheid);
@@ -2526,7 +2540,7 @@ SQLupgrades(Client c, mvc *m)
/* temporarily use variable `err' to check existence of MAL
* module gsl */
- if ((err = getName("gsl")) == NULL || getModule(err) == NULL) {
+ if (!res && (((err = getName("gsl")) == NULL || getModule(err) ==
NULL))) {
/* no MAL module gsl, check for SQL function sys.chi2prob */
sql_find_subtype(&tp, "double", 0, 0);
if (sql_bind_func(m->sa, s, "chi2prob", &tp, &tp, F_FUNC)) {
@@ -2535,19 +2549,21 @@ SQLupgrades(Client c, mvc *m)
if ((err = sql_update_gsl(c, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
}
sql_find_subtype(&tp, "clob", 0, 0);
- if (sql_bind_aggr(m->sa, s, "group_concat", &tp) == NULL) {
+ if (!res && sql_bind_aggr(m->sa, s, "group_concat", &tp) == NULL) {
if ((err = sql_update_aug2018(c, m, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
- if (sql_bind_func(m->sa, s, "dependencies_schemas_on_users", NULL,
NULL, F_UNION)
+ if (!res && sql_bind_func(m->sa, s, "dependencies_schemas_on_users",
NULL, NULL, F_UNION)
&& sql_bind_func(m->sa, s, "dependencies_owners_on_schemas", NULL,
NULL, F_UNION)
&& sql_bind_func(m->sa, s, "dependencies_tables_on_views", NULL, NULL,
F_UNION)
&& sql_bind_func(m->sa, s, "dependencies_tables_on_indexes", NULL,
NULL, F_UNION)
@@ -2567,73 +2583,85 @@ SQLupgrades(Client c, mvc *m)
if ((err = sql_drop_functions_dependencies_Xs_on_Ys(c,
prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
}
- if ((err = sql_update_aug2018_sp2(c, prev_schema)) != NULL) {
+ if (!res && (err = sql_update_aug2018_sp2(c, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
- if ((t = mvc_bind_table(m, s, "systemfunctions")) != NULL &&
+ if (!res && (t = mvc_bind_table(m, s, "systemfunctions")) != NULL &&
t->type == tt_table) {
if (!systabfixed &&
(err = sql_fix_system_tables(c, m, prev_schema)) != NULL) {
fprintf(stderr, "!%s\n", err);
freeException(err);
+ res = -1;
}
systabfixed = true;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list