Changeset: 86ab8ca6d9ff for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/86ab8ca6d9ff
Modified Files:
        clients/mapiclient/dump.c
        clients/mapiclient/mclient.c
        sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_01.test
        sql/backends/monet5/sql_upgrades.c
        sql/scripts/52_describe.sql
        sql/scripts/76_dump.sql
        sql/storage/bat/bat_logger.c
        sql/storage/store.c
        
sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.test
        
sql/test/BugTracker-2010/Tests/store_function_argument_correctly.Bug-2750.test
        sql/test/BugTracker-2013/Tests/recursion.test
        sql/test/BugTracker-2015/Tests/crash.Bug-3736.test
        sql/test/BugTracker-2017/Tests/parsererror.Bug-6381.test
        sql/test/BugTracker-2020/Tests/semijoin.Bug-7001.test
        sql/test/Dependencies/Tests/dependency_DBobjects.test
        sql/test/Dependencies/Tests/dependency_functions.test
        sql/test/Dependencies/Tests/dependency_owner_schema_3.test
        sql/test/Dependencies/Tests/view_table_udf.test
        sql/test/Tests/function_syntax.test
        sql/test/Tests/procedure_syntax.test
        sql/test/bugs/Tests/innerjoin_multiple-bug-sf-943661.test
        
sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-previous-upgrade/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128
        sql/test/emptydb/Tests/check.SQL.py
        sql/test/emptydb/Tests/check.stable.out
        sql/test/emptydb/Tests/check.stable.out.32bit
        sql/test/emptydb/Tests/check.stable.out.int128
        sql/test/sys-schema/Tests/check_ForeignKey_referential_integrity.test
        sql/test/sys-schema/Tests/check_MaxStrLength_violations.test
        sql/test/sys-schema/Tests/check_Not_Nullable_columns.test
        sql/test/sys-schema/Tests/utilities.test
        
sql/test/testdb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/testdb-previous-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-previous-upgrade/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
Branch: mangled
Log Message:

Replace sql_name with mangled_name in functions table.


