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

Use digits to determine Time print precision.


diffs (117 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4111,7 +4111,7 @@ static char* mapi_convert_decimal(struct
 
 static char* mapi_convert_time(struct MapiColumn *col) {
        if (*((int*) col->buffer_ptr) == *((int*)col->null_value)) return NULL;
-       if (conversion_time_to_string(col->write_buf, COLBUFSIZ, (int*) 
col->buffer_ptr, *((int*)col->null_value), 0) < 0) {
+       if (conversion_time_to_string(col->write_buf, COLBUFSIZ, (int*) 
col->buffer_ptr, *((int*)col->null_value), col->digits, 0) < 0) {
                return NULL;
        }
        return (char*) col->write_buf;
@@ -4226,16 +4226,13 @@ read_into_cache(MapiHdl hdl, int lookahe
                                if (!mnstr_readStr(mid->from, table_name) ||
                                                !mnstr_readStr(mid->from, 
col_name) ||
                                                !mnstr_readStr(mid->from, 
type_sql_name) ||
-                                               !mnstr_readInt(mid->from, 
&typelen)) {
+                                               !mnstr_readInt(mid->from, 
&typelen) || 
+                                               !mnstr_readInt(mid->from, 
&result->fields[i].digits) || 
+                                               !mnstr_readInt(mid->from, 
&result->fields[i].scale)) {
                                        return mapi_setError(mid, "read error 
from stream while reading result set", "read_into_cache", MERROR);
                                }
 
-                               if (strcasecmp(type_sql_name, "decimal") == 0) {
-                                       // decimal type, read the scale as well
-                                       if (!mnstr_readInt(mid->from, 
&result->fields[i].scale)) {
-                                               return mapi_setError(mid, "read 
error from stream while reading result set", "read_into_cache", MERROR);
-                                       }
-                               } else if (strcasecmp(type_sql_name, 
"sec_interval") == 0) {
+                               if (strcasecmp(type_sql_name, "sec_interval") 
== 0) {
                                        result->fields[i].scale = 3;
                                }
 
diff --git a/common/utils/conversion.c b/common/utils/conversion.c
--- a/common/utils/conversion.c
+++ b/common/utils/conversion.c
@@ -262,25 +262,24 @@ conversion_date_to_string(char *dst, int
 }
 
 int 
-conversion_time_to_string(char *dst, int len, const int *src, int null_value, 
int timezone_diff) {
+conversion_time_to_string(char *dst, int len, const int *src, int null_value, 
int digits, int timezone_diff) {
        int sec, min, hour, ms;
-       //int ms;
        int time = *src;
        int mtime = 24 * 60 * 60 * 1000;
+       int res = 0;
        if (len < daytimeStrlen) return -1;
        if (*src == null_value) {
                strcpy(dst, NULL_STRING);
                return 3;
        }
+       // account for the timezone of the client
+       time += timezone_diff;
        // time has to be between 00:00 and 24:00
        if (time < 0)
                time = mtime + time;
        if (time > mtime)
                time = time - mtime;
-       // account for the timezone of the client
-       time += timezone_diff * 1000 * 60 * 60;
 
-       // for some reason, mclient does not render the ms part of the time, so 
we don't either
        hour = time / 3600000;
        time -= hour * 3600000;
        min = time / 60000;
@@ -288,7 +287,13 @@ conversion_time_to_string(char *dst, int
        sec = time / 1000;
        time -= sec * 1000;
        ms = time;
-       return sprintf(dst, "%02d:%02d:%02d.%03d000", hour, min, sec, ms);
+       if (res = sprintf(dst, "%02d:%02d:%02d.%03d000", hour, min, sec, ms) < 
0) {
+               return res;
+       }
+
+       // adjust displayed precision based on the digits
+       dst[9 + digits] = '\0';
+       return 9 + digits;
 }
 
 static int days_between_zero_and_epoch = 719528;
diff --git a/common/utils/conversion.h b/common/utils/conversion.h
--- a/common/utils/conversion.h
+++ b/common/utils/conversion.h
@@ -62,7 +62,7 @@ numeric_conversion(hge, hge);
 numeric_conversion(int, date);
 
 // *src is ms since 00:00:00
-int conversion_time_to_string(char *dst, int len, const int *src, int 
null_value, int timezone_diff);
+int conversion_time_to_string(char *dst, int len, const int *src, int 
null_value, int digits, int timezone_diff);
 
 // *src is time since epoch in ms
 int conversion_epoch_to_string(char *dst, int len, const lng *src, lng 
null_value);
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
@@ -1943,19 +1943,11 @@ static int mvc_export_resultset_prot10(m
 
                if (!mnstr_writeLng(s, (lng) max(max(strlen(c->tn), 
strlen(c->name)), strlen(type->sqlname)) + 1) ||
                                !write_str_term(s, c->tn) || !write_str_term(s, 
c->name) || !write_str_term(s, type->sqlname) ||
-                               !mnstr_writeInt(s, typelen)) {
+                               !mnstr_writeInt(s, typelen) || 
!mnstr_writeInt(s, c->type.digits) || !mnstr_writeInt(s, c->type.scale)) {
                        fres = -1;
                        goto cleanup;
                }
 
-               if (type->eclass == EC_DEC) {
-                       // if the type is a decimal, we write the scale as a 
4-byte integer as well
-                       if (!mnstr_writeInt(s, c->type.scale)) {
-                               fres = -1;
-                               goto cleanup;
-                       }
-               }
-
                // write NULL values for this column to the stream
                // NULL values are encoded as <size:int> <NULL value> (<size> 
is always <typelen> for fixed size columns)
                if (!mnstr_writeInt(s, nil_len)) {
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to