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

2019-08-06 Thread Tamas Bunth (via logerrit)
 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 
AuthorDate: Wed Jul 31 14:20:21 2019 +0200
Commit: Tamás Bunth 
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 
Reviewed-by: Tamás Bunth 
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 = m_xDriver->connect(m_sUrl, m_infos);
+if (!xConnection.is())
+CPPUNIT_ASSERT_MESSAGE("cannot connect to data source!", 
xConnection.is());
+uno::Reference 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 xPrepared = xConnection->prepareStatement(
+OUString{ "INSERT INTO myTestTable VALUES (?, ?, ?, ?, ?)" });
+Reference 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 = xPrepared->executeQuery();
+xResultSet->next();
+Reference 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 
AuthorDate: Tue Jul 30 15:05:35 2019 +0200
Commit: Tamás Bunth 
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 
Reviewed-on: https://gerrit.libreoffice.org/76734
Tested-by: Jenkins CollaboraOffice 
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

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

2019-08-06 Thread Tamas Bunth (via logerrit)
 connectivity/qa/connectivity/mysql/mysql.cxx |   41 ++
 connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx |  172 
+-
 connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.hxx |7 
 connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx  |   82 ++--
 connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx  |   22 +
 5 files changed, 199 insertions(+), 125 deletions(-)

New commits:
commit ea97f1e39015e36958374157e98b120bec47cb69
Author: Tamas Bunth 
AuthorDate: Mon Jul 29 13:27:38 2019 +0200
Commit: Tamás Bunth 
CommitDate: Tue Aug 6 16:25:12 2019 +0200

mysqlc: Fix query of cursor position in result set

Fix queries like "IsAfterLast" in result sets of prepared statements in
the mysql driver.

Cursor position is stored in the driver, since the mysql C driver does
not support the query of the cursor position.

The cursor position works the following way:
- 0 means the cursor is on "BeforeFirst". In that state calling of
  getXXX() methods is user error.
- 1 means the first row is already fetched.
- n means the last fow is fetched, where n is the total number of rows
  in the result set.
- Everything bigger than n is "AfterLast"

Change-Id: I131f2042606897019cc0f868dbc4151faf4850ac
Reviewed-on: https://gerrit.libreoffice.org/76549
Tested-by: Jenkins
Reviewed-by: Tamás Bunth 
Reviewed-on: https://gerrit.libreoffice.org/76583
Tested-by: Jenkins CollaboraOffice 
Reviewed-on: https://gerrit.libreoffice.org/76870

diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx 
b/connectivity/qa/connectivity/mysql/mysql.cxx
index 546e916bd0a7..a3d88c065219 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -53,6 +53,7 @@ public:
 void testDBMetaData();
 void testTimestampField();
 void testNumericConversionPrepared();
+void testPreparedStmtIsAfterLast();
 
 CPPUNIT_TEST_SUITE(MysqlTestDriver);
 CPPUNIT_TEST(testDBConnection);
@@ -62,6 +63,7 @@ public:
 CPPUNIT_TEST(testDBMetaData);
 CPPUNIT_TEST(testTimestampField);
 CPPUNIT_TEST(testNumericConversionPrepared);
+CPPUNIT_TEST(testPreparedStmtIsAfterLast);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -390,6 +392,45 @@ void MysqlTestDriver::testNumericConversionPrepared()
 xStatement->executeUpdate("DROP TABLE myTestTable");
 }
 
