Changeset: 66141ffe9d92 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=66141ffe9d92
Modified Files:
        clients/mapiclient/dump.c
Branch: Jul2015
Log Message:

Gross hack: mserver creates but doesn't accept columns of type decimal(39,X).
Or decimal(19,X) for non 128 bit systems.


diffs (124 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -171,6 +171,41 @@ has_schemas_system(Mapi mid)
        return 0;
 }
 
+/* return TRUE if the HUGEINT type exists */
+static int
+has_hugeint(Mapi mid)
+{
+       MapiHdl hdl;
+       int ret;
+
+       if ((hdl = mapi_query(mid,
+                             "SELECT id "
+                             "FROM sys.types "
+                             "WHERE sqlname = 'hugeint'")) == NULL ||
+           mapi_error(mid))
+               goto bailout;
+       ret = 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);
+       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 int
 dump_foreign_keys(Mapi mid, const char *schema, const char *tname, const char 
*tid, stream *toConsole)
 {
@@ -394,10 +429,11 @@ static int dump_column_definition(
        const char *schema,
        const char *tname,
        const char *tid,
-       int foreign);
+       int foreign,
+       int hashge);
 
 static int
-dump_type(Mapi mid, stream *toConsole, char *c_type, char *c_type_digits, char 
*c_type_scale)
+dump_type(Mapi mid, stream *toConsole, char *c_type, char *c_type_digits, char 
*c_type_scale, int hashge)
 {
        int space = 0;
 
@@ -502,13 +538,19 @@ dump_type(Mapi mid, stream *toConsole, c
                space = mnstr_printf(toConsole, "DECIMAL");
        } else if (strcmp(c_type, "table") == 0) {
                mnstr_printf(toConsole, "TABLE ");
-               dump_column_definition(mid, toConsole, NULL, NULL, 
c_type_digits, 1);
+               dump_column_definition(mid, toConsole, NULL, NULL, 
c_type_digits, 1, hashge);
        } else if (strcmp(c_type_digits, "0") == 0) {
                space = mnstr_printf(toConsole, "%s", toUpper(c_type));
        } else if (strcmp(c_type_scale, "0") == 0) {
                space = mnstr_printf(toConsole, "%s(%s)",
                                toUpper(c_type), c_type_digits);
        } else {
+               if (strcmp(c_type, "decimal") == 0) {
+                       if (strcmp(c_type_digits, "39") == 0)
+                               c_type_digits = "38";
+                       else if (!hashge && strcmp(c_type_digits, "19") == 0)
+                               c_type_digits = "18";
+               }
                space = mnstr_printf(toConsole, "%s(%s,%s)",
                                toUpper(c_type), c_type_digits, c_type_scale);
        }
@@ -516,7 +558,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)
+dump_column_definition(Mapi mid, stream *toConsole, const char *schema, const 
char *tname, const char *tid, int foreign, int hashge)
 {
        MapiHdl hdl = NULL;
        char *query;
@@ -586,7 +628,7 @@ dump_column_definition(Mapi mid, stream 
 
                mnstr_printf(toConsole, "\t\"%s\"%*s ",
                             c_name, CAP(slen - strlen(c_name)), "");
-               space = dump_type(mid, toConsole, c_type, c_type_digits, 
c_type_scale);
+               space = dump_type(mid, toConsole, c_type, c_type_digits, 
c_type_scale, hashge);
                if (strcmp(c_null, "false") == 0) {
                        mnstr_printf(toConsole, "%*s NOT NULL",
                                        CAP(13 - space), "");
@@ -763,6 +805,7 @@ describe_table(Mapi mid, char *schema, c
        int type = 0;
        size_t maxquerylen;
        char *sname = NULL;
+       int hashge;
 
        if (schema == NULL) {
                if ((sname = strchr(tname, '.')) != NULL) {
@@ -778,6 +821,8 @@ describe_table(Mapi mid, char *schema, c
                schema = sname;
        }
 
+       hashge = has_hugeint(mid);
+
        maxquerylen = 512 + strlen(tname) + strlen(schema);
 
        query = malloc(maxquerylen);
@@ -830,7 +875,7 @@ describe_table(Mapi mid, char *schema, c
                             "",
                             schema, tname);
 
-               if (dump_column_definition(mid, toConsole, schema, tname, NULL, 
foreign))
+               if (dump_column_definition(mid, toConsole, schema, tname, NULL, 
foreign, hashge))
                        goto bailout;
                if (type == 5)
                        mnstr_printf(toConsole, " ON '%s'", view);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to