Changeset: 1697b26f2155 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1697b26f2155
Modified Files:
        sql/backends/monet5/sql_cast.c
        sql/backends/monet5/sql_result.c
        sql/test/BugTracker-2009/Tests/bool-str-bug.stable.out
        sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out
        
sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out.int128
Branch: Dec2016
Log Message:

fix bug 6110, if use t/f and true/false when possible, when converting boolean
values to string


diffs (294 lines):

diff --git a/sql/backends/monet5/sql_cast.c b/sql/backends/monet5/sql_cast.c
--- a/sql/backends/monet5/sql_cast.c
+++ b/sql/backends/monet5/sql_cast.c
@@ -367,6 +367,9 @@ SQLstr_cast_(str *res, mvc *m, int eclas
        int sz = MAX(2, len + 1);       /* nil should fit */
 
        if (tpe != TYPE_str) {
+               /* TODO get max size for all from type */
+               if (len == 0 && tpe == TYPE_bit) /* should hold false */
+                       sz = 6;
                r = GDKmalloc(sz);
                if (r == NULL)
                        throw(SQL, "str_cast", MAL_MALLOC_FAIL);
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
@@ -1191,8 +1191,15 @@ convert2str(mvc *m, int eclass, int d, i
                l = sql_timestamp_tostr((void *) &ts_res, buf, &len, mtype, p);
        } else if (eclass == EC_BIT) {
                bit b = *(bit *) p;
-               (*buf)[0] = '0' + !!b; /* or: '1' - !b */
-               (*buf)[1] = 0;
+               if (len <= 0 || len > 5) {
+                       if (b)
+                               strcpy(*buf, "true");
+                       else
+                               strcpy(*buf, "false");
+               } else {
+                       (*buf)[0] = b?'t':'f';
+                       (*buf)[1] = 0;
+               }
        } else {
                l = (*BATatoms[mtype].atomToStr) (buf, &len, p);
        }
diff --git a/sql/test/BugTracker-2009/Tests/bool-str-bug.stable.out 
b/sql/test/BugTracker-2009/Tests/bool-str-bug.stable.out
--- a/sql/test/BugTracker-2009/Tests/bool-str-bug.stable.out
+++ b/sql/test/BugTracker-2009/Tests/bool-str-bug.stable.out
@@ -31,8 +31,8 @@ Ready.
 % b # name
 % char # type
 % 1 # length
-[ "1"  ]
-[ "0"  ]
+[ "t"  ]
+[ "f"  ]
 [ NULL ]
 
 # 19:54:05 >  
diff --git 
a/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out 
b/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out
--- a/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out
+++ b/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out
@@ -132,40 +132,40 @@ Ready.
 % v,   L3 # name
 % boolean,     char # type
 % 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
 [ NULL,        NULL    ]
 #SELECT v, convert(v, varchar(6)) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     varchar # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, convert(v, CHARACTER LARGE OBJECT) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, convert(v, Clob) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as boolean) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
@@ -222,40 +222,40 @@ Ready.
 % v,   L3 # name
 % boolean,     char # type
 % 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as varchar(6)) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     varchar # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as CHARACTER LARGE OBJECT) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as Clob) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #DROP TABLE T_BOOLEAN;
 #CREATE TABLE T_blob (v BLOB);
diff --git 
a/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out.int128
 
b/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out.int128
--- 
a/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out.int128
+++ 
b/sql/test/BugTracker-2016/Tests/convert-function-test.Bug-3460.stable.out.int128
@@ -146,40 +146,40 @@ Ready.
 % v,   L3 # name
 % boolean,     char # type
 % 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
 [ NULL,        NULL    ]
 #SELECT v, convert(v, varchar(6)) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     varchar # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, convert(v, CHARACTER LARGE OBJECT) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, convert(v, Clob) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as boolean) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
@@ -246,40 +246,40 @@ Ready.
 % v,   L3 # name
 % boolean,     char # type
 % 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
+[ true,        "t"     ]
+[ false,       "f"     ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as varchar(6)) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     varchar # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as CHARACTER LARGE OBJECT) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #SELECT v, cast(v as Clob) from T_BOOLEAN;
 % sys.t_boolean,       sys.L3 # table_name
 % v,   L3 # name
 % boolean,     clob # type
-% 5,   1 # length
-[ true,        "1"     ]
-[ false,       "0"     ]
-[ true,        "1"     ]
-[ false,       "0"     ]
+% 5,   5 # length
+[ true,        "true"  ]
+[ false,       "false" ]
+[ true,        "true"  ]
+[ false,       "false" ]
 [ NULL,        NULL    ]
 #DROP TABLE T_BOOLEAN;
 #CREATE TABLE T_blob (v BLOB);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to