Changeset: 7ca8c36b6831 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7ca8c36b6831
Modified Files:
clients/mapiclient/mclient.c
clients/mapilib/mapi.c
clients/mapilib/mapi.h
common/utils/conversion.c
monetdb5/mal/mal_client.c
monetdb5/mal/mal_client.h
monetdb5/mal/mal_session.c
monetdb5/mal/mal_session.h
monetdb5/modules/mal/mal_mapi.c
sql/backends/monet5/sql_result.c
Branch: protocol
Log Message:
Generate fake MAPI headers for TESTrenderer, and optionally send render widths
to the client.
Render widths are necessary so the TESTrenderer and TABLErenderer have the same
output as before.
diffs (truncated from 587 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
@@ -832,49 +832,9 @@ CSVrenderer(MapiHdl hdl)
if (i != fields - 1) {
*buffer_ptr++ = *sep;
}
-
- /*
-
- if (s == NULL)
- s = nullstring == default_nullstring ? "" :
nullstring;
- if (strchr(s, *sep) != NULL ||
- strchr(s, '\n') != NULL ||
- strchr(s, '"') != NULL) {
- mnstr_printf(toConsole, "%s\"",
- i == 0 ? "" : sep);
- while (*s) {
- switch (*s) {
- case '\n':
- mnstr_write(toConsole, "\\n",
1, 2);
- break;
- case '\t':
- mnstr_write(toConsole, "\\t",
1, 2);
- break;
- case '\r':
- mnstr_write(toConsole, "\\r",
1, 2);
- break;
- case '\\':
- mnstr_write(toConsole, "\\\\",
1, 2);
- break;
- case '"':
- mnstr_write(toConsole, "\"\"",
1, 2);
- break;
- default:
- mnstr_write(toConsole, s, 1, 1);
- break;
- }
- s++;
- }
- mnstr_write(toConsole, "\"", 1, 1);
- } else
- mnstr_printf(toConsole, "%s%s",
- i == 0 ? "" : sep, s);*/
- }
- //mnstr_printf(toConsole, "\n");
-
+ }
*buffer_ptr++ = 0;
puts(buffer);
-
}
}
@@ -1071,6 +1031,7 @@ TESTrenderer(MapiHdl hdl)
char *sep;
int i;
int prot10 = mapi_is_protocol10(hdl);
+ int header_rendered = 0;
SQLqueryEcho(hdl);
while (!mnstr_errnr(toConsole) && (!prot10 ? (reply = fetch_line(hdl))
!= 0 : (fields = fetch_row(hdl)) != 0)) {
@@ -1082,6 +1043,34 @@ TESTrenderer(MapiHdl hdl)
continue;
}
fields = mapi_split_line(hdl);
+ } else if (header_rendered == 0) {
+ header_rendered = 1;
+ // generate fake MAPI headers for the testweb
+ // table names
+ mnstr_printf(toConsole, "%% ");
+ for(int i = 0; i < fields; i++) {
+ mnstr_printf(toConsole, "%s%s",
mapi_get_table(hdl, i), i < fields - 1 ? ",\t" : " ");
+ }
+ mnstr_printf(toConsole, "# table_name\n");
+ // column names
+ mnstr_printf(toConsole, "%% ");
+ for(int i = 0; i < fields; i++) {
+ mnstr_printf(toConsole, "%s%s",
mapi_get_name(hdl, i), i < fields - 1 ? ",\t" : " ");
+ }
+ mnstr_printf(toConsole, "# name\n");
+ // column type names
+ mnstr_printf(toConsole, "%% ");
+ for(int i = 0; i < fields; i++) {
+ mnstr_printf(toConsole, "%s%s",
mapi_get_type(hdl, i), i < fields - 1 ? ",\t" : " ");
+ }
+ mnstr_printf(toConsole, "# type\n");
+ // column lengths
+ mnstr_printf(toConsole, "%% ");
+ for(int i = 0; i < fields; i++) {
+ mnstr_printf(toConsole, "%lld%s",
mapi_get_len(hdl, i), i < fields - 1 ? ",\t" : " ");
+ }
+ mnstr_printf(toConsole, "# length\n");
+ l = mapi_fetch_field_len(hdl, i);
}
sep = "[ ";
for (i = 0; i < fields; i++) {
@@ -3367,6 +3356,16 @@ main(int argc, char **argv)
}
}
+ // we need to know the column render width for the TEST and TABLE
formatters
+ if (output) {
+ setFormatter(output);
+ }
+ if (!output || (formatter == TESTformatter || formatter ==
TABLEformatter)) {
+ mapi_set_compute_column_width(mid, 1);
+ } else {
+ mapi_set_compute_column_width(mid, 0);
+ }
+
if (mid && mapi_error(mid) == MOK)
mapi_reconnect(mid); /* actually, initial connect */
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -838,6 +838,7 @@ struct MapiColumn {
char *columnname;
char *columntype;
int columnlength;
+ int typelen;
int digits;
int scale;
void *null_value;
@@ -944,6 +945,7 @@ struct MapiStruct {
stream *tracelog; /* keep a log for inspection */
stream *from, *to;
int index; /* to mark the log records */
+ int compute_column_widths;
};
struct MapiResultSet {
@@ -2873,7 +2875,7 @@ mapi_reconnect(Mapi mid)
if (prot_version == prot10 || prot_version ==
prot10compressed) {
// if we are using protocol 10, we have to send
either PROT10/PROT10COMPRESSED to the server
// so the server knows which protocol to use
- retval = snprintf(buf, BLOCK,
"%s:%s:%s:%s:%s:%s:%s%s:%zu:\n",
+ retval = snprintf(buf, BLOCK,
"%s:%s:%s:%s:%s:%s:%s%s%s:%zu:\n",
#ifdef WORDS_BIGENDIAN
"BIG",
#else
@@ -2884,6 +2886,7 @@ mapi_reconnect(Mapi mid)
prot_version == prot10 ? "PROT10" :
"PROT10COMPR",
comp == COMPRESSION_SNAPPY ? "SNAPPY" :
(comp == COMPRESSION_LZ4 ? "LZ4" : ""),
mid->colcomp == COLUMN_COMPRESSION_PFOR ?
",HAVEPFOR" : (mid->colcomp == COLUMN_COMPRESSION_BINPACK ? ",HAVEBINPACK" :
(mid->colcomp == COLUMN_COMPRESSION_PROTOBUF ? ",PROTOBUF" : (mid->colcomp ==
COLUMN_COMPRESSION_PROTOBUF_NOPACK ? ",PROTOBUFNOPACK" : ""))),
+ mid->compute_column_widths ?
"COMPUTECOLWIDTH" : "",
mid->blocksize);
} else {
retval = snprintf(buf, BLOCK,
"%s:%s:%s:%s:%s:\n",
@@ -4109,15 +4112,15 @@ parse_header_line(MapiHdl hdl, char *lin
*/
static char* mapi_convert_varchar(struct MapiColumn *col) {
- if (col->buffer_ptr[col->columnlength - 1] == '\0') {
+ if (col->buffer_ptr[col->typelen - 1] == '\0') {
// if the varchar buffer is not entirely filled, we can
directly use the data as char*
if (strcmp(col->buffer_ptr, (char*)col->null_value) == 0)
return NULL;
return (char*) col->buffer_ptr;
}
// if the buffer is filled, there is no null terminator so we have to
copy the data
- memcpy(col->dynamic_write_buf, col->buffer_ptr, col->columnlength);
- col->dynamic_write_buf[col->columnlength] = '\0';
+ memcpy(col->dynamic_write_buf, col->buffer_ptr, col->typelen);
+ col->dynamic_write_buf[col->typelen] = '\0';
if (strcmp(col->dynamic_write_buf, (char*)col->null_value) == 0)
return NULL;
return (char*) col->dynamic_write_buf;
@@ -4161,7 +4164,7 @@ mapi_string_conversion_function(hge,hge,
mapi_string_conversion_function(int,date,date);
static char* mapi_convert_decimal(struct MapiColumn *col) {
- if (conversion_decimal_to_string(col->buffer_ptr, col->write_buf,
COLBUFSIZ, col->scale, col->columnlength, col->null_value) < 0) {
+ if (conversion_decimal_to_string(col->buffer_ptr, col->write_buf,
COLBUFSIZ, col->scale, col->typelen, col->null_value) < 0) {
return NULL;
}
return (char*) col->write_buf;
@@ -4251,6 +4254,7 @@ read_into_cache(MapiHdl hdl, int lookahe
char *table_name, *col_name, *type_sql_name;
int typelen;
int null_len;
+ lng column_print_length;
if (!mnstr_readLng(mid->from,
&col_info_length)) {
return mid->error;
@@ -4291,20 +4295,27 @@ read_into_cache(MapiHdl hdl, int lookahe
if (mnstr_read(mid->from,
result->fields[i].null_value, null_len, 1) != 1) {
return mid->error;
}
+ column_print_length = typelen;
+ if (mid->compute_column_widths) {
+ if (!mnstr_readLng(mid->from,
&column_print_length)) {
+ return mid->error;
+ }
+ }
// fprintf(stderr, "%lld col_info_length=%lld,
table_name=%s, col_name=%s, type_sql_name=%s, type_len=%d\n",
// i, col_info_length, table_name,
col_name, type_sql_name, typelen);
result->fields[i].columnname = col_name;
result->fields[i].tablename = table_name;
result->fields[i].columntype = type_sql_name;
- result->fields[i].columnlength = typelen;
+ result->fields[i].typelen = typelen;
+ result->fields[i].columnlength =
column_print_length;
result->fields[i].dynamic_write_buf = NULL;
result->fields[i].converter = NULL;
if (strcasecmp(type_sql_name, "varchar") == 0
|| strcasecmp(type_sql_name, "char") == 0) {
if (typelen > 0) {
result->fields[i].converter =
(mapi_converter) mapi_convert_varchar;
-
result->fields[i].dynamic_write_buf = malloc(result->fields[i].columnlength *
sizeof(char));
+
result->fields[i].dynamic_write_buf = malloc(result->fields[i].typelen *
sizeof(char));
} else {
result->fields[i].converter =
(mapi_converter) mapi_convert_clob;
}
@@ -5696,7 +5707,7 @@ mapi_fetch_row(MapiHdl hdl)
// iterate over cols
for (i = 0; i < (size_t) result->fieldcnt; i++) {
result->fields[i].buffer_ptr = buf;
- if (result->fields[i].columnlength < 0) {
+ if (result->fields[i].typelen < 0) {
// variable-length column
lng col_len = *((lng*) buf);
assert((size_t) col_len <
hdl->mid->blocksize && col_len > 0);
@@ -5746,7 +5757,7 @@ mapi_fetch_row(MapiHdl hdl)
result->fields[i].buffer_ptr =
resbuffer;
} else {
#endif
- buf += nrows *
result->fields[i].columnlength;
+ buf += nrows *
result->fields[i].typelen;
#ifdef HAVE_PFOR
}
#endif
@@ -5758,7 +5769,7 @@ mapi_fetch_row(MapiHdl hdl)
result->tuple_count += nrows;
} else {
for (i = 0; i < (size_t) result->fieldcnt; i++) {
- if (result->fields[i].columnlength < 0) {
+ if (result->fields[i].typelen < 0) {
// variable-length column
if (hdl->mid->protobuf_res) {
if (hdl->mid->colcomp ==
COLUMN_COMPRESSION_PROTOBUF) {
@@ -5777,7 +5788,7 @@ mapi_fetch_row(MapiHdl hdl)
#endif
}
} else {
- result->fields[i].buffer_ptr +=
result->fields[i].columnlength;
+ result->fields[i].buffer_ptr +=
result->fields[i].typelen;
}
}
}
@@ -6222,4 +6233,8 @@ mapi_set_column_compression(Mapi mid, co
return 0;
}
-
+void
+mapi_set_compute_column_width(Mapi mid, int compute_column_width) {
+ mid->compute_column_widths = compute_column_width ? 1 : 0;
+
+}
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -237,6 +237,7 @@ mapi_export MapiMsg mapi_set_protocol(Ma
mapi_export MapiMsg mapi_set_compression(Mapi mid, const char* compression);
mapi_export MapiMsg mapi_set_column_compression(Mapi mid, const char* colcomp);
mapi_export void mapi_set_blocksize(Mapi mid, size_t blocksize);
+mapi_export void mapi_set_compute_column_width(Mapi mid, int
compute_column_width);
#ifdef _MSC_VER
mapi_export const char *wsaerror(int);
diff --git a/common/utils/conversion.c b/common/utils/conversion.c
--- a/common/utils/conversion.c
+++ b/common/utils/conversion.c
@@ -33,13 +33,15 @@ typedef void *ptr;
#endif
#endif
+#define NULL_STRING "NULL"
+
int
conversion_bit_to_string(char *dst, int len, const signed char *src, signed
char null_value)
{
if (len < 6) return -1;
if (*src == null_value)
- return snprintf(dst, len, "nil");
+ return snprintf(dst, len, NULL_STRING);
if (*src)
return snprintf(dst, len, "true");
return snprintf(dst, len, "false");
@@ -52,7 +54,7 @@ conversion_##TYPE##_to_string(char *dst,
{ \
if (len < TYPE##Strlen) return -1; \
if (*src == nullvalue) { \
- return snprintf(dst, len, "nil"); \
+ return snprintf(dst, len, NULL_STRING); \
} \
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list