Kaydet (Commit) 930074a9 authored tarafından Tamas Bunth's avatar Tamas Bunth Kaydeden (comit) Andras Timar

mysqlc: Allow conversions between different types

Change-Id: I54c1f438a755267db0896637c79f915de9113f83
Reviewed-on: https://gerrit.libreoffice.org/71246Reviewed-by: 's avatarAndras Timar <andras.timar@collabora.com>
Tested-by: 's avatarAndras Timar <andras.timar@collabora.com>
üst 07aecc1d
......@@ -35,6 +35,7 @@ $(eval $(call gb_Library_use_sdk_api,mysqlc))
$(eval $(call gb_Library_use_libraries,mysqlc,\
cppu \
dbtools \
sal \
salhelper \
comphelper \
......
......@@ -52,6 +52,7 @@ public:
void testMultipleResultsets();
void testDBMetaData();
void testTimestampField();
void testNumericConversionPrepared();
CPPUNIT_TEST_SUITE(MysqlTestDriver);
CPPUNIT_TEST(testDBConnection);
......@@ -60,6 +61,7 @@ public:
CPPUNIT_TEST(testMultipleResultsets);
CPPUNIT_TEST(testDBMetaData);
CPPUNIT_TEST(testTimestampField);
CPPUNIT_TEST(testNumericConversionPrepared);
CPPUNIT_TEST_SUITE_END();
};
......@@ -358,6 +360,36 @@ void MysqlTestDriver::testTimestampField()
xStatement->executeUpdate("DROP TABLE myTestTable");
}
/**
* Test getting value from a decimal type column from a result set of a
* prepared statement, getting as a tinyint, string, short, int, long.
*/
void MysqlTestDriver::testNumericConversionPrepared()
{
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 (myDecimal DECIMAL(4,2))");
xStatement->executeUpdate("INSERT INTO myTestTable VALUES (11.22)");
Reference<XPreparedStatement> xPrepared
= xConnection->prepareStatement("SELECT * from myTestTable");
Reference<XResultSet> xResultSet = xPrepared->executeQuery();
xResultSet->next(); // use it
Reference<XRow> xRow(xResultSet, UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("11.22"), xRow->getString(1));
// converting to integer types results in rounding down the number
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int8>(11), xRow->getByte(1));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(11), xRow->getShort(1));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(11), xRow->getInt(1));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(11), xRow->getLong(1));
xStatement->executeUpdate("DROP TABLE myTestTable");
}
CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver);
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -36,6 +36,7 @@
#include <com/sun/star/sdbcx/XDeleteRows.hpp>
#include <com/sun/star/sdbcx/XRowLocate.hpp>
#include <com/sun/star/util/XCancellable.hpp>
#include <connectivity/FValue.hxx>
#include <cppuhelper/compbase12.hxx>
......@@ -92,6 +93,10 @@ class OPreparedResultSet final : public OBase_Mutex,
void SAL_CALL getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const SAL_OVERRIDE;
template <typename T> T safelyRetrieveValue(const sal_Int32 nColumnIndex);
template <typename T> T retrieveValue(const sal_Int32 nColumnIndex);
connectivity::ORowSetValue getRowSetValue(sal_Int32 nColumnIndex);
// you can't delete objects of this type
virtual ~OPreparedResultSet() override = default;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment