Changeset: e79f82d345d7 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e79f82d345d7 Modified Files: clients/mapiclient/mclient.c clients/mapilib/mapi.c sql/backends/monet5/sql_result.c Branch: protocol Log Message:
client diffs (185 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -330,13 +330,16 @@ fetch_line(MapiHdl hdl) 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); + // yeah right. circumvent your own api... +// char *reply; +// +// do { +// if ((reply = fetch_line(hdl)) == NULL) +// return 0; +// } while (*reply != '[' && *reply != '='); +// return mapi_split_line(hdl); +// + return mapi_fetch_row(hdl); } static void diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c --- a/clients/mapilib/mapi.c +++ b/clients/mapilib/mapi.c @@ -826,6 +826,7 @@ struct MapiColumn { int columnlength; int digits; int scale; + void* dataprot10; }; /* information about bound columns */ @@ -938,6 +939,7 @@ struct MapiResultSet { struct MapiColumn *fields; struct MapiRowBuf cache; int commentonly; /* only comments seen so far */ + mapi_int64 rows_read; }; struct MapiStatement { @@ -4010,13 +4012,23 @@ read_into_cache(MapiHdl hdl, int lookahe lng nr_rows; lng nr_cols; lng i; + result = malloc(sizeof(struct MapiResultSet)); + if (!result) { + // TODO: actually set mid->error :) + return mid->error; + } if (!mnstr_readInt(mid->from, &result_set_id) || !mnstr_readLng(mid->from, &nr_rows) || !mnstr_readLng(mid->from, &nr_cols)) { return mid->error; } fprintf(stderr, "result_set_id=%d, nr_rows=%llu, nr_cols=%lld\n", result_set_id, nr_rows, nr_cols); - + result->fieldcnt = nr_cols; + result->row_count = nr_rows; + result->fields = malloc(sizeof(struct MapiColumn) * result->fieldcnt); + result->tableid = result_set_id; + result->querytype = Q_TABLE; + result->tuple_count = 0; for (i = 0; i < nr_cols; i++) { lng col_info_length; @@ -4040,18 +4052,19 @@ read_into_cache(MapiHdl hdl, int lookahe !mnstr_readInt(mid->from, &typelen)) { 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); + 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; } + hdl->result = result; + hdl->active = result; { - lng nrows = 0; char dummy; // we flush on the other side so this read will always fail mnstr_readChr(mid->from, &dummy); - if (!mnstr_readLng(mid->from, &nrows)) { - return mid->error; - } - fprintf(stderr, "nrows=%llu\n", nrows); } @@ -5276,6 +5289,27 @@ mapi_fetch_row(MapiHdl hdl) int n; struct MapiResultSet *result; + if (hdl->mid->protocol == prot10) { + result = hdl->result; + result->rows_read++; + // do we have any rows in our cache + if (result->rows_read > result->tuple_count && result->rows_read < result->row_count) { + // read block from socket + lng nrows = 0; + // we flush on the other side so this read will always fail + if (!mnstr_readLng(mid->from, &nrows)) { + // FIXME: set hdl->mid to something + return hdl->mid->error; + } + + fprintf(stderr, "nrows=%llu\n", nrows); + + + // iterate over cols + } + return result->fieldcnt; + } + mapi_hdl_check(hdl, "mapi_fetch_row"); do { if ((reply = mapi_fetch_line(hdl)) == NULL) 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 @@ -1868,11 +1868,13 @@ static int mvc_export_resultset_prot10(r size_t i; size_t row = 0; size_t srow = 0; - + lng *var_col_len; BATiter *iterators; iterators = GDKmalloc(sizeof(BATiter) * t->nr_cols); - if (!iterators) { + var_col_len = GDKmalloc(sizeof(lng) * t->nr_cols); + + if (!iterators || !var_col_len) { return -1; } @@ -1897,6 +1899,7 @@ static int mvc_export_resultset_prot10(r int mtype = c->type.type->localtype; int typelen = ATOMsize(mtype); iterators[i] = bat_iterator(BATdescriptor(c->b)); + if (ATOMvarsized(mtype)) { typelen = -1; } @@ -1912,6 +1915,10 @@ static int mvc_export_resultset_prot10(r while (row < (size_t) count) { size_t crow = 0; size_t bytes_left = bsize; + for (i = 0; i < (size_t) t->nr_cols; i++) { + var_col_len[i] = 0; + } + // FIXME: this can be skipped if there are no variable-length types in the result set while (row < (size_t) count) { size_t rowsize = 0; @@ -1920,8 +1927,10 @@ static int mvc_export_resultset_prot10(r int mtype = c->type.type->localtype; if (ATOMvarsized(mtype)) { // FIXME support other types than string + size_t slen = strlen((const char*) BUNtail(iterators[i], row)) + 1; assert(mtype == TYPE_str); - rowsize += strlen((const char*) BUNtail(iterators[i], row)) + 1; + rowsize += slen; + var_col_len[i]+= slen; } else { rowsize += ATOMsize(mtype); } @@ -1941,6 +1950,9 @@ static int mvc_export_resultset_prot10(r if (ATOMvarsized(mtype)) { // FIXME support other types than string assert(mtype == TYPE_str); + if (!mnstr_writeLng(s, var_col_len[i])) { + return -1; + } for (crow = srow; crow < row; crow++) { if (!write_str_term(s, (char*) BUNtail(iterators[i], crow))) { return -1; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list