Changeset: e002fb29f09e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e002fb29f09e
Modified Files:
clients/mapiclient/dump.c
Branch: Oct2020
Log Message:
Work around a bug somewhere that can leave a CHAR column with length 0.
diffs (38 lines):
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -969,6 +969,34 @@ dump_column_definition(Mapi mid, stream
mnstr_printf(toConsole, "\t");
space = dquoted_print(toConsole, c_name, " ");
mnstr_printf(toConsole, "%*s", CAP(slen - space), "");
+ if (s != NULL && t != NULL &&
+ strcmp(c_type, "char") == 0 && strcmp(c_type_digits,
"0") == 0) {
+ /* if the number of characters is not specified (due to
a bug),
+ * calculate a size */
+ char *c = descape(c_name);
+ if (c != NULL) {
+ size_t qlen = strlen(c) + strlen(s) + strlen(t)
+ 64;
+ char *q = malloc(qlen);
+ if (q != NULL) {
+ snprintf(q, qlen, "SELECT
max(length(\"%s\")) FROM \"%s\".\"%s\"", c, s, t);
+ MapiHdl h = mapi_query(mid, q);
+ if (h != NULL) {
+ if (mapi_fetch_row(h) != 0) {
+ const char *d =
mapi_fetch_field(h, 0);
+ free(c_type_digits);
+ /* if NULL, i.e. no
non-NULL values, fill in 1 */
+ c_type_digits =
strdup(d ? d : "1");
+ fprintf(stderr,
"Warning: fixing size of CHAR column for %s of table %s.%s\n", c_name, schema,
tname);
+ }
+ mapi_close_handle(h);
+ }
+ free(q);
+ }
+ free(c);
+ }
+ if (c_type_digits == NULL)
+ goto bailout;
+ }
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",
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list