Changeset: 4d9a5438ef8f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4d9a5438ef8f
Modified Files:
        sql/backends/monet5/sql_upgrades.c
        sql/common/sql_types.c
        sql/server/rel_rel.c
        sql/server/rel_select.c
        sql/server/rel_unnest.c
Branch: privfuncs
Log Message:

Merged with default


diffs (truncated from 2061 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -522,12 +522,6 @@ ssize_t fltToStr(str *dst, size_t *len, 
 const flt flt_nil;
 gdk_return gdk_add_callback(char *name, gdk_callback_func *f, int argc, void 
*argv[], int interval);
 gdk_return gdk_remove_callback(char *, gdk_callback_func *f);
-geomcatalogfix_fptr geomcatalogfix_get(void);
-void geomcatalogfix_set(geomcatalogfix_fptr);
-geomsqlfix_fptr geomsqlfix_get(void);
-void geomsqlfix_set(geomsqlfix_fptr);
-bool geomversion_get(void);
-void geomversion_set(void);
 lng getBBPlogno(void);
 bat getBBPsize(void);
 lng getBBPtransid(void);
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -2615,6 +2615,9 @@ doFile(Mapi mid, stream *fp, bool useins
                                                }
                                                q += snprintf(q, endq - q, " 
ORDER BY fullname, type, remark");
 
+                                               stream *saveFD;
+                                               start_pager(&saveFD);
+
                                                hdl = mapi_query(mid, query);
                                                free(query);
                                                CHECK_RESULT(mid, hdl, buf, fp);
@@ -2647,6 +2650,7 @@ doFile(Mapi mid, stream *fp, bool useins
                                                }
                                                mapi_close_handle(hdl);
                                                hdl = NULL;
+                                               end_pager(saveFD);
                                        }
                                        continue;
                                }
@@ -2742,8 +2746,7 @@ doFile(Mapi mid, stream *fp, bool useins
                                        continue;
 #ifdef HAVE_POPEN
                                case '|':
-                                       if (pager)
-                                               free(pager);
+                                       free(pager);
                                        pager = NULL;
                                        setWidth();     /* reset to system 
default */
 
diff --git a/common/utils/muuid.c b/common/utils/muuid.c
--- a/common/utils/muuid.c
+++ b/common/utils/muuid.c
@@ -12,6 +12,7 @@
 #include "monetdb_config.h"
 #include "muuid.h"
 #include <string.h> /* strdup */
+#include <unistd.h>    /* for getentropy on FreeBSD */
 #if defined(HAVE_GETENTROPY) && defined(HAVE_SYS_RANDOM_H)
 #include <sys/random.h>
 #endif
diff --git a/gdk/gdk_geomlogger.h b/gdk/gdk_geomlogger.h
deleted file mode 100644
--- a/gdk/gdk_geomlogger.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0.  If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
- */
-
-#ifndef _GEOMLOGGER_H_
-#define _GEOMLOGGER_H_
-
-typedef int (*geomcatalogfix_fptr)(void *, int);
-gdk_export void geomcatalogfix_set(geomcatalogfix_fptr);
-gdk_export geomcatalogfix_fptr geomcatalogfix_get(void);
-
-typedef str (*geomsqlfix_fptr)(int);
-gdk_export void geomsqlfix_set(geomsqlfix_fptr);
-gdk_export geomsqlfix_fptr geomsqlfix_get(void);
-
-gdk_export void geomversion_set(void);
-gdk_export bool geomversion_get(void);
-
-#endif /* _GEOMLOGGER_H_ */
diff --git a/gdk/gdk_logger_old.c b/gdk/gdk_logger_old.c
--- a/gdk/gdk_logger_old.c
+++ b/gdk/gdk_logger_old.c
@@ -158,13 +158,6 @@ typedef struct logformat_t {
 
 typedef enum {LOG_OK, LOG_EOF, LOG_ERR} log_return;
 
-#include "gdk_geomlogger.h"
-
-/* When reading an old format database, we may need to read the geom
- * Well-known Binary (WKB) type differently.  This variable is used to
- * indicate that to the function wkbREAD during reading of the log. */
-static bool geomisoldversion;
-
 static gdk_return tr_grow(trans *tr);
 
 static BUN
@@ -1608,9 +1601,6 @@ logger_load(const char *fn, char filenam
                goto error;
        BBPretain(lg->lg->dcatalog->batCacheid);
 
-       /* done reading the log, revert to "normal" behavior */
-       geomisoldversion = false;
-
        return GDK_SUCCEED;
   error:
        if (fp)
@@ -1983,42 +1973,3 @@ logger_del_bat(old_logger *lg, log_bid b
        return BUNappend(lg->dcatalog, &pos, false);
 /*assert(BBP_lrefs(bid) == 0);*/
 }
-
-static geomcatalogfix_fptr geomcatalogfix = NULL;
-static geomsqlfix_fptr geomsqlfix = NULL;
-
-void
-geomcatalogfix_set(geomcatalogfix_fptr f)
-{
-       geomcatalogfix = f;
-}
-
-geomcatalogfix_fptr
-geomcatalogfix_get(void)
-{
-       return geomcatalogfix;
-}
-
-void
-geomsqlfix_set(geomsqlfix_fptr f)
-{
-       geomsqlfix = f;
-}
-
-geomsqlfix_fptr
-geomsqlfix_get(void)
-{
-       return geomsqlfix;
-}
-
-void
-geomversion_set(void)
-{
-       geomisoldversion = true;
-}
-
-bool
-geomversion_get(void)
-{
-       return geomisoldversion;
-}
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -2083,8 +2083,6 @@ geoGetType(char **res, int *info, int *f
 /* returns a pointer to a nil-mbr. */
 static mbr mbrNIL;             /* to be filled in */
 
-#include "gdk_geomlogger.h"
-
 str
 geom_prelude(void *ret)
 {
diff --git a/monetdb5/modules/mal/language.c b/monetdb5/modules/mal/language.c
--- a/monetdb5/modules/mal/language.c
+++ b/monetdb5/modules/mal/language.c
@@ -40,8 +40,11 @@ CMDraise(str *ret, str *msg)
        if( *ret == NULL)
                throw(MAL, "mal.raise", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        res = GDKstrdup(*msg);
-       if( res == NULL)
+       if( res == NULL) {
+               GDKfree(*ret);
+               *ret = NULL;
                throw(MAL, "mal.raise", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       }
        return res;
 }
 
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
@@ -26,7 +26,7 @@
  * functions, args) when internal types and/or functions have changed
  * (i.e. the ones in sql_types.c) */
 static str
-sql_fix_system_tables(Client c, mvc *sql, const char *prev_schema)
+sql_fix_system_tables(Client c, mvc *sql)
 {
        size_t bufsize = 1000000, pos = 0;
        char *buf = GDKmalloc(bufsize), *err = NULL;
@@ -37,7 +37,6 @@ sql_fix_system_tables(Client c, mvc *sql
        if (buf == NULL)
                throw(SQL, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
        s = mvc_bind_schema(sql, "sys");
-       pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n");
 
        pos += snprintf(buf + pos, bufsize - pos,
                        "delete from sys.dependencies where id < 2000;\n");
@@ -137,8 +136,6 @@ sql_fix_system_tables(Client c, mvc *sql
                }
        }
 
-       pos += snprintf(buf + pos, bufsize - pos, "set schema \"%s\";\n", 
prev_schema);
-
        assert(pos < bufsize);
        printf("Running database upgrade commands:\n%s\n", buf);
        err = SQLstatementIntern(c, buf, "update", true, false, NULL);
@@ -146,23 +143,73 @@ sql_fix_system_tables(Client c, mvc *sql
        return err;             /* usually MAL_SUCCEED */
 }
 
+static str
+check_sys_tables(Client c, mvc *m, sql_schema *s)
+{
+       struct {
+               const char *name;
+               const char *func;
+               const char *type;
+               sql_ftype ftype;
+       } tests[] = {
+               /* tests a few internal functions: the last one created, the
+                * first one created, and one of the first ones created after
+                * the geom module */
+               { "sys_update_tables", "update_tables", NULL,   F_PROC, },
+               { "length",            "nitems",        "blob", F_FUNC, },
+               { "isnull",            "isnil",         "void", F_FUNC, },
+               {0},
+       };
+
+       /* if any of the tested function's internal ID does not match the ID
+        * in the sys.functions table, we recreate the internal part of the
+        * system tables */
+       for (int i = 0; tests[i].name; i++) {
+               bool needsystabfix = true;
+               sql_subtype tp, *tpp;
+               if (tests[i].type) {
+                       sql_find_subtype(&tp, tests[i].type, 0, 0);
+                       tpp = &tp;
+               } else {
+                       tpp = NULL;
+               }
+               sql_subfunc *f = sql_bind_func(m, s->base.name, tests[i].name, 
tpp, NULL, tests[i].ftype, true);
+               if (f == NULL)
+                       throw(SQL, __func__, "cannot find procedure 
sys.%s(%s)", tests[i].name, tests[i].type ? tests[i].type : "");
+               sqlid id = f->func->base.id;
+               char buf[128];
+               snprintf(buf, sizeof(buf), "select id from sys.functions where 
name = '%s' and func = '%s' and schema_id = 2000;\n", tests[i].name, 
tests[i].func);
+               res_table *output = NULL;
+               char *err = SQLstatementIntern(c, buf, "update", true, false, 
&output);
+               if (err)
+                       return err;
+               BAT *b;
+               if ((b = BATdescriptor(output->cols[0].b)) != NULL) {
+                       if (BATcount(b) > 0) {
+                               BATiter bi = bat_iterator(b);
+                               needsystabfix = * (int *) BUNtloc(bi, 0) != id;
+                               bat_iterator_end(&bi);
+                       }
+                       BBPunfix(b->batCacheid);
+               }
+               res_table_destroy(output);
+               if (needsystabfix)
+                       return sql_fix_system_tables(c, m);
+       }
+       return NULL;
+}
+
 #ifdef HAVE_HGE
 static str
-sql_update_hugeint(Client c, mvc *sql, const char *prev_schema, bool 
*systabfixed)
+sql_update_hugeint(Client c, mvc *sql)
 {
        size_t bufsize = 8192, pos = 0;
        char *buf, *err;
 
-       if (!*systabfixed &&
-           (err = sql_fix_system_tables(c, sql, prev_schema)) != NULL)
-               return err;
-       *systabfixed = true;
-
+       (void) sql;
        if ((buf = GDKmalloc(bufsize)) == NULL)
                throw(SQL, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
 
-       pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n");
-
        /* 90_generator_hge.sql */
        pos += snprintf(buf + pos, bufsize - pos,
                        "create function sys.generate_series(first hugeint, 
\"limit\" hugeint)\n"
@@ -242,7 +289,6 @@ sql_update_hugeint(Client c, mvc *sql, c
                        "update sys.functions set system = true where system <> 
true and name = 'filter' and schema_id = (select id from sys.schemas where name 
= 'json') and type = %d;\n",
                        (int) F_UNION, (int) F_AGGR, (int) F_ANALYTIC, (int) 
F_FUNC);
 
-       pos += snprintf(buf + pos, bufsize - pos, "set schema \"%s\";\n", 
prev_schema);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to