Changeset: 1b6dfe528792 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1b6dfe528792
Modified Files:
        clients/mapiclient/dump.c
Branch: Mar2018
Log Message:

Use function_type_keyword and language_keyword columns when dumping.


diffs (114 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -1384,17 +1384,17 @@ static int
 dump_function(Mapi mid, stream *toConsole, const char *fid, int hashge)
 {
        MapiHdl hdl;
-       size_t qlen = 200 + strlen(fid);
+       size_t qlen = 400 + strlen(fid);
        char *query = malloc(qlen);
        const char *sep;
-       char *ffunc;
-       const char *sname, *fname;
+       char *ffunc, *flkey;
+       const char *sname, *fname, *ftkey;
        int flang, ftype;
 
        if (!query)
                return 1;
 
-       snprintf(query, qlen, "SELECT f.id, f.func, f.language, f.type, s.name, 
f.name FROM sys.functions f, sys.schemas s WHERE f.schema_id = s.id AND f.id = 
%s", fid);
+       snprintf(query, qlen, "SELECT f.id, f.func, f.language, f.type, s.name, 
f.name, ft.function_type_keyword, fl.language_keyword FROM sys.functions f JOIN 
sys.schemas s ON f.schema_id = s.id JOIN sys.function_types ft ON f.type = 
ft.function_type_id LEFT OUTER JOIN sys.function_languages fl ON f.language = 
fl.language_id WHERE f.id = %s", fid);
        hdl = mapi_query(mid, query);
        if (mapi_fetch_row(hdl) == 0) {
                free(query);
@@ -1406,6 +1406,8 @@ dump_function(Mapi mid, stream *toConsol
        ftype = atoi(mapi_fetch_field(hdl, 3));
        sname = mapi_fetch_field(hdl, 4);
        fname = mapi_fetch_field(hdl, 5);
+       ftkey = mapi_fetch_field(hdl, 6);
+       flkey = mapi_fetch_field(hdl, 7);
        if (flang == 1 || flang == 2) {
                /* all information is stored in the func column */
                mnstr_printf(toConsole, "%s\n", ffunc);
@@ -1413,33 +1415,11 @@ dump_function(Mapi mid, stream *toConsol
                free(query);
                return 0;
        }
-       mnstr_printf(toConsole, "CREATE ");
-       switch (ftype) {
-       case 1:                 /* scalar function */
-       case 5:                 /* table returning function */
-               mnstr_printf(toConsole, "FUNCTION");
-               break;
-       case 2:
-               mnstr_printf(toConsole, "PROCEDURE");
-               break;
-       case 3:
-               mnstr_printf(toConsole, "AGGREGATE");
-               break;
-       case 4:
-               mnstr_printf(toConsole, "FILTER FUNCTION");
-               break;
-       case 7:
-               mnstr_printf(toConsole, "LOADER");
-               break;
-       default:
-               /* shouldn't happen (6 is F_ANALYTIC, but no syntax to
-                * create, or values are not defined) */
-               free(query);
-               mapi_close_handle(hdl);
-               return -1;
-       }
+       /* strdup these two because they are needed after another query */
        ffunc = strdup(ffunc);
-       mnstr_printf(toConsole, " ");
+       if (flkey)
+               flkey = strdup(flkey);
+       mnstr_printf(toConsole, "CREATE %s ", ftkey);
        quoted_print(toConsole, sname, false);
        mnstr_printf(toConsole, ".");
        quoted_print(toConsole, fname, false);
@@ -1488,38 +1468,9 @@ dump_function(Mapi mid, stream *toConsol
                } while (mapi_fetch_row(hdl) != 0);
        }
        mapi_close_handle(hdl);
-       mnstr_printf(toConsole, " LANGUAGE ");
-       switch (flang) {
-       case 3:
-               mnstr_printf(toConsole, "R");
-               break;
-       case 4:
-               mnstr_printf(toConsole, "C");
-               break;
-       case 5:
-               mnstr_printf(toConsole, "J");
-               break;
-       case 6:
-               mnstr_printf(toConsole, "PYTHON");
-               break;
-       case 7:
-               mnstr_printf(toConsole, "PYTHON_MAP");
-               break;
-       case 8:
-               mnstr_printf(toConsole, "PYTHON2");
-               break;
-       case 9:
-               mnstr_printf(toConsole, "PYTHON2_MAP");
-               break;
-       case 10:
-               mnstr_printf(toConsole, "PYTHON3");
-               break;
-       case 11:
-               mnstr_printf(toConsole, "PYTHON3_MAP");
-               break;
-       default:                /* unknown language */
-               free(ffunc);
-               return -1;
+       if (flkey) {
+               mnstr_printf(toConsole, " LANGUAGE %s", flkey);
+               free(flkey);
        }
        mnstr_printf(toConsole, "\n%s\n", ffunc);
        free(ffunc);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to