+/**
+ * Test cursor positioning method isAfterLast in case of using prepared
+ * statement.
+ */
+void MysqlTestDriver::testPreparedStmtIsAfterLast()
+{
+Reference xConnection = m_xDriver->connect(m_sUrl, m_infos);
+if (!xConnection.is())
+CPPUNIT_ASSERT_MESSAGE("cannot connect to data source!", 
xConnection.is());
+uno::Reference 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)");
+Reference xPrepared
+= xConnection->prepareStatement(OUString{ "INSERT INTO myTestTable 
VALUES (?)" });
+Reference xParams(xPrepared, UNO_QUERY);
+constexpr int ROW_COUNT = 6;
+for (int i = 0; i < ROW_COUNT; ++i)
+{
+xParams->setShort(1, i);
+xPrepared->executeUpdate();
+}
+
+// query test table
+xPrepared = xConnection->prepareStatement("SELECT id from myTestTable 
where id = 3");
+Reference xResultSet = xPrepared->executeQuery();
+
+// There should be exactly one row, therefore IsAfterLast is false at 
first.
+xResultSet->next();
+CPPUNIT_ASSERT(!xResultSet->isAfterLast());
+
+// attempt to fetch more data
+bool hasData = xResultSet->next();
+CPPUNIT_ASSERT(!hasData); // now we are on "AfterLast"
+CPPUNIT_ASSERT(xResultSet->isAfterLast());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx
index ead866968ead..3d69eb5d2248 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx
@@ -100,6 +100,62 @@ const std::type_index 
getTypeFromMysqlType(enum_field_types type)
 }
 }
 
+bool OPreparedResultSet::fetchResult()
+{
+// allocate array if it does not exist
+if (m_aData == nullptr)
+{
+m_aData.reset(new MYSQL_BIND[m_nColumnCount]);
+memset(m_aData.get(), 0, m_nColumnCount * sizeof(MYSQL_BIND));
+m_aMetaData.reset(new BindMetaData[m_nColumnCount]);
+}
+for (sal_Int32 i = 0; i < m_nColumnCount; ++i)
+{
+m_aMetaData[i].is_null = 0;
+m_aMetaData[i].length = 0l;
+m_aMetaData[i].error = 0;
+
+m_aData[i].is_null = &m_aMetaData[i].is_null;
+  

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

2019-08-02 Thread Tamas Bunth (via logerrit)
 connectivity/qa/connectivity/mysql/mysql.cxx|   36 
+
 connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx |   11 +-
 connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx |2 
 connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx |   40 
+-
 4 files changed, 67 insertions(+), 22 deletions(-)

New commits:
commit 4f2271cef80ade0edfc272afd13388a8d67ccf2e
Author: Tamas Bunth 
AuthorDate: Tue Jan 29 13:00:21 2019 +0100
Commit: Tamás Bunth 
CommitDate: Fri Aug 2 16:49:35 2019 +0200

mysqlc: fix timestamp query of result set

Also add test for inserting and reading timestamp values.

Change-Id: I2ba997c438f4e33965b0fe0602e58eddeff38b01
Reviewed-on: https://gerrit.libreoffice.org/67066
Tested-by: Jenkins
Reviewed-by: Tamás Bunth 
Reviewed-on: https://gerrit.libreoffice.org/67091
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 
Reviewed-on: https://gerrit.libreoffice.org/76730
Tested-by: Jenkins CollaboraOffice 

diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx 
b/connectivity/qa/connectivity/mysql/mysql.cxx
index 77e82c9cdfc5..38683149d432 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -20,6 +20,8 @@
 #include 
 #include 
 #include 
+
+#include 
 #include 
 #include 
 
@@ -49,6 +51,7 @@ public:
 void testDBPositionChange();
 void testMultipleResultsets();
 void testDBMetaData();
+void testTimestampField();
 
 CPPUNIT_TEST_SUITE(MysqlTestDriver);
 CPPUNIT_TEST(testDBConnection);
@@ -56,6 +59,7 @@ public:
 CPPUNIT_TEST(testIntegerInsertAndQuery);
 CPPUNIT_TEST(testMultipleResultsets);
 CPPUNIT_TEST(testDBMetaData);
+CPPUNIT_TEST(testTimestampField);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -322,6 +326,38 @@ void MysqlTestDriver::testDBMetaData()
 nUpdateCount = xStatement->executeUpdate("DROP TABLE myTestTable");
 }
 
+void MysqlTestDriver::testTimestampField()
+{
+Reference xConnection = m_xDriver->connect(m_sUrl, m_infos);
+if (!xConnection.is())
+CPPUNIT_ASSERT_MESSAGE("cannot connect to data source!", 
xConnection.is());
+uno::Reference xStatement = xConnection->createStatement();
+CPPUNIT_ASSERT(xStatement.is());
+xStatement->executeUpdate("DROP TABLE IF EXISTS myTestTable");
+
+xStatement->executeUpdate(
+"CREATE TABLE myTestTable (id INTEGER PRIMARY KEY, mytimestamp 
timestamp)");
+xStatement->executeUpdate("INSERT INTO myTestTable VALUES (1, '2008-02-16 
20:15:03')");
+
+// now let's query
+Reference xResultSet
+= xStatement->executeQuery("SELECT mytimestamp from myTestTable");
+
+xResultSet->next(); // use it
+Reference xRow(xResultSet, UNO_QUERY);
+CPPUNIT_ASSERT_MESSAGE("cannot extract row from result set!", xRow.is());
+util::DateTime dt = xRow->getTimestamp(1);
+CPPUNIT_ASSERT_EQUAL(static_cast(2008), dt.Year);
+CPPUNIT_ASSERT_EQUAL(static_cast(2), dt.Month);
+CPPUNIT_ASSERT_EQUAL(static_cast(16), dt.Day);
+
+CPPUNIT_ASSERT_EQUAL(static_cast(20), dt.Hours);
+CPPUNIT_ASSERT_EQUAL(static_cast(15), dt.Minutes);
+CPPUNIT_ASSERT_EQUAL(static_cast(3), dt.Seconds);
+
+xStatement->executeUpdate("DROP TABLE myTestTable");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
index 1d93aa952383..6fb5f1e3ee61 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
@@ -235,7 +235,7 @@ uno::Reference SAL_CALL 
OResultSet::getBinaryStream(sal_Int32 colu
 
 OString sVal = m_aRows[m_nRowPosition][column - 1];
 return new SequenceInputStream{ uno::Sequence(
-reinterpret_cast(sVal.getStr()), getDataLength(column 
- 1)) };
+reinterpret_cast(sVal.getStr()), 
getDataLength(column)) };
 }
 
 uno::Reference SAL_CALL OResultSet::getCharacterStream(sal_Int32 
column)
@@ -285,7 +285,7 @@ uno::Sequence SAL_CALL 
OResultSet::getBytes(sal_Int32 column)
 return uno::Sequence();
 
 return uno::Sequence(reinterpret_cast(sVal.getStr()),
-   getDataLength(column - 1));
+   getDataLength(column));
 }
 
 Date SAL_CALL OResultSet::getDate(sal_Int32 column)
