Changeset: 56f10d08d102 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/56f10d08d102
Modified Files:
sql/backends/monet5/sql.c
testing/Mtest.py.in
Branch: ustr
Log Message:
Merge with default branch.
diffs (truncated from 775 to 300 lines):
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -320,37 +320,6 @@ static char *encoding;
#include "iconv-stream.h"
#endif
-/* The Mapi library eats away the comment lines, which we need to
- * detect end of debugging. We overload the routine to our liking. */
-
-static char *
-fetch_line(MapiHdl hdl)
-{
- char *reply;
-
- if ((reply = mapi_fetch_line(hdl)) == NULL)
- return NULL;
- if (strncmp(reply, "mdb>#", 5) == 0) {
- if (strncmp(reply, "mdb>#EOD", 8) == 0)
- setPrompt();
- else
- snprintf(promptbuf, sizeof(promptbuf), "mdb>");
- }
- return reply;
-}
-
-static int
-fetch_row(MapiHdl hdl)
-{
- char *reply;
-
- do {
- if ((reply = fetch_line(hdl)) == NULL)
- return 0;
- } while (*reply != '[' && *reply != '=');
- return mapi_split_line(hdl);
-}
-
static void
SQLsetSpecial(const char *command)
{
@@ -395,7 +364,7 @@ utf8strlenmax(char *s, char *e, size_t m
} else if (codepoint <= 0x1F || codepoint == 0177) {
len += 4; /* control, rendered as
"\\%03o" */
} else if (0x80 <= codepoint && codepoint <= 0x9F) {
- len += 6; /* control, rendered as
"u\\%04x" */
+ len += 6; /* control, rendered as
"\\u%04x" */
} else {
/* charwidth() returning -1 is caught by the
above */
len += charwidth(codepoint);
@@ -738,7 +707,7 @@ XMLrenderer(MapiHdl hdl)
if (name != NULL && *name != 0)
XMLprattr("name", name);
mnstr_printf(toConsole, ">\n");
- while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (fields =
fetch_row(hdl)) != 0) {
+ while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (fields =
mapi_fetch_row(hdl)) != 0) {
mnstr_printf(toConsole, "<row>");
for (i = 0; i < fields; i++) {
char *data = mapi_fetch_field(hdl, i);
@@ -775,7 +744,7 @@ EXPANDEDrenderer(MapiHdl hdl)
if (w > fieldw)
fieldw = w;
}
- while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (fields =
fetch_row(hdl)) != 0) {
+ while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (fields =
mapi_fetch_row(hdl)) != 0) {
int valuew = 0, len;
++rec;
for (i = 0; i < fields; i++) {
@@ -836,7 +805,7 @@ CSVrenderer(MapiHdl hdl)
}
mnstr_printf(toConsole, "\n");
}
- while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (fields =
fetch_row(hdl)) != 0) {
+ while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (fields =
mapi_fetch_row(hdl)) != 0) {
for (i = 0; i < fields; i++) {
s = mapi_fetch_field(hdl, i);
if (!noquote && s != NULL && s[strcspn(s, specials)] !=
'\0') {
@@ -1070,7 +1039,7 @@ TESTrenderer(MapiHdl hdl)
char *sep;
int i;
- while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (reply =
fetch_line(hdl)) != 0) {
+ while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (reply =
mapi_fetch_line(hdl)) != 0) {
if (*reply != '[') {
if (*reply == '=')
reply++;
@@ -1221,7 +1190,7 @@ RAWrenderer(MapiHdl hdl)
{
char *line;
- while ((line = fetch_line(hdl)) != 0) {
+ while ((line = mapi_fetch_line(hdl)) != 0) {
if (*line == '=')
line++;
mnstr_printf(toConsole, "%s\n", line);
@@ -1264,12 +1233,12 @@ SQLdebugRendering(MapiHdl hdl)
int cnt = 0;
snprintf(promptbuf, sizeof(promptbuf), "mdb>");
- while ((reply = fetch_line(hdl))) {
+ while ((reply = mapi_fetch_line(hdl))) {
cnt++;
mnstr_printf(toConsole, "%s\n", reply);
if (strncmp(reply, "mdb>#EOD", 8) == 0) {
cnt = 0;
- while ((reply = fetch_line(hdl)))
+ while ((reply = mapi_fetch_line(hdl)))
mnstr_printf(toConsole, "%s\n", reply);
break;
}
@@ -1515,7 +1484,7 @@ SQLrenderer(MapiHdl hdl)
lines = SQLheader(hdl, len, printfields, fields != printfields);
int64_t nrows = 0; /* count number of rows printed
*/
- while ((rfields = fetch_row(hdl)) != 0) {
+ while ((rfields = mapi_fetch_row(hdl)) != 0) {
if (mnstr_errnr(toConsole) != MNSTR_NO__ERROR)
continue;
if (rfields != fields) {
@@ -1858,9 +1827,9 @@ format_result(Mapi mid, MapiHdl hdl, boo
mnstr_printf(stderr_stream,
"invalid/unknown response from
server, "
"ignoring output\n");
- for (i = 0; i < 5 && (reply = fetch_line(hdl))
!= 0; i++)
+ for (i = 0; i < 5 && (reply =
mapi_fetch_line(hdl)) != 0; i++)
mnstr_printf(stderr_stream, "? %s\n",
reply);
- if (i == 5 && fetch_line(hdl) != 0) {
+ if (i == 5 && mapi_fetch_line(hdl) != 0) {
mnstr_printf(stderr_stream,
"(remaining output
omitted, "
"use \\fraw to examine in
detail)\n");
@@ -1872,7 +1841,7 @@ format_result(Mapi mid, MapiHdl hdl, boo
* logic there doesn't expect
* random unread garbage
* somehow */
- while (fetch_line(hdl) != 0)
+ while (mapi_fetch_line(hdl) != 0)
;
}
continue;
@@ -2579,7 +2548,7 @@ doFile(Mapi mid, stream *fp, bool useins
size_t tquerylen = 0;
hdl = mapi_query(mid, "select
value from sys.env() where name = 'monet_version'");
CHECK_RESULT(mid, hdl, buf, fp);
- if (fetch_row(hdl) > 0) {
+ if (mapi_fetch_row(hdl) > 0) {
const char *version =
mapi_fetch_field(hdl, 0);
int major, minor, patch;
if (version &&
@@ -2626,7 +2595,7 @@ doFile(Mapi mid, stream *fp, bool useins
free(query);
CHECK_RESULT(mid, hdl, buf, fp);
char *prevs1name = NULL,
*prevt1name = NULL;
- while (fetch_row(hdl) > 0) {
+ while (mapi_fetch_row(hdl) > 0)
{
const char *s1name =
mapi_fetch_field(hdl, 0);
const char *t1name =
mapi_fetch_field(hdl, 1);
const char *c1name =
mapi_fetch_field(hdl, 2);
@@ -2829,7 +2798,7 @@ doFile(Mapi mid, stream *fp, bool useins
hdl = mapi_query(mid, query);
free(query);
CHECK_RESULT(mid, hdl, buf, fp);
- while (fetch_row(hdl) == 3) {
+ while (mapi_fetch_row(hdl) ==
3) {
const char *type =
mapi_fetch_field(hdl, 0);
const char *name =
mapi_fetch_field(hdl, 1);
const char *remark =
mapi_fetch_field(hdl, 2);
@@ -3924,7 +3893,11 @@ main(int argc, char **argv)
exit(2);
}
+#if SIZEOF_VOID_P == 4
mapi_cache_limit(mid, 1000);
+#else
+ mapi_cache_limit(mid, 5000);
+#endif
mapi_setAutocommit(mid, autocommit);
if (mode == SQL && !settz)
mapi_set_time_zone(mid, 0);
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -3127,7 +3127,10 @@ parse_header_line(MapiHdl hdl, char *lin
if (result->fieldcnt > result->maxfields) {
REALLOC(result->fields, result->fieldcnt);
- memset(result->fields + result->maxfields, 0,
(result->fieldcnt - result->maxfields) * sizeof(*result->fields));
+ for (int i = result->maxfields; i < result->fieldcnt;
i++)
+ result->fields[i] = (struct MapiColumn) {
+ .columnlength = -1,
+ };
result->maxfields = result->fieldcnt;
}
@@ -3162,7 +3165,10 @@ parse_header_line(MapiHdl hdl, char *lin
result->fieldcnt = n;
if (n > result->maxfields) {
REALLOC(result->fields, n);
- memset(result->fields + result->maxfields, 0, (n -
result->maxfields) * sizeof(*result->fields));
+ for (int i = result->maxfields; i < n; i++)
+ result->fields[i] = (struct MapiColumn) {
+ .columnlength = -1,
+ };
result->maxfields = n;
}
}
@@ -4339,25 +4345,23 @@ mapi_slice_row(struct MapiResultSet *res
free(p);
}
if (i != result->fieldcnt) {
- int j;
- for (j = 0; j < result->fieldcnt; j++) {
- if (result->fields[j].columnname)
- free(result->fields[j].columnname);
- result->fields[j].columnname = NULL;
- if (result->fields[j].columntype)
- free(result->fields[j].columntype);
- result->fields[j].columntype = NULL;
- if (result->fields[j].tablename)
- free(result->fields[j].tablename);
- result->fields[j].tablename = NULL;
- result->fields[j].columnlength = 0;
+ for (int j = 0; j < result->fieldcnt; j++) {
+ free(result->fields[j].columnname);
+ free(result->fields[j].columntype);
+ free(result->fields[j].tablename);
+ result->fields[j] = (struct MapiColumn) {
+ .columnlength = -1,
+ };
}
}
if (i > result->fieldcnt) {
result->fieldcnt = i;
if (i > result->maxfields) {
REALLOC(result->fields, i);
- memset(result->fields + result->maxfields, 0, (i -
result->maxfields) * sizeof(*result->fields));
+ for (int j = result->maxfields; j < i; j++)
+ result->fields[j] = (struct MapiColumn) {
+ .columnlength = -1,
+ };
result->maxfields = i;
}
}
@@ -4571,14 +4575,65 @@ mapi_get_table(MapiHdl hdl, int fnr)
return 0;
}
+#include "mutf8.h"
+
+static size_t
+strwidth(const char *s)
+{
+ if (s == NULL)
+ return 0;
+ size_t len = 0;
+
+ for (uint32_t state = 0, codepoint = 0; *s; s++) {
+ switch (decode(&state, &codepoint, (uint8_t) *s)) {
+ case UTF8_ACCEPT: {
+ int n = charwidth(codepoint);
+ if (n >= 0)
+ len += n;
+ else
+ len++; /* assume width 1 if
unprintable */
+ if (len >= (unsigned) INT_MAX)
+ return INT_MAX;
+ break;
+ }
+ default:
+ break;
+ case UTF8_REJECT:
+ assert(0);
+ }
+ }
+ return len;
+}
+
int
mapi_get_len(MapiHdl hdl, int fnr)
{
struct MapiResultSet *result;
mapi_hdl_check0(hdl);
- if ((result = hdl->result) != 0 && fnr >= 0 && fnr < result->fieldcnt)
+ if ((result = hdl->result) != 0 && fnr >= 0 && fnr < result->fieldcnt) {
+ if (result->fields[fnr].columnlength < 0) {
+ size_t maxlen = 0;
+ Mapi mid = hdl->mid;
+ if (mid->active && read_into_cache(mid->active, 0) !=
MOK)
+ return 0;
+ for (int i = 0; i < result->cache.writer; i++) {
+ if (result->cache.line[i].rows == NULL ||
+ result->cache.line[i].rows[0] != '[')
+ continue;
+ mapi_slice_row(result, i);
+ size_t len =
strwidth(result->cache.line[i].anchors[fnr]);
+ if (len > maxlen)
+ maxlen = len;
+ if (maxlen > (size_t) INT_MAX) {
+ maxlen = (size_t) INT_MAX;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]