dbaccess/source/ui/dlg/directsql.cxx |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

New commits:
commit 16a8943f7dbf338377fe486cc75116b89742c7b0
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Thu May 25 23:51:04 2023 +0200
Commit:     Julien Nabet <serval2...@yahoo.fr>
CommitDate: Fri May 26 09:09:53 2023 +0200

    tdf#153317: direct SQL: try to detect Bit field in Mysql/MariaDB
    
    Change-Id: I462cb28c15a0cd1d3c93f2335bcac02ca09c78e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152289
    Tested-by: Jenkins
    Reviewed-by: Julien Nabet <serval2...@yahoo.fr>

diff --git a/dbaccess/source/ui/dlg/directsql.cxx 
b/dbaccess/source/ui/dlg/directsql.cxx
index 9080e63dca3f..a82f8d4c10f8 100644
--- a/dbaccess/source/ui/dlg/directsql.cxx
+++ b/dbaccess/source/ui/dlg/directsql.cxx
@@ -318,8 +318,21 @@ namespace dbaui
                 int i = 1;
                 for (;;)
                 {
-                    // be dumb, treat everything as a string
-                    out.append(xRow->getString(i) + ",");
+                    // be dumb, treat everything as a string unless below
+                    // tdf#153317, at least "Bit" type in Mysql/MariaDB gives: 
"\000" or "\001"
+                    // so retrieve Sequence from getBytes, test if it has a 
length of 1 (so we avoid BLOB/CLOB or other complex types)
+                    // and test if the value of first byte is one of those.
+                    // In this case, there's a good chance it's a "Bit" field
+                    // remark: for unknown reason, getByte(i) gives "\000" 
even if the bit is at 1.
+                    auto seq = xRow->getBytes(i);
+                    if ((seq.getLength() == 1) && (seq[0] <= 1))
+                    {
+                        out.append(OUString::number(static_cast<int>(seq[0])) 
+ ",");
+                    }
+                    else
+                    {
+                        out.append(xRow->getString(i) + ",");
+                    }
                     i++;
                 }
             }

Reply via email to