[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - 2 commits - connectivity/qa connectivity/source

Tamas Bunth (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 6 14:26:32 UTC 2019


 connectivity/qa/connectivity/mysql/mysql.cxx                     |   45 ++++++++++
 connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx |    8 +
 2 files changed, 52 insertions(+), 1 deletion(-)

New commits:
commit 2459458a0d9bb194a1f0de63b8b4fd591b2c5d5f
Author:     Tamas Bunth <tamas.bunth at collabora.co.uk>
AuthorDate: Wed Jul 31 14:20:21 2019 +0200
Commit:     Tamás Bunth <btomi96 at gmail.com>
CommitDate: Tue Aug 6 16:25:29 2019 +0200

    mysqlc: Add test for textual blob types
    
    Test setting and querying the following data types:
    TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT
    
    Test them using prepared statements.
    
    Change-Id: I43387034ad8c32c3731cde70a22cc8b3dd652b78
    Reviewed-on: https://gerrit.libreoffice.org/76749
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/76872

diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx
index a3d88c065219..ce382f8efba7 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -54,6 +54,7 @@ public:
     void testTimestampField();
     void testNumericConversionPrepared();
     void testPreparedStmtIsAfterLast();
+    void testGetStringFromBloColumnb();
 
     CPPUNIT_TEST_SUITE(MysqlTestDriver);
     CPPUNIT_TEST(testDBConnection);
@@ -64,6 +65,7 @@ public:
     CPPUNIT_TEST(testTimestampField);
     CPPUNIT_TEST(testNumericConversionPrepared);
     CPPUNIT_TEST(testPreparedStmtIsAfterLast);
+    CPPUNIT_TEST(testGetStringFromBloColumnb);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -429,6 +431,49 @@ void MysqlTestDriver::testPreparedStmtIsAfterLast()
     bool hasData = xResultSet->next();
     CPPUNIT_ASSERT(!hasData); // now we are on "AfterLast"
     CPPUNIT_ASSERT(xResultSet->isAfterLast());
+    xStatement->executeUpdate("DROP TABLE IF EXISTS myTestTable");
+}
+
+void MysqlTestDriver::testGetStringFromBloColumnb()
+{
+    Reference<XConnection> xConnection = m_xDriver->connect(m_sUrl, m_infos);
+    if (!xConnection.is())
+        CPPUNIT_ASSERT_MESSAGE("cannot connect to data source!", xConnection.is());
+    uno::Reference<XStatement> xStatement = xConnection->createStatement();
+    CPPUNIT_ASSERT(xStatement.is());
+    xStatement->executeUpdate("DROP TABLE IF EXISTS myTestTable");
+
+    // create test table
+    xStatement->executeUpdate("CREATE TABLE myTestTable (id INTEGER PRIMARY KEY, tinytexty "
+                              "TINYTEXT, texty TEXT, mediumTexty MEDIUMTEXT, longtexty LONGTEXT)");
+    Reference<XPreparedStatement> xPrepared = xConnection->prepareStatement(
+        OUString{ "INSERT INTO myTestTable VALUES (?, ?, ?, ?, ?)" });
+    Reference<XParameters> xParams(xPrepared, UNO_QUERY);
+    constexpr int ROW_COUNT = 6;
+    for (int i = 0; i < ROW_COUNT; ++i)
+    {
+        xParams->setShort(1, i);
+        xParams->setString(2, OUString::number(i));
+        xParams->setString(3, OUString::number(i));
+        xParams->setString(4, OUString::number(i));
+        xParams->setString(5, OUString::number(i));
+        xPrepared->executeUpdate();
+    }
+
+    // query test table
+    xPrepared = xConnection->prepareStatement(
+        "SELECT tinytexty, texty, mediumtexty, longtexty from myTestTable where texty LIKE '3'");
+    Reference<XResultSet> xResultSet = xPrepared->executeQuery();
+    xResultSet->next();
+    Reference<XRow> xRow(xResultSet, UNO_QUERY);
+
+    // all the textual blob types should be able to be queried via getString().
+    CPPUNIT_ASSERT_EQUAL(OUString("3"), xRow->getString(1));
+    CPPUNIT_ASSERT_EQUAL(OUString("3"), xRow->getString(2));
+    CPPUNIT_ASSERT_EQUAL(OUString("3"), xRow->getString(3));
+    CPPUNIT_ASSERT_EQUAL(OUString("3"), xRow->getString(4));
+
+    xStatement->executeUpdate("DROP TABLE IF EXISTS myTestTable");
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver);
commit e04322c3adcff323c06b043f19c5b300c5b75d1d
Author:     Tamas Bunth <tamas.bunth at collabora.co.uk>
AuthorDate: Tue Jul 30 15:05:35 2019 +0200
Commit:     Tamás Bunth <btomi96 at gmail.com>
CommitDate: Tue Aug 6 16:25:21 2019 +0200

    mysqlc: Support reading blob as string
    
    Change-Id: I1ef0c3817bc255e7f0c38aca73c475b19d5d7d9b
    Reviewed-on: https://gerrit.libreoffice.org/76600
    Tested-by: Jenkins
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/76734
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/76871

diff --git a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx
index 3d69eb5d2248..ad240292de1c 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx
@@ -313,7 +313,10 @@ template <> DateTime OPreparedResultSet::retrieveValue(sal_Int32 column)
 
 template <> OUString OPreparedResultSet::retrieveValue(sal_Int32 column)
 {
-    if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(OUString)))
+    // redirect call to the appropiate method if needed
+    // BLOB can be simply read out as string
+    if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(OUString))
+        && m_aFields[column - 1].type != MYSQL_TYPE_BLOB)
         return getRowSetValue(column);
     const char* sStr = static_cast<const char*>(m_aData[column - 1].buffer);
 
@@ -351,6 +354,9 @@ ORowSetValue OPreparedResultSet::getRowSetValue(sal_Int32 nColumnIndex)
         case MYSQL_TYPE_DECIMAL:
         case MYSQL_TYPE_NEWDECIMAL:
             return getString(nColumnIndex);
+        case MYSQL_TYPE_BLOB:
+            throw SQLException("Column with type BLOB cannot be converted", *this, OUString(), 1,
+                               Any());
         default:
             SAL_WARN("connectivity.mysqlc", "OPreparedResultSet::getRowSetValue: unknown type: "
                                                 << m_aFields[nColumnIndex - 1].type);


More information about the Libreoffice-commits mailing list