diffs (truncated from 87121 to 300 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -213,49 +213,6 @@ static const char *actions[] = {
 };
 #define NR_ACTIONS     ((int) (sizeof(actions) / sizeof(actions[0])))
 
-static bool
-functions_has_sqlname(Mapi mid)
-{
-       bool ret;
-       MapiHdl hdl;
-       static int answer = -1;
-
-       if (answer >= 0)
-               return (bool) answer;
-
-       if ((hdl = mapi_query(mid,
-               "select c.name"
-               "       from sys.columns c, sys.tables t"
-               "       where"
-               "               c.table_id = t.id and"
-               "               t.name = 'functions' and"
-               "               t.schema_id = (select id from sys.schemas where 
name = 'sys') and"
-               "               c.name = 'sqlname'")) == NULL
-               || mapi_error(mid))
-               goto bailout;
-       ret = (int) mapi_get_row_count(hdl) == 1;
-       while ((mapi_fetch_row(hdl)) != 0) {
-               if (mapi_error(mid))
-                       goto bailout;
-       }
-       if (mapi_error(mid))
-               goto bailout;
-       mapi_close_handle(hdl);
-       answer = (int) ret;
-       return ret;
-
-bailout:
-       if (hdl) {
-               if (mapi_result_error(hdl))
-                       mapi_explain_result(hdl, stderr);
-               else
-                       mapi_explain_query(hdl, stderr);
-               mapi_close_handle(hdl);
-       } else
-               mapi_explain(mid, stderr);
-       return 0;
-}
-
 static char *
 get_schema(Mapi mid)
 {
@@ -1186,8 +1143,6 @@ describe_table(Mapi mid, const char *sch
        int ca = 0;
        size_t maxquerylen;
        bool hashge;
-       bool has_sqlname;
-       const char* functions_sqlname;
 
        if (schema == NULL) {
                if ((sname = strchr(tname, '.')) != NULL) {
@@ -1268,9 +1223,6 @@ describe_table(Mapi mid, const char *sch
                goto bailout2;
        }
 
-       has_sqlname = functions_has_sqlname(mid);
-       functions_sqlname = has_sqlname ? "sqlname" : "name";
-
        if (type == 1) {
                /* the table is actually a view */
                mnstr_printf(toConsole, "%s\n", view);
@@ -1279,11 +1231,11 @@ describe_table(Mapi mid, const char *sch
                if (!databaseDump) { //if it is not a database dump the table 
might depend on UDFs that must be dumped first
                        assert(table_id);
                        snprintf(query, maxquerylen,
-                                        "SELECT f.id, s.name, f.%s "
+                                        "SELECT f.id, s.name, f.name "
                                         "FROM sys.schemas s, "
                                              "sys.functions f "
                                         "WHERE s.id = f.schema_id "
-                                          "AND f.id IN (SELECT id FROM 
sys.dependencies WHERE depend_id = '%d')", functions_sqlname,
+                                          "AND f.id IN (SELECT id FROM 
sys.dependencies WHERE depend_id = '%d')",
                                         table_id);
                        if ((hdl = mapi_query(mid, query)) == NULL || 
mapi_error(mid))
                                goto bailout;
@@ -2148,7 +2100,7 @@ dump_table(Mapi mid, const char *schema,
 }
 
 static int
-dump_function(Mapi mid, stream *toConsole, const char *fid, bool hashge, const 
char* functions_sqlname)
+dump_function(Mapi mid, stream *toConsole, const char *fid, bool hashge)
 {
        MapiHdl hdl = NULL;
        size_t query_size = 5120 + strlen(fid);
@@ -2169,7 +2121,7 @@ dump_function(Mapi mid, stream *toConsol
                             "f.language, "
                             "f.type, "
                             "s.name, "
-                            "f.%s, "
+                            "f.name, "
                             "ft.function_type_keyword, "
                             "fl.language_keyword, "
                             "c.remark "
@@ -2179,7 +2131,7 @@ dump_function(Mapi mid, stream *toConsol
                           "LEFT OUTER JOIN sys.function_languages fl ON 
f.language = fl.language_id "
                           "LEFT OUTER JOIN sys.comments c ON f.id = c.id "
                      "WHERE f.id = %s",
-                     functions_sqlname, fid);
+                     fid);
        assert(query_len < (int) query_size);
        if (query_len < 0 || query_len >= (int) query_size ||
            (hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
@@ -2450,8 +2402,6 @@ dump_functions(Mapi mid, stream *toConso
        size_t query_size;
        int query_len;
        bool hashge;
-       bool has_sqlname;
-       const char* functions_sqlname = NULL;
        char *to_free = NULL;
        bool wantSystem;
        long prev_sid;
@@ -2481,8 +2431,6 @@ dump_functions(Mapi mid, stream *toConso
        }
 
        hashge = has_hugeint(mid);
-       has_sqlname = functions_has_sqlname(mid);
-       functions_sqlname = has_sqlname ? "sqlname" : "name";
 
        query_size = 5120 + (sname ? strlen(sname) : 0) + (fname ? 
strlen(fname) : 0);
        query = malloc(query_size);
@@ -2504,7 +2452,7 @@ dump_functions(Mapi mid, stream *toConso
                                              query_size - query_len,
                                              "AND s.name = '%s' ", sname);
                if (fname)
-                       query_len += snprintf(query + query_len, query_size - 
query_len, "AND f.%s = '%s' ", functions_sqlname, fname);
+                       query_len += snprintf(query + query_len, query_size - 
query_len, "AND f.name = '%s' ", fname);
                if (!wantSystem) {
                        query_len += snprintf(query + query_len, query_size - 
query_len, "AND NOT f.system ");
                }
@@ -2532,7 +2480,7 @@ dump_functions(Mapi mid, stream *toConso
                                dquoted_print(toConsole, schema, ";\n");
                                prev_sid = sid;
                        }
-                       dump_function(mid, toConsole, fid, hashge, 
functions_sqlname);
+                       dump_function(mid, toConsole, fid, hashge);
                        free(fid);
                } else {
                        goto bailout;
@@ -2643,8 +2591,8 @@ dump_database(Mapi mid, stream *toConsol
                  "AND p.grantor = g.id "
                  "AND p.privileges = pc.privilege_code_id "
                "ORDER BY s.name, t.name, c.name, a.name, g.name, p.grantable";
-       const char *function_grants_template =
-               "SELECT s.name, f.%s, a.name, "
+       const char *function_grants =
+               "SELECT s.name, f.name, a.name, "
                       "pc.privilege_code_name, "
                       "g.name, p.grantable, "
                       "ft.function_type_keyword "
@@ -2659,7 +2607,7 @@ dump_database(Mapi mid, stream *toConsol
                  "AND p.privileges = pc.privilege_code_id "
                  "AND f.type = ft.function_type_id "
                  "AND NOT f.system "
-               "ORDER BY s.name, f.%s, a.name, g.name, p.grantable";
+               "ORDER BY s.name, f.name, a.name, g.name, p.grantable";
        const char *schemas =
                "SELECT s.name, a.name, rem.remark "
                "FROM sys.schemas s LEFT OUTER JOIN sys.comments rem ON s.id = 
rem.id, "
@@ -2750,7 +2698,7 @@ dump_database(Mapi mid, stream *toConsol
                          "AND s.name <> 'tmp' "
                        "UNION ALL "
                        "SELECT s.name AS sname, " /* functions and procedures 
*/
-                              "f.%s AS name, "
+                              "f.name AS name, "
                               "f.id AS id, "
                               "NULL AS query, "
                               "NULL AS remark " /* emitted separately */
@@ -2780,9 +2728,6 @@ dump_database(Mapi mid, stream *toConsol
        /* start a transaction for the dump */
        mnstr_printf(toConsole, "%s;\n", start_trx);
 
-       bool has_sqlname = functions_has_sqlname(mid);
-       const char* functions_sqlname = has_sqlname ? "sqlname" : "name";
-
        if ((hdl = mapi_query(mid, start_trx)) == NULL || mapi_error(mid))
                goto bailout;
        mapi_close_handle(hdl);
@@ -3124,9 +3069,7 @@ dump_database(Mapi mid, stream *toConsol
        hdl = NULL;
 
        /* dump views, functions and triggers */
-       char function_views[5120];
-       snprintf(function_views, sizeof(function_views), 
views_functions_triggers, functions_sqlname);
-       if ((hdl = mapi_query(mid, function_views)) == NULL ||
+       if ((hdl = mapi_query(mid, views_functions_triggers)) == NULL ||
                mapi_error(mid))
                goto bailout;
 
@@ -3327,10 +3270,6 @@ dump_database(Mapi mid, stream *toConsol
                goto bailout;
        mapi_close_handle(hdl);
 
-
-       char function_grants[5120];
-       snprintf(function_grants, 
sizeof(function_grants),function_grants_template, functions_sqlname, 
functions_sqlname);
-
        if ((hdl = mapi_query(mid, function_grants)) == NULL ||
            mapi_error(mid))
                goto bailout;
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -173,49 +173,6 @@ static char *nullstring = default_nullst
 #include <ctype.h>
 #include "mhelp.h"
 
-static bool
-functions_has_sqlname(Mapi mid)
-{
-       bool ret;
-       MapiHdl hdl;
-       static int answer = -1;
-
-       if (answer >= 0)
-               return (bool) answer;
-
-       if ((hdl = mapi_query(mid,
-               "select c.name"
-               "       from sys.columns c, sys.tables t"
-               "       where"
-               "               c.table_id = t.id and"
-               "               t.name = 'functions' and"
-               "               t.schema_id = (select id from sys.schemas where 
name = 'sys') and"
-               "               c.name = 'sqlname'")) == NULL
-               || mapi_error(mid))
-               goto bailout;
-       ret = (int) mapi_get_row_count(hdl) == 1;
-       while ((mapi_fetch_row(hdl)) != 0) {
-               if (mapi_error(mid))
-                       goto bailout;
-       }
-       if (mapi_error(mid))
-               goto bailout;
-       mapi_close_handle(hdl);
-       answer = (int) ret;
-       return ret;
-
-bailout:
-       if (hdl) {
-               if (mapi_result_error(hdl))
-                       mapi_explain_result(hdl, stderr);
-               else
-                       mapi_explain_query(hdl, stderr);
-               mapi_close_handle(hdl);
-       } else
-               mapi_explain(mid, stderr);
-       return 0;
-}
-
 static timertype
 gettime(void)
 {
@@ -2569,10 +2526,59 @@ doFile(Mapi mid, stream *fp, bool useins
                                                end_pager(saveFD);
 #endif
                                        } else {
-
-                                               const char* functions_sqlname = 
functions_has_sqlname(mid) ? "sqlname" : "name";
-
-                                               size_t len = 5000 + 400 + 
strlen(line);
+                                               /* get all object names in 
current schema */
+                                               const char *with_clause =
+                                                       "with 
describe_all_objects AS (\n"
+                                                       "  SELECT s.name AS 
sname,\n"
+                                                       "      t.name,\n"
+                                                       "      s.name || '.' || 
t.name AS fullname,\n"
+                                                       "      CAST(CASE 
t.type\n"
+                                                       "      WHEN 1 THEN 2\n" 
/* ntype for views */
+                                                       "      ELSE 1\n" /* 
ntype for tables */
+                                                       "      END AS SMALLINT) 
AS ntype,\n"
+                                                       "      (CASE WHEN 
t.system THEN 'SYSTEM ' ELSE '' END) || tt.table_type_name AS type,\n"
+                                                       "      t.system,\n"
+                                                       "      c.remark AS 
remark\n"
+                                                       "    FROM sys._tables 
t\n"
+                                                       "    LEFT OUTER JOIN 
sys.comments c ON t.id = c.id\n"
+                                                       "    LEFT OUTER JOIN 
sys.schemas s ON t.schema_id = s.id\n"
+                                                       "    LEFT OUTER JOIN 
sys.table_types tt ON t.type = tt.table_type_id\n"
+                                                       "  UNION ALL\n"
+                                                       "  SELECT s.name AS 
sname,\n"
+                                                       "      sq.name,\n"
+                                                       "      s.name || '.' || 
sq.name AS fullname,\n"
+                                                       "      CAST(4 AS 
SMALLINT) AS ntype,\n"
+                                                       "      'SEQUENCE' AS 
type,\n"
+                                                       "      false AS 
system,\n"
+                                                       "      c.remark AS 
remark\n"
+                                                       "    FROM sys.sequences 
sq\n"
+                                                       "    LEFT OUTER JOIN 
sys.comments c ON sq.id = c.id\n"
+                                                       "    LEFT OUTER JOIN 
sys.schemas s ON sq.schema_id = s.id\n"
+                                                       "  UNION ALL\n"
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to