Changeset: aace52b0ce2d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=aace52b0ce2d
Modified Files:
        clients/mapiclient/mclient.c
        clients/mapilib/mapi.c
        clients/mapilib/mapi.h
        common/stream/stream.c
        common/stream/stream.h
        sql/backends/monet5/sql_result.c
Branch: protocol
Log Message:

Fix some mclient issues with new protocol.


diffs (268 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1070,16 +1070,19 @@ TESTrenderer(MapiHdl hdl)
        char *tp;
        char *sep;
        int i;
+       int prot10 = mapi_is_protocol10(hdl);
 
        SQLqueryEcho(hdl);
-       while (!mnstr_errnr(toConsole) && (reply = fetch_line(hdl)) != 0) {
-               if (*reply != '[') {
-                       if (*reply == '=')
-                               reply++;
-                       mnstr_printf(toConsole, "%s\n", reply);
-                       continue;
+       while (!mnstr_errnr(toConsole) && (!prot10 ? (reply = fetch_line(hdl)) 
!= 0 : (fields = fetch_row(hdl)) != 0)) {
+               if (!prot10) {
+                       if (*reply != '[') {
+                               if (*reply == '=')
+                                       reply++;
+                               mnstr_printf(toConsole, "%s\n", reply);
+                               continue;
+                       }
+                       fields = mapi_split_line(hdl);
                }
-               fields = mapi_split_line(hdl);
                sep = "[ ";
                for (i = 0; i < fields; i++) {
                        s = mapi_fetch_field(hdl, i);
@@ -1213,7 +1216,7 @@ static void
 CLEANrenderer(MapiHdl hdl)
 {
        char *reply;
-
+       int prot10 = mapi_is_protocol10(hdl);
        SQLqueryEcho(hdl);
        while (!mnstr_errnr(toConsole) && (reply = fetch_line(hdl)) != 0) {
                if (*reply == '%')
@@ -1228,12 +1231,17 @@ static void
 RAWrenderer(MapiHdl hdl)
 {
        char *line;
-
+       int prot10 = mapi_is_protocol10(hdl);
        SQLqueryEcho(hdl);
-       while ((line = fetch_line(hdl)) != 0) {
-               if (*line == '=')
-                       line++;
-               mnstr_printf(toConsole, "%s\n", line);
+       if (prot10) {
+               // "raw" renderer does not make much sense with prot10, because 
the raw protocol is binary data
+               CSVrenderer(hdl);
+       } else {
+               while ((line = fetch_line(hdl)) != 0) {
+                       if (*line == '=')
+                               line++;
+                       mnstr_printf(toConsole, "%s\n", line);
+               }
        }
 }
 
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -974,6 +974,7 @@ struct MapiStatement {
        int needmore;           /* need more input */
        int *pending_close;
        int npending_close;
+       int prot10_resultset;
        MapiHdl prev, next;
 };
 
@@ -2656,8 +2657,9 @@ mapi_reconnect(Mapi mid)
                        }
                }
                if (env_blocksize) {
+                       size_t blocksize;
                        errno = 0;
-                       size_t blocksize = (size_t) atol(env_blocksize);
+                       blocksize = (size_t) atol(env_blocksize);
                        if (errno != 0) {
                                errno = 0;
                                fprintf(stderr, "Incorrect block size: %s\n", 
env_blocksize);
@@ -4358,6 +4360,8 @@ read_into_cache(MapiHdl hdl, int lookahe
                        lng nr_rows;
                        lng nr_cols;
                        lng i;
+
+                       hdl->prot10_resultset = 1;
                        result = new_result(hdl);
 
                        if (!result) {
@@ -4468,8 +4472,7 @@ read_into_cache(MapiHdl hdl, int lookahe
                                        result->fields[i].converter = 
(mapi_converter) mapi_convert_unknown;
                                        // TODO: complain
                                }
-
-                               //printf("Column %d: %s - %s (%d)\n", i, 
col_name, type_sql_name, typelen);
+                               //printf("Column %d: %s - %s (%d, %p)\n", i, 
col_name, type_sql_name, typelen, result->fields[i].converter);
                        }
                        hdl->result = result;
                        hdl->active = result;
@@ -5622,6 +5625,7 @@ mapi_slice_row(struct MapiResultSet *res
        char *p;
        int i = 0;
 
+
        p = result->cache.line[cr].rows;
        if (p == NULL)
                return mapi_setError(result->hdl->mid, "Current row missing", 
"mapi_slice_row", MERROR);
@@ -5686,9 +5690,12 @@ mapi_split_line(MapiHdl hdl)
 {
        int n;
        struct MapiResultSet *result;
-
        result = hdl->result;
        assert(result != NULL);
+       if (hdl->mid->protocol == prot10 || hdl->mid->protocol == 
prot10compressed) {
+               assert(0);
+               return -1;
+       }
        if ((n = result->cache.line[result->cache.reader].fldcnt) == 0) {
                n = mapi_slice_row(result, result->cache.reader);
                /* no need to call mapi_store_bind since
@@ -5709,7 +5716,7 @@ mapi_fetch_row(MapiHdl hdl)
        size_t i;
        struct MapiResultSet *result;
 
-       if (hdl->mid->protocol == prot10 || hdl->mid->protocol == 
prot10compressed) {
+       if (hdl->prot10_resultset) {
                char* buf;
 
                result = hdl->result;
@@ -5720,6 +5727,7 @@ mapi_fetch_row(MapiHdl hdl)
                        hdl->active = NULL;
                        bs2_resetbuf(hdl->mid->from);
                        mnstr_readChr(hdl->mid->from, &dummy);
+                       hdl->prot10_resultset = 0;
                        return 0;
                }
                // if not, check if our cache is empty
@@ -5735,11 +5743,11 @@ mapi_fetch_row(MapiHdl hdl)
                                hdl->mid->errorstr = strdup("Failed to write 
confirm message to server.");
                                hdl->mid->error = 0;
                                fprintf(stderr, "Failure 2.\n");
+                               hdl->prot10_resultset = 0;
                                return hdl->mid->error;
                        }
 #endif
 
-
                        if (hdl->mid->colcomp == COLUMN_COMPRESSION_PROTOBUF || 
hdl->mid->colcomp == COLUMN_COMPRESSION_PROTOBUF_NOPACK) {
                                char dummy;
                                buffer buf;
@@ -5801,6 +5809,7 @@ mapi_fetch_row(MapiHdl hdl)
                                hdl->mid->errorstr = strdup("Failed to read row 
response");
                                hdl->mid->error = 0;
                                fprintf(stderr, "Failure 3.\n");
+                               hdl->prot10_resultset = 0;
                                return hdl->mid->error;
                        }
 
@@ -5963,8 +5972,15 @@ mapi_fetch_field(MapiHdl hdl, int fnr)
 {
        int cr;
        struct MapiResultSet *result;
-       if (hdl->mid->protocol == prot10 || hdl->mid->protocol == 
prot10compressed) {
+       if (hdl->prot10_resultset) {
                result = hdl->result;
+               if (result == NULL || 
+                       result->fields == NULL || 
+                       result->fields[fnr].converter == NULL || 
+                       result->rows_read == 0) {
+                       mapi_setError(hdl->mid, "Must do a successful 
mapi_fetch_row first", "mapi_fetch_field", MERROR);
+                       return 0;
+               }
                assert (result->rows_read <= result->tuple_count && 
result->rows_read <= result->row_count);
                if (fnr > result->fieldcnt) {
                        mapi_setError(hdl->mid, "column index out of bounds", 
"mapi_fetch_field", MERROR);
@@ -5999,9 +6015,14 @@ mapi_fetch_field_len(MapiHdl hdl, int fn
 {
        int cr;
        struct MapiResultSet *result;
-       if (hdl->mid->protocol == prot10 || hdl->mid->protocol == 
prot10compressed) {
+       if (hdl->prot10_resultset) {
+               char* value = mapi_fetch_field(hdl, fnr);
+               if (!value) {
+                       mapi_setError(hdl->mid, "Must do a successful 
mapi_fetch_row first", "mapi_fetch_field_len", MERROR);
+                       return 0;
+               }
                // this really should not be called for the new protocol
-               return strlen(mapi_fetch_field(hdl, fnr));
+               return strlen(value);
        }
        mapi_hdl_check0(hdl, "mapi_fetch_field_len");
 
@@ -6261,6 +6282,11 @@ mapi_get_active(Mapi mid)
        return mid->active;
 }
 
+int 
+mapi_is_protocol10(MapiHdl hdl) {
+       return hdl->prot10_resultset;
+}
+
 MapiMsg mapi_set_protocol(Mapi mid, const char* protocol) {
        if (strcasecmp(protocol, "prot9") == 0) {
                mid->protocol = prot9;
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -233,6 +233,7 @@ mapi_export char *mapi_quote(const char 
 mapi_export char *mapi_unquote(char *msg);
 mapi_export MapiHdl mapi_get_active(Mapi mid);
 
+mapi_export int mapi_is_protocol10(MapiHdl hdl);
 mapi_export MapiMsg mapi_set_protocol(Mapi mid, const char* prot);
 mapi_export MapiMsg mapi_set_compression(Mapi mid, const char* compression);
 mapi_export MapiMsg mapi_set_column_compression(Mapi mid, const char* colcomp);
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -3975,8 +3975,7 @@ block_stream(stream *s)
        return ns;
 }
 
-
-
+#ifdef VARINT_PADDING
 int 
 varint_size(int varint) {
        if      (varint < 0x80)    return 1;
@@ -4063,6 +4062,7 @@ read_varint(char *buf, int *value) {
             return varsize;
     }
 }
+#endif
 
 typedef struct bs2 {
        stream *s;              /* underlying stream */
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -258,10 +258,12 @@ typedef enum {
        COLUMN_COMPRESSION_PROTOBUF_NOPACK = 4
 } column_compression;
 
+#ifdef VARINT_PADDING
 stream_export int varint_size(int varint);
 stream_export int write_varint(char *buf, int varint);
 stream_export int read_varint_value(char *buf);
 stream_export int read_varint(char *buf, int *value);
+#endif
 
 stream_export stream *block_stream2(stream *s, size_t bufsiz, 
compression_method comp, column_compression colcomp);
 stream_export void* bs2_getbuf(stream *ss);
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -1898,6 +1898,7 @@ static int mvc_export_resultset_prot10(r
                        errno = 0;
                }
        }
+       fprintf(stdout, "Export resultset 10.\n");
 
        iterators = GDKzalloc(sizeof(BATiter) * t->nr_cols);
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to