Changeset: 2eb9b2081c99 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2eb9b2081c99
Modified Files:
clients/mapilib/mapi.c
sql/backends/monet5/sql_result.c
Branch: protocol
Log Message:
Add support for CHAR type and use correct DECIMAL type typelen.
diffs (143 lines):
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4100,6 +4100,13 @@ parse_header_line(MapiHdl hdl, char *lin
*/
static char* mapi_convert_varchar(struct MapiColumn *col) {
+ if (col->buffer_ptr[col->columnlength - 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';
if (strcmp(col->dynamic_write_buf, (char*)col->null_value) == 0)
@@ -4416,7 +4423,7 @@ read_into_cache(MapiHdl hdl, int lookahe
result->fields[i].dynamic_write_buf = NULL;
result->fields[i].converter = NULL;
- if (strcasecmp(type_sql_name, "varchar") == 0) {
+ if (strcasecmp(type_sql_name, "varchar") == 0
|| strcasecmp(type_sql_name, "char") == 0) {
result->fields[i].converter =
(mapi_converter) mapi_convert_varchar;
result->fields[i].dynamic_write_buf =
malloc(result->fields[i].columnlength * sizeof(char));
} else if (strcasecmp(type_sql_name, "clob") ==
0) {
@@ -4439,9 +4446,12 @@ read_into_cache(MapiHdl hdl, int lookahe
} else if (strcasecmp(type_sql_name, "bigint")
== 0) {
result->fields[i].converter =
(mapi_converter) mapi_convert_lng;
} else {
+ fprintf(stderr, "Unrecognized sql type:
%s\n", type_sql_name);
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);
}
hdl->result = result;
hdl->active = result;
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
@@ -1922,47 +1922,6 @@ static int mvc_export_resultset_prot10(r
int retval = -1;
iterators[i] = bat_iterator(BATdescriptor(c->b));
- /*if (strcasecmp(c->type.type->sqlname, "decimal") == 0) {
- str res = MAL_SUCCEED;
- int bat_type = ATOMstorage(iterators[i].b->ttype);
- int hpos = c->type.scale;
- bat result = 0;
-
- //decimal values can be stored in various numeric fields, so
check the numeric field and convert the one it's actually stored in
- switch(bat_type)
- {
- case TYPE_bte:
- res = batbte_dec2_dbl(&result, &hpos,
&iterators[i].b->batCacheid);
- break;
- case TYPE_sht:
- res = batsht_dec2_dbl(&result, &hpos,
&iterators[i].b->batCacheid);
- break;
- case TYPE_int:
- res = batint_dec2_dbl(&result, &hpos,
&iterators[i].b->batCacheid);
- break;
- case TYPE_lng:
- res = batlng_dec2_dbl(&result, &hpos,
&iterators[i].b->batCacheid);
- break;
- #ifdef HAVE_HGE
- case TYPE_hge:
- res = bathge_dec2_dbl(&result, &hpos,
&iterators[i].b->batCacheid);
- break;
- #endif
- default:
- fres = -1;
- goto cleanup;
- }
- if (res == MAL_SUCCEED) {
- mtype = TYPE_dbl;
- typelen = sizeof(dbl);
- BBPunfix(iterators[i].b->batCacheid);
- iterators[i].b = BATdescriptor(result);
- } else {
- fres = -1;
- goto cleanup;
- }
- }*/
-
if (ATOMvarsized(mtype)) {
// FIXME support other types than string
assert(mtype == TYPE_str);
@@ -1970,13 +1929,12 @@ static int mvc_export_resultset_prot10(r
// varchar with fixed max length
typelen = c->type.digits;
fixed_lengths += typelen;
- nil_len = typelen;
} else {
// variable length strings
typelen = -1;
varsized++;
- nil_len = strlen(str_nil) + 1;
}
+ nil_len = strlen(str_nil) + 1;
} else {
fixed_lengths += typelen;
nil_len = typelen;
@@ -2006,10 +1964,7 @@ static int mvc_export_resultset_prot10(r
switch(ATOMstorage(mtype)) {
case TYPE_str:
- retval = 1;
- for(j = 0; j < (size_t) nil_len; j++) {
- retval = retval && mnstr_writeBte(s,
str_nil[j]);
- }
+ retval = write_str_term(s, str_nil);
break;
case TYPE_bit:
case TYPE_bte:
@@ -2115,6 +2070,7 @@ static int mvc_export_resultset_prot10(r
break;
}
#endif
+ //printf("Rows: %zu\n", (size_t)(row - srow));
assert(bs2_buffer(s).pos == 0);
@@ -2207,7 +2163,7 @@ static int mvc_export_resultset_prot10(r
if (c->type.digits > 0) {
// varchar
size_t buflen = c->type.digits * (row -
srow);
- char *tmpbuf = GDKmalloc(buflen);
+ char *tmpbuf = GDKmalloc(buflen *
sizeof(char));
char *bufptr = tmpbuf;
char *ptr;
assert(tmpbuf);
@@ -2241,7 +2197,7 @@ static int mvc_export_resultset_prot10(r
} else {
int atom_size = ATOMsize(mtype);
if (strcasecmp(c->type.type->sqlname,
"decimal") == 0) {
- atom_size = sizeof(dbl);
+ atom_size =
ATOMsize(ATOMstorage(mtype));
}
#ifdef HAVE_BINPACK
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list