@@ -488,7 +488,7 @@ Time SAL_CALL OResultSet::getTime(sal_Int32 column)
 return t;
 
 OString sVal = m_aRows[m_nRowPosition][column - 1];
-OString timeString{ sVal.getStr(), getDataLength(column - 1) };
+OString timeString{ sVal.getStr(), getDataLength(column) };
 OString token;
 sal_Int32 nIndex, i = 0;
 
@@ -528,11 +528,14 @@ DateTime SAL_CALL OResultSet::getTimestamp(sal_Int32 
column)
 
 // YY-MM-DD HH:MM:SS
 std::vector dateAndTime
-= lcl_split(OString{ sVal

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

2019-08-02 Thread Tamas Bunth (via logerrit)
 connectivity/qa/connectivity/mysql/mysql.cxx|   84 
 connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx  |2 
 connectivity/source/drivers/mysqlc/mysqlc_general.cxx   |   26 +-
 connectivity/source/drivers/mysqlc/mysqlc_general.hxx   |4 
 connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx |2 
 connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx |9 
 connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx |   99 
+-
 connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.hxx |   31 +--
 8 files changed, 182 insertions(+), 75 deletions(-)

New commits:
commit 3d5adeab32a1b40dff203face30223ce7d298c26
Author: Tamas Bunth 
AuthorDate: Tue Jan 22 13:06:45 2019 +0100
Commit: Tamás Bunth 
CommitDate: Fri Aug 2 16:49:13 2019 +0200

mysqlc: resultset's previous() on first position..

.. should move the cursor backwards to beforeFirst position and return
false.

Change-Id: Icbb4bed0ea39ea3a0bf375d5616e3ef768fc69d9
Reviewed-on: https://gerrit.libreoffice.org/66730
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 
Reviewed-on: https://gerrit.libreoffice.org/76729
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tamás Bunth 

diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx 
b/connectivity/qa/connectivity/mysql/mysql.cxx
index 414a0de569e2..77e82c9cdfc5 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -241,6 +241,12 @@ void MysqlTestDriver::testDBPositionChange()
 xResultSet->first();
 CPPUNIT_ASSERT_EQUAL(1, xResultSet->getRow());
 
+// Now previous should put the cursor to before-first position, but it
+// should return with false.
+successPrevious = xResultSet->previous();
+CPPUNIT_ASSERT(!successPrevious);
+CPPUNIT_ASSERT_EQUAL(0, xResultSet->getRow());
+
 nUpdateCount = xStatement->executeUpdate("DROP TABLE myTestTable");
 CPPUNIT_ASSERT_EQUAL(0, nUpdateCount); // it's a DDL statement
 }
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
index be02c7c73ee3..1d93aa952383 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
@@ -659,8 +659,15 @@ sal_Bool SAL_CALL OResultSet::previous()
 MutexGuard aGuard(m_aMutex);
 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
 
-if (m_nRowPosition <= 0)
+if (m_nRowPosition == 0)
+{
+m_nRowPosition--;
 return false;
+}
+else if (m_nRowPosition < 0)
+{
+return false;
+}
 
 m_nRowPosition--;
 return true;
commit 4348e54817da8b8b4348935fff74ca9d8b7ab4e0
Author: Tamas Bunth 
AuthorDate: Sat Dec 29 15:22:56 2018 +0100
Commit: Tamás Bunth 
CommitDate: Fri Aug 2 16:49:03 2019 +0200

mysqlc: Fix result set metadata related issue

In order to allow fetching result of multiple result sets at time same
time, all the data is fetched and copied on demand from the mysql result
set. The mysql result set (MYSQL_RES) is freed afterwards.

That means we need a copy of the meta information as well. Now all the
meta data is stored in the driver for each result set, so it does not
depend on the MYSQL_RES structure anymore.

Also add test case for invoking some meta data queries before and after
fetching the result set.

Change-Id: Ie8bf993926ebe89cd362ab0b311d1f3d164b84df
Reviewed-on: https://gerrit.libreoffice.org/65855
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 
Reviewed-on: https://gerrit.libreoffice.org/76726
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tamás Bunth 

diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx 
b/connectivity/qa/connectivity/mysql/mysql.cxx
index 24436641fe6c..414a0de569e2 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -13,7 +13,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -44,11 +47,15 @@ public:
 void testCreateAndDropTable();
 void testIntegerInsertAndQuery();
 void testDBPositionChange();
+void testMultipleResultsets();
+void testDBMetaData();
 
 CPPUNIT_TEST_SUITE(MysqlTestDriver);
 CPPUNIT_TEST(testDBConnection);
 CPPUNIT_TEST(testCreateAndDropTable);
 CPPUNIT_TEST(testIntegerInsertAndQuery);
+CPPUNIT_TEST(testMultipleResultsets);
+CPPUNIT_TEST(testDBMetaData);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -238,6 +245,77 @@ void MysqlTestDriver::testDBPositionChange()
 CPPUNIT_ASSERT_EQUAL(0, nUpdateCount); // it's a DDL statement
 }
 
+void MysqlTestDriver::testMultipleResultsets()
+{
+Reference xConnection = m_xDriver->connect(m_sUrl, m_infos);
+CPPUNIT_ASSERT(xConnection.is(

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

2019-08-01 Thread Tamas Bunth (via logerrit)
 connectivity/qa/connectivity/mysql/mysql.cxx|   13 -
 connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx |   37 +++-
 connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx |4 -
 3 files changed, 40 insertions(+), 14 deletions(-)

New commits:
commit 366915de3f1f123b345eebbeb3a4646d69ae72da
Author: Tamas Bunth 
AuthorDate: Mon Dec 10 10:43:14 2018 +0100
Commit: Tamás Bunth 
CommitDate: Thu Aug 1 13:50:31 2019 +0200

mysqlc: Fix obtaining field information in rs

Result set field information should be stored correctly. It is queried
from database on demand and stored locally.

Change-Id: Ia62c62e6db32b45640b9fcd5f48c6249aecc41a2
Reviewed-on: https://gerrit.libreoffice.org/64861
Tested-by: Jenkins
Reviewed-by: Tamás Bunth 
Reviewed-on: https://gerrit.libreoffice.org/65160
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 
Reviewed-on: https://gerrit.libreoffice.org/76724
Tested-by: Jenkins CollaboraOffice 

diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx 
b/connectivity/qa/connectivity/mysql/mysql.cxx
index 16172439df0f..24436641fe6c 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -165,6 +165,7 @@ void MysqlTestDriver::testIntegerInsertAndQuery()
 Reference xResultSet = xStatement->executeQuery("SELECT id 
from myTestTable");
 CPPUNIT_ASSERT_MESSAGE("result set cannot be instantiated after query", 
xResultSet.is());
 Reference xRow(xResultSet, UNO_QUERY);
+Reference xColumnLocate(xResultSet, UNO_QUERY);
 CPPUNIT_ASSERT_MESSAGE("cannot extract row from result set!", xRow.is());
 
 for (long i = 0; i < ROW_COUNT; ++i)
@@ -172,6 +173,7 @@ void MysqlTestDriver::testIntegerInsertAndQuery()
 bool hasRow = xResultSet->next();
 CPPUNIT_ASSERT_MESSAGE("not enough result after query", hasRow);
 CPPUNIT_ASSERT_EQUAL(i, xRow->getLong(1)); // first and only column
+CPPUNIT_ASSERT_EQUAL(i, 
xRow->getLong(xColumnLocate->findColumn("id"))); // test findColumn
 }
 CPPUNIT_ASSERT_MESSAGE("Cursor is not on last position.",
xResultSet->isLast()); // cursor is on last position
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
index 5ee7aa943206..d6c2a9b724b4 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
@@ -134,6 +134,18 @@ void OResultSet::ensureResultFetched()
 }
 }
 
+void OResultSet::ensureFieldInfoFetched()
+{
+if (!m_aFields.empty())
+return;
+unsigned nFieldCount = mysql_num_fields(m_pResult);
+MYSQL_FIELD* pFields = mysql_fetch_fields(m_pResult);
+m_aFields.reserve(nFieldCount);
+for (unsigned i = 0; i < nFieldCount; ++i)
+m_aFields.push_back(OUString{
+pFields[i].name, static_cast(strlen(pFields[i].name)), 
m_encoding });
+}
+
 void OResultSet::fetchResult()
 {
 // Mysql C API does not allow simultaneously opened result sets, but sdbc 
does.
@@ -143,20 +155,18 @@ void OResultSet::fetchResult()
 // TODO ensure that
 m_nRowCount = mysql_num_rows(m_pResult);
 
+ensureFieldInfoFetched();
+
 // fetch all the data
 m_aRows.reserve(m_nRowCount);
 
-m_nFieldCount = mysql_num_fields(m_pResult);
-MYSQL_FIELD* pFields = mysql_fetch_fields(m_pResult);
-m_aFields.assign(pFields, pFields + m_nFieldCount);
-
 for (sal_Int32 row = 0; row < m_nRowCount; ++row)
 {
 MYSQL_ROW data = mysql_fetch_row(m_pResult);
 unsigned long* lengths = mysql_fetch_lengths(m_pResult);
 m_aRows.push_back(DataFields{});
 // MYSQL_ROW is char**, array of strings
-for (unsigned col = 0; col < m_nFieldCount; ++col)
+for (std::size_t col = 0; col < m_aFields.size(); ++col)
 {
 m_aRows.back().push_back(OString{ data[col], 
static_cast(lengths[col]) });
 }
@@ -202,11 +212,12 @@ sal_Int32 SAL_CALL OResultSet::findColumn(const OUString& 
columnName)
 {
 MutexGuard aGuard(m_aMutex);
 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
+ensureFieldInfoFetched();
 
-for (unsigned int i = 0; i < m_nFieldCount; ++i)
+for (std::size_t i = 0; i < m_aFields.size(); ++i)
 {
-if (columnName.equalsIgnoreAsciiCaseAscii(m_aFields[i].name))
-return i + 1; // sdbc indexes from 1
+if (columnName.equalsIgnoreAsciiCase(m_aFields[i]))
+return static_cast(i) + 1; // sdbc indexes from 1
 }
 
 throw SQLException("The column name '" + columnName + "' is not valid.", 
*this, "42S22", 0,
@@ -1092,7 +1103,7 @@ css::uno::Reference 
SAL_CALL OResultSet::getProper
 
 void OResultSet::checkColumnIndex(sal_Int32 index)
 {
-if (index < 1 || index > static_cast(m_nFieldCount))
+if (index < 1 || index > static_cast(m_aFields.si