Changeset: 59b752c4a0d0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=59b752c4a0d0
Modified Files:
        clients/mapiclient/dump.c
        clients/mapiclient/msqldump.c
Branch: default
Log Message:

Merge with Mar2018 branch.


diffs (truncated from 508 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
@@ -121,15 +121,15 @@ get_schema(Mapi mid)
 }
 
 /* return TRUE if the HUGEINT type exists */
-static int
+static bool
 has_hugeint(Mapi mid)
 {
        MapiHdl hdl;
-       int ret;
+       bool ret;
        static int hashge = -1;
 
        if (hashge >= 0)
-               return hashge;
+               return (bool) hashge;
 
        if ((hdl = mapi_query(mid,
                              "SELECT id "
@@ -145,7 +145,7 @@ has_hugeint(Mapi mid)
        if (mapi_error(mid))
                goto bailout;
        mapi_close_handle(hdl);
-       hashge = ret;
+       hashge = (int) ret;
        return ret;
 
   bailout:
@@ -383,8 +383,8 @@ static int dump_column_definition(
        const char *schema,
        const char *tname,
        const char *tid,
-       int foreign,
-       int hashge);
+       bool foreign,
+       bool hashge);
 
 static const char *geomsubtypes[] = {
        NULL,                   /* 0 */
@@ -399,7 +399,7 @@ static const char *geomsubtypes[] = {
 };
 
 static int
-dump_type(Mapi mid, stream *toConsole, const char *c_type, const char 
*c_type_digits, const char *c_type_scale, int hashge)
+dump_type(Mapi mid, stream *toConsole, const char *c_type, const char 
*c_type_digits, const char *c_type_scale, bool hashge)
 {
        int space = 0;
 
@@ -533,7 +533,7 @@ dump_type(Mapi mid, stream *toConsole, c
 }
 
 static int
-dump_column_definition(Mapi mid, stream *toConsole, const char *schema, const 
char *tname, const char *tid, int foreign, int hashge)
+dump_column_definition(Mapi mid, stream *toConsole, const char *schema, const 
char *tname, const char *tid, bool foreign, bool hashge)
 {
        MapiHdl hdl = NULL;
        char *query;
@@ -782,7 +782,7 @@ describe_table(Mapi mid, const char *sch
        int type = 0;
        size_t maxquerylen;
        char *sname = NULL;
-       int hashge;
+       bool hashge;
 
        if (schema == NULL) {
                if ((sname = strchr(tname, '.')) != NULL) {
@@ -1338,102 +1338,15 @@ dump_table(Mapi mid, const char *schema,
 }
 
 static int
-dump_function_comment(Mapi mid, stream *toConsole, const char *id)
-{
-       int len = 5120;
-       char *query = malloc(len);
-       MapiHdl hdl = NULL;
-       int hashge;
-
-       if (!query)
-               return 1;
-
-       snprintf(query, len,
-               "%s "
-               "SELECT coalesce(function_type_keyword, '') AS category, "
-                      "s.name AS schema, "
-                      "CASE RANK() OVER (PARTITION BY f.id ORDER BY p.number 
ASC) WHEN 1 THEN f.name ELSE NULL END AS name, "
-                      "p.type, "
-                      "p.type_digits, "
-                      "p.type_scale, "
-                      "CASE RANK() OVER (PARTITION BY f.id ORDER BY p.number 
DESC) WHEN 1 THEN c.remark ELSE NULL END AS remark, "
-                      "ROW_NUMBER() OVER (ORDER BY f.id, p.number) AS line "
-               "FROM sys.functions f "
-                    "JOIN comments c ON f.id = c.id "
-                    "JOIN sys.schemas s ON f.schema_id = s.id "
-                    "LEFT OUTER JOIN sys.function_types ft ON f.type = 
ft.function_type_id "
-                    "LEFT OUTER JOIN sys.args p ON f.id = p.func_id AND 
p.inout = 1 "
-               "WHERE f.id = %s "
-               "ORDER BY line",
-               get_compat_clause(mid),
-               id);
-
-       hashge = has_hugeint(mid);
-       hdl = mapi_query(mid, query);
-       if (hdl == NULL || mapi_error(mid))
-               goto bailout;
-       while (!mnstr_errnr(toConsole) && mapi_fetch_row(hdl) != 0) {
-               int i = 0;
-               char *category = mapi_fetch_field(hdl, i++);
-               char *sname = mapi_fetch_field(hdl, i++);
-               char *name = mapi_fetch_field(hdl, i++);
-               char *type = mapi_fetch_field(hdl, i++);
-               char *type_digits = mapi_fetch_field(hdl, i++);
-               char *type_scale = mapi_fetch_field(hdl, i++);
-               char *remark = mapi_fetch_field(hdl, i++);
-
-               if (name) {
-                       mnstr_printf(toConsole, "COMMENT ON %s ", category);
-                       quoted_print(toConsole, sname, false);
-                       mnstr_printf(toConsole, ".");
-                       quoted_print(toConsole, name, false);
-                       mnstr_printf(toConsole, "(");
-               } else {
-                       mnstr_printf(toConsole, ", ");
-               }
-
-               if (type) {
-                       dump_type(NULL, toConsole, type, type_digits, 
type_scale, hashge);
-               }
-
-               if (remark) {
-                       mnstr_printf(toConsole, ") IS ");
-                       quoted_print(toConsole, remark, true);
-                       mnstr_printf(toConsole, ";\n");
-               }
-       }
-       if (mapi_error(mid))
-               goto bailout;
-
-       free(query);
-       mapi_close_handle(hdl);
-       return 0;
-
-       bailout:
-       if (query)
-               free(query);
-       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 1;
-}
-
-static int
-dump_function(Mapi mid, stream *toConsole, const char *fid, int hashge)
+dump_function(Mapi mid, stream *toConsole, const char *fid, bool hashge)
 {
        MapiHdl hdl;
        size_t qlen = 5120 + strlen(fid);
        char *query = malloc(qlen);
        char *q, *end_q;
        const char *sep;
-       char *ffunc = NULL, *flkey = NULL;
-       const char *sname, *fname, *ftkey;
+       char *ffunc = NULL, *flkey = NULL, *remark = NULL;
+       char *sname, *fname, *ftkey;
        int flang, ftype;
 
        if (!query)
@@ -1449,12 +1362,14 @@ dump_function(Mapi mid, stream *toConsol
                             "f.type, "
                             "s.name, "
                             "f.name, "
-                            "function_type_keyword, "
-                            "language_keyword "
+                            "ft.function_type_keyword, "
+                            "fl.language_keyword, "
+                            "c.remark "
                      "FROM sys.functions f "
                           "JOIN sys.schemas s ON f.schema_id = s.id "
                           "JOIN function_types ft ON f.type = 
ft.function_type_id "
                           "LEFT OUTER JOIN function_languages fl ON f.language 
= fl.language_id "
+                          "LEFT OUTER JOIN comments c ON f.id = c.id "
                      "WHERE f.id = %s",
                      get_compat_clause(mid), fid);
        if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
@@ -1474,6 +1389,13 @@ dump_function(Mapi mid, stream *toConsol
        fname = mapi_fetch_field(hdl, 5);
        ftkey = mapi_fetch_field(hdl, 6);
        flkey = mapi_fetch_field(hdl, 7);
+       remark = mapi_fetch_field(hdl, 8);
+       if (remark) {
+               remark = strdup(remark);
+               sname = strdup(sname);
+               fname = strdup(fname);
+               ftkey = strdup(ftkey);
+       }
        if (flang == 1 || flang == 2) {
                /* all information is stored in the func column
                 * first skip initial comments and empty lines */
@@ -1485,74 +1407,111 @@ dump_function(Mapi mid, stream *toConsol
                                ffunc++;
                }
                mnstr_printf(toConsole, "%s\n", ffunc);
-               mapi_close_handle(hdl);
-               free(query);
-               return 0;
+               if (remark == NULL) {
+                       mapi_close_handle(hdl);
+                       free(query);
+                       return 0;
+               }
+       } else {
+               mnstr_printf(toConsole, "CREATE %s ", ftkey);
+               quoted_print(toConsole, sname, false);
+               mnstr_printf(toConsole, ".");
+               quoted_print(toConsole, fname, false);
+               mnstr_printf(toConsole, "(");
        }
        /* strdup these two because they are needed after another query */
        ffunc = strdup(ffunc);
        if (flkey)
                flkey = strdup(flkey);
-       mnstr_printf(toConsole, "CREATE %s ", ftkey);
-       quoted_print(toConsole, sname, false);
-       mnstr_printf(toConsole, ".");
-       quoted_print(toConsole, fname, false);
-       mnstr_printf(toConsole, "(");
        snprintf(query, qlen, "SELECT a.name, a.type, a.type_digits, 
a.type_scale, a.inout FROM sys.args a, sys.functions f WHERE a.func_id = f.id 
AND f.id = %s ORDER BY a.inout DESC, a.number", fid);
        mapi_close_handle(hdl);
-       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
-               free(query);
+       hdl = mapi_query(mid, query);
+       free(query);
+       if (hdl == NULL || mapi_error(mid)) {
                free(ffunc);
                free(flkey);
+               if (remark)
+                       free(remark);
                return 1;
        }
-       sep = "";
-       while (mapi_fetch_row(hdl) != 0) {
-               const char *aname = mapi_fetch_field(hdl, 0);
-               const char *atype = mapi_fetch_field(hdl, 1);
-               const char *adigs = mapi_fetch_field(hdl, 2);
-               const char *ascal = mapi_fetch_field(hdl, 3);
-               const char *ainou = mapi_fetch_field(hdl, 4);
-
-               if (strcmp(ainou, "0") == 0) {
-                       /* end of arguments */
-                       break;
-               }
-
-               mnstr_printf(toConsole, "%s", sep);
-               quoted_print(toConsole, aname, false);
-               mnstr_printf(toConsole, " ");
-               dump_type(mid, toConsole, atype, adigs, ascal, hashge);
-               sep = ", ";
-       }
-       mnstr_printf(toConsole, ")");
-       if (ftype == 1 || ftype == 3 || ftype == 5) {
-               sep = "TABLE (";
-               mnstr_printf(toConsole, " RETURNS ");
-               do {
+       if (flang != 1 && flang != 2) {
+               sep = "";
+               while (mapi_fetch_row(hdl) != 0) {
                        const char *aname = mapi_fetch_field(hdl, 0);
                        const char *atype = mapi_fetch_field(hdl, 1);
                        const char *adigs = mapi_fetch_field(hdl, 2);
                        const char *ascal = mapi_fetch_field(hdl, 3);
+                       const char *ainou = mapi_fetch_field(hdl, 4);
 
-                       assert(strcmp(mapi_fetch_field(hdl, 4), "0") == 0);
-                       if (ftype == 5) {
-                               mnstr_printf(toConsole, "%s", sep);
-                               quoted_print(toConsole, aname, false);
-                               mnstr_printf(toConsole, " ");
-                               sep = ", ";
+                       if (strcmp(ainou, "0") == 0) {
+                               /* end of arguments */
+                               break;
                        }
+
+                       mnstr_printf(toConsole, "%s", sep);
+                       quoted_print(toConsole, aname, false);
+                       mnstr_printf(toConsole, " ");
                        dump_type(mid, toConsole, atype, adigs, ascal, hashge);
-               } while (mapi_fetch_row(hdl) != 0);
+                       sep = ", ";
+               }
+               mnstr_printf(toConsole, ")");
+               if (ftype == 1 || ftype == 3 || ftype == 5) {
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to