[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
Fri Aug 2 14:50:15 UTC 2019
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 <tamas.bunth at collabora.co.uk>
AuthorDate: Tue Jan 29 13:00:21 2019 +0100
Commit: Tamás Bunth <btomi96 at gmail.com>
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 <btomi96 at gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/67091
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/76730
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
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 <com/sun/star/sdbc/XParameters.hpp>
#include <com/sun/star/sdbc/XStatement.hpp>
#include <com/sun/star/sdbc/XDriver.hpp>
+
+#include <com/sun/star/util/DateTime.hpp>
#include <svtools/miscopt.hxx>
#include <osl/process.h>
@@ -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> 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");
+
+ 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> xResultSet
+ = xStatement->executeQuery("SELECT mytimestamp from myTestTable");
+
+ xResultSet->next(); // use it
+ Reference<XRow> 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<short>(2008), dt.Year);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), dt.Month);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(16), dt.Day);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(20), dt.Hours);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(15), dt.Minutes);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(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<XInputStream> SAL_CALL OResultSet::getBinaryStream(sal_Int32 colu
OString sVal = m_aRows[m_nRowPosition][column - 1];
return new SequenceInputStream{ uno::Sequence<sal_Int8>(
- reinterpret_cast<sal_Int8 const*>(sVal.getStr()), getDataLength(column - 1)) };
+ reinterpret_cast<sal_Int8 const*>(sVal.getStr()), getDataLength(column)) };
}
uno::Reference<XInputStream> SAL_CALL OResultSet::getCharacterStream(sal_Int32 column)
@@ -285,7 +285,7 @@ uno::Sequence<sal_Int8> SAL_CALL OResultSet::getBytes(sal_Int32 column)
return uno::Sequence<sal_Int8>();
return uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const*>(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<OString> dateAndTime
- = lcl_split(OString{ sVal.getStr(), getDataLength(column - 1) }, ' ');
+ = lcl_split(OString{ sVal.getStr(), getDataLength(column) }, ' ');
auto dateParts = lcl_split(dateAndTime.at(0), '-');
auto timeParts = lcl_split(dateAndTime.at(1), ':');
+ if (dateParts.size() < 2 || timeParts.size() < 2)
+ throw SQLException("Timestamp has a wrong format", *this, OUString(), 1, Any());
+
DateTime dt;
dt.Year = dateParts.at(0).toUInt32();
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx b/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx
index d3afafbdb6cc..34be3a2ca36c 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx
@@ -75,7 +75,7 @@ class OResultSet final : public OBase_Mutex,
sal_Int32 getDataLength(sal_Int32 column)
{
- return m_aRows[m_nRowCount][column - 1].getLength();
+ return m_aRows[m_nRowPosition][column - 1].getLength();
}
bool checkNull(sal_Int32 column);
commit 9331e3a3ce2c66a3395b6d0d3727d299bd73c4fd
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
AuthorDate: Sun Jan 6 17:10:26 2019 +0100
Commit: Tamás Bunth <btomi96 at gmail.com>
CommitDate: Fri Aug 2 16:49:26 2019 +0200
mysqlc: replace initializer list with assignment
Because visual c++ compiler may not support it without creating a
constructor for the struct.
Change-Id: I6c8868c4e34cbe7b67e413b1db18aed01378c959
Reviewed-on: https://gerrit.libreoffice.org/65905
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/76727
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx
index ba8c36da83ce..7b3601f57774 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx
@@ -37,23 +37,29 @@ OResultSetMetaData::OResultSetMetaData(OConnection& rConn, MYSQL_RES* pResult)
unsigned nFieldCount = mysql_num_fields(pResult);
for (unsigned i = 0; i < nFieldCount; ++i)
{
- MySqlFieldInfo fieldInfo{
- OUString{ fields[i].name, static_cast<sal_Int32>(fields[i].name_length),
- m_rConnection.getConnectionEncoding() }, // column name
- static_cast<sal_Int32>(fields[i].length), // length
- mysqlc_sdbc_driver::mysqlToOOOType(fields[i].type, fields[i].charsetnr), // type
- fields[i].type, // mysql_type
- fields[i].charsetnr, // charset number
- fields[i].flags,
- OUString{ fields[i].db, static_cast<sal_Int32>(fields[i].db_length),
- m_rConnection.getConnectionEncoding() }, // schema name
- OUString{ fields[i].table, static_cast<sal_Int32>(fields[i].table_length),
- m_rConnection.getConnectionEncoding() }, // table name
- OUString{ fields[i].catalog, static_cast<sal_Int32>(fields[i].catalog_length),
- m_rConnection.getConnectionEncoding() }, // catalog
- static_cast<sal_Int32>(fields[i].decimals),
- static_cast<sal_Int32>(fields[i].max_length)
- };
+ MySqlFieldInfo fieldInfo;
+ {
+ fieldInfo.columnName
+ = OUString{ fields[i].name, static_cast<sal_Int32>(fields[i].name_length),
+ m_rConnection.getConnectionEncoding() };
+ fieldInfo.length = static_cast<sal_Int32>(fields[i].length);
+ fieldInfo.type
+ = mysqlc_sdbc_driver::mysqlToOOOType(fields[i].type, fields[i].charsetnr);
+ fieldInfo.mysql_type = fields[i].type;
+ fieldInfo.charsetNumber = fields[i].charsetnr;
+ fieldInfo.flags = fields[i].flags;
+ fieldInfo.schemaName
+ = OUString{ fields[i].db, static_cast<sal_Int32>(fields[i].db_length),
+ m_rConnection.getConnectionEncoding() };
+ fieldInfo.tableName
+ = OUString{ fields[i].table, static_cast<sal_Int32>(fields[i].table_length),
+ m_rConnection.getConnectionEncoding() };
+ fieldInfo.catalogName
+ = OUString{ fields[i].catalog, static_cast<sal_Int32>(fields[i].catalog_length),
+ m_rConnection.getConnectionEncoding() };
+ fieldInfo.decimals = static_cast<sal_Int32>(fields[i].decimals);
+ fieldInfo.max_length = static_cast<sal_Int32>(fields[i].max_length);
+ }
m_fields.push_back(std::move(fieldInfo));
}
}
More information about the Libreoffice-commits
mailing list