summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerrence Enger <tenger@iseries-guru.com>2018-09-05 13:25:54 -0400
committerTamás Bunth <btomi96@gmail.com>2018-10-22 16:18:39 +0200
commit4d7dd4e1e4e072db8bcfe4d52b8c185187353e74 (patch)
tree6e1d25557f5426cae75798d77496aac6dca2d8f2
parent2606f2bc1ac921f2e9c33da36b6b8bbb75ac0386 (diff)
tdf#119625: coerce migrated Time between 0 and 24 hours
Coincidentally, remove unwarranted addition of one hour Added unit test dbaccess_tdf119625 Change-Id: I84a47c7abd4ab8e2c80d3faaf8cf4f11e1b81df3 Reviewed-on: https://gerrit.libreoffice.org/60048 Tested-by: Jenkins Reviewed-by: Tamás Bunth <btomi96@gmail.com> Tested-by: Tamás Bunth <btomi96@gmail.com>
-rw-r--r--dbaccess/CppunitTest_dbaccess_tdf119625.mk107
-rw-r--r--dbaccess/Module_dbaccess.mk1
-rw-r--r--dbaccess/qa/unit/data/tdf119625.odbbin0 -> 6350 bytes
-rw-r--r--dbaccess/qa/unit/tdf119625.cxx111
-rw-r--r--dbaccess/source/filter/hsqldb/rowinputbinary.cxx14
5 files changed, 225 insertions, 8 deletions
diff --git a/dbaccess/CppunitTest_dbaccess_tdf119625.mk b/dbaccess/CppunitTest_dbaccess_tdf119625.mk
new file mode 100644
index 000000000000..448d671d4911
--- /dev/null
+++ b/dbaccess/CppunitTest_dbaccess_tdf119625.mk
@@ -0,0 +1,107 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,dbaccess_tdf119625))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_tdf119625, \
+ dbaccess/qa/unit/tdf119625 \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,dbaccess_tdf119625, \
+ basegfx \
+ comphelper \
+ cppu \
+ cppuhelper \
+ dba \
+ dbahsql \
+ dbu \
+ sdbt \
+ drawinglayer \
+ editeng \
+ for \
+ forui \
+ i18nlangtag \
+ msfilter \
+ oox \
+ sal \
+ salhelper \
+ sax \
+ sb \
+ sfx \
+ sot \
+ svl \
+ svt \
+ svx \
+ svxcore \
+ test \
+ subsequenttest \
+ tl \
+ tk \
+ ucbhelper \
+ unotest \
+ utl \
+ vbahelper \
+ vcl \
+ xo \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,dbaccess_tdf119625))
+$(eval $(call gb_CppunitTest_use_vcl,dbaccess_tdf119625))
+
+$(eval $(call gb_CppunitTest_set_include,dbaccess_tdf119625,\
+ -I$(SRCDIR)/dbaccess/source/filter/hsqldb \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,dbaccess_tdf119625,\
+ offapi \
+ oovbaapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_components,dbaccess_tdf119625,\
+ basic/util/sb \
+ comphelper/util/comphelp \
+ configmgr/source/configmgr \
+ connectivity/source/drivers/hsqldb/hsqldb \
+ connectivity/source/drivers/firebird/firebird_sdbc \
+ connectivity/source/manager/sdbc2 \
+ dbaccess/util/dba \
+ dbaccess/util/dbu \
+ dbaccess/util/sdbt \
+ dbaccess/source/filter/xml/dbaxml \
+ filter/source/config/cache/filterconfig1 \
+ forms/util/frm \
+ framework/util/fwk \
+ i18npool/util/i18npool \
+ linguistic/source/lng \
+ oox/util/oox \
+ package/source/xstor/xstor \
+ package/util/package2 \
+ sax/source/expatwrap/expwrap \
+ scripting/source/basprov/basprov \
+ scripting/util/scriptframe \
+ sfx2/util/sfx \
+ sot/util/sot \
+ svl/source/fsstor/fsstorage \
+ svl/util/svl \
+ toolkit/util/tk \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+ ucb/source/ucp/tdoc/ucptdoc1 \
+ unotools/util/utl \
+ unoxml/source/rdf/unordf \
+ unoxml/source/service/unoxml \
+ uui/util/uui \
+ xmloff/util/xo \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,dbaccess_tdf119625))
+
+# vim: set noet sw=4 ts=4:
diff --git a/dbaccess/Module_dbaccess.mk b/dbaccess/Module_dbaccess.mk
index 9c834b0d7e7c..74796bcac4e6 100644
--- a/dbaccess/Module_dbaccess.mk
+++ b/dbaccess/Module_dbaccess.mk
@@ -46,6 +46,7 @@ $(eval $(call gb_Module_add_check_targets,dbaccess,\
endif
$(eval $(call gb_Module_add_check_targets,dbaccess,\
CppunitTest_dbaccess_firebird_test \
+ CppunitTest_dbaccess_tdf119625 \
))
endif
diff --git a/dbaccess/qa/unit/data/tdf119625.odb b/dbaccess/qa/unit/data/tdf119625.odb
new file mode 100644
index 000000000000..e7bd69d60b4b
--- /dev/null
+++ b/dbaccess/qa/unit/data/tdf119625.odb
Binary files differ
diff --git a/dbaccess/qa/unit/tdf119625.cxx b/dbaccess/qa/unit/tdf119625.cxx
new file mode 100644
index 000000000000..9ec05bf6a518
--- /dev/null
+++ b/dbaccess/qa/unit/tdf119625.cxx
@@ -0,0 +1,111 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "dbtest_base.cxx"
+
+#include <hsqlimport.hxx>
+
+#include <osl/process.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <com/sun/star/sdbc/DataType.hpp>
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <test/unoapi_test.hxx>
+#include <svtools/miscopt.hxx>
+#include <com/sun/star/util/Time.hpp>
+
+using namespace dbahsql;
+
+class Tdf119625Test : public DBTestBase
+{
+public:
+ void testTime();
+
+ virtual void setUp() override;
+
+ CPPUNIT_TEST_SUITE(Tdf119625Test);
+
+ CPPUNIT_TEST(testTime);
+
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void Tdf119625Test::setUp()
+{
+ DBTestBase::setUp();
+ SvtMiscOptions aMiscOptions;
+ osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData);
+}
+
+struct expect_t
+{
+ sal_Int16 id;
+ sal_Int16 h, m, s;
+};
+
+/* The values here assume that our results are in UTC. However,
+ tdf#119675 "Firebird: Migration: User dialog to set treatment of
+ datetime and time values during migration" is going to change the
+ finaly result of migration. If that change is implemented below
+ the level we are testing, this test will have to allow for or set
+ the destination timezone.
+ */
+static const expect_t expect[]
+ = { { 0, 15, 10, 10 }, { 1, 23, 30, 30 }, { 2, 5, 0, 0 }, { 3, 4, 30, 0 },
+ { 4, 3, 15, 10 }, { 5, 5, 0, 0 }, { 6, 3, 22, 22 } };
+
+void Tdf119625Test::testTime()
+{
+ uno::Reference<XOfficeDatabaseDocument> xDocument = getDocumentForFileName("tdf119625.odb");
+
+ uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
+ // at this point migration is already done
+ /* In the presence of tdf#119625, terminal already has messages
+
+ *value exceeds the range for a valid time
+ caused by
+ 'isc_dsql_execute'
+
+ warn:dbaccess:22435:22435:dbaccess/source/filter/hsqldb/hsqlimport.cxx:373: Error during migratio
+
+ In this case, we do not expect anything good from the following
+ code, but I (tje, 2018-09-04) do not know how to detect this
+ situation. In particular, the migration has been observed to
+ create the destination table (but truncated after the first
+ row), and xConnection.is() returns true.
+ */
+
+ // select basically everything from the .odb
+ uno::Reference<XStatement> statement = xConnection->createStatement();
+ OUString sql{ " SELECT id, tst_dt, tst_d, tst_t "
+ " FROM tst_data "
+ "ORDER BY id" };
+
+ uno::Reference<XResultSet> xRes = statement->executeQuery(sql);
+ uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW);
+
+ // check result
+ for (auto& e : expect)
+ {
+ CPPUNIT_ASSERT(xRes->next());
+ CPPUNIT_ASSERT_EQUAL(xRow->getShort(1), e.id);
+ auto time_got = xRow->getTime(4);
+ auto time_expected = com::sun::star::util::Time(0, e.s, e.m, e.h, false);
+ auto equal_times = time_got == time_expected;
+ CPPUNIT_ASSERT(equal_times);
+ }
+ CPPUNIT_ASSERT(!xRes->next());
+
+ closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Tdf119625Test);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/dbaccess/source/filter/hsqldb/rowinputbinary.cxx b/dbaccess/source/filter/hsqldb/rowinputbinary.cxx
index 600e7729c03e..58579cd39c25 100644
--- a/dbaccess/source/filter/hsqldb/rowinputbinary.cxx
+++ b/dbaccess/source/filter/hsqldb/rowinputbinary.cxx
@@ -333,15 +333,13 @@ std::vector<Any> HsqlRowInputStream::readOneRow(const ColumnTypeVector& nColType
sal_Int64 value = 0;
m_pStream->ReadInt64(value);
auto valueInSecs = value / 1000;
- sal_uInt16 nHours = 0;
- // in negative case value is comprised between
- // -24 * 60 * 60 and -1
- // so add 24 * 60 * 60 in order the rest of calculus is ok
- if (valueInSecs < 0)
- valueInSecs += 24 * 60 * 60;
- else
- nHours = (valueInSecs / 3600) + 1;
+ /* Observed valueInSecs fall in the range from
+ negative one day to positive two days. Coerce
+ valueInSecs between zero and positive one day.*/
+ const int secPerDay = 24 * 60 * 60;
+ valueInSecs = (valueInSecs + secPerDay) % secPerDay;
+ auto nHours = valueInSecs / (60 * 60);
valueInSecs = valueInSecs % 3600;
const sal_uInt16 nMins = valueInSecs / 60;
const sal_uInt16 nSecs = valueInSecs % 60;