[Libreoffice-commits] core.git: dbaccess/source
Tamas Bunth
tamas.bunth at collabora.co.uk
Sun Mar 11 15:59:09 UTC 2018
dbaccess/source/filter/hsqldb/fbcreateparser.cxx | 4 ++
dbaccess/source/filter/hsqldb/hsqlimport.cxx | 23 ++++++++++++---
dbaccess/source/filter/hsqldb/rowinputbinary.cxx | 34 +++++++++++++++++++++--
3 files changed, 53 insertions(+), 8 deletions(-)
New commits:
commit 813296d4a21163ffba86f1f4c0bec6ddb0511e6c
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date: Sun Mar 11 11:54:36 2018 +0100
dbahsql: import DATE and DATETIME columns
Change-Id: Ibfd9340fad40efab891cba5b77ce3496424a3525
Reviewed-on: https://gerrit.libreoffice.org/51076
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
diff --git a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx
index f69580423cf2..b92be4af6812 100644
--- a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx
+++ b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx
@@ -113,7 +113,9 @@ OUString FbCreateStmtParser::compose() const
lcl_appendWithSpace(sSql, lcl_DataTypetoFbTypeName(columnIter->getDataType()));
const std::vector<sal_Int32> params = columnIter->getParams();
- if (params.size() > 0)
+
+ // Firebird SQL dialect does not like paremeters for TIMESTAMP
+ if (params.size() > 0 && columnIter->getDataType() != DataType::TIMESTAMP)
{
sSql.append("(");
auto it = params.cbegin();
diff --git a/dbaccess/source/filter/hsqldb/hsqlimport.cxx b/dbaccess/source/filter/hsqldb/hsqlimport.cxx
index 7f6426231b06..95f7de3a878a 100644
--- a/dbaccess/source/filter/hsqldb/hsqlimport.cxx
+++ b/dbaccess/source/filter/hsqldb/hsqlimport.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/uno/Exception.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/WrongFormatException.hpp>
+#include <com/sun/star/util/Date.hpp>
#include <com/sun/star/sdbc/XConnection.hpp>
#include <com/sun/star/sdbc/XParameters.hpp>
@@ -154,8 +155,14 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
}
break;
case DataType::DATE:
- // TODO
- break;
+ {
+ css::util::Date date;
+ if (row.at(i) >>= date)
+ {
+ xParam->setDate(i + 1, date);
+ }
+ }
+ break;
case DataType::TIME:
{
css::util::Time time;
@@ -163,11 +170,17 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
{
xParam->setTime(i + 1, time);
}
- break;
}
+ break;
case DataType::TIMESTAMP:
- // TODO
- break;
+ {
+ css::util::DateTime dateTime;
+ if (row.at(i) >>= dateTime)
+ {
+ xParam->setTimestamp(i + 1, dateTime);
+ }
+ }
+ break;
case DataType::BOOLEAN:
{
bool bVal = false;
diff --git a/dbaccess/source/filter/hsqldb/rowinputbinary.cxx b/dbaccess/source/filter/hsqldb/rowinputbinary.cxx
index 0bcd0109e304..7b6fd4eff94c 100644
--- a/dbaccess/source/filter/hsqldb/rowinputbinary.cxx
+++ b/dbaccess/source/filter/hsqldb/rowinputbinary.cxx
@@ -22,10 +22,13 @@
#include <com/sun/star/io/WrongFormatException.hpp>
#include <com/sun/star/io/XConnectable.hpp>
#include <com/sun/star/util/Time.hpp>
+#include <com/sun/star/util/Date.hpp>
+#include <com/sun/star/util/DateTime.hpp>
#include <unotools/ucbstreamhelper.hxx>
#include <tools/stream.hxx>
#include <rtl/ustrbuf.hxx>
+#include <ctime>
namespace
{
@@ -299,7 +302,16 @@ std::vector<Any> HsqlRowInputStream::readOneRow(const ColumnTypeVector& nColType
}
break;
case DataType::DATE:
- break;
+ {
+ sal_Int64 value = 0;
+ m_pStream->ReadInt64(value); // in millisec, from 1970
+ sal_Int64 nEpochSec = value / 1000;
+ std::tm* tm = std::gmtime(&nEpochSec);
+ css::util::Date date(tm->tm_mday, tm->tm_mon + 1,
+ tm->tm_year + 1900); // day, month, year
+ aData.push_back(makeAny(date));
+ }
+ break;
case DataType::TIME:
{
sal_Int64 value = 0;
@@ -309,7 +321,25 @@ std::vector<Any> HsqlRowInputStream::readOneRow(const ColumnTypeVector& nColType
}
break;
case DataType::TIMESTAMP:
- break;
+ {
+ sal_Int64 nEpochMillis = 0;
+ m_pStream->ReadInt64(nEpochMillis);
+ sal_Int64 nEpochSec = nEpochMillis / 1000;
+ std::tm* tm = std::gmtime(&nEpochSec);
+
+ sal_Int32 nNanos = 0;
+ m_pStream->ReadInt32(nNanos);
+ css::util::DateTime dateTime;
+ dateTime.NanoSeconds = nNanos;
+ dateTime.Seconds = tm->tm_sec;
+ dateTime.Minutes = tm->tm_min;
+ dateTime.Hours = tm->tm_hour;
+ dateTime.Day = tm->tm_mday;
+ dateTime.Month = tm->tm_mon + 1; // indexed from 0
+ dateTime.Year = 1900 + tm->tm_year;
+ aData.push_back(makeAny(dateTime));
+ }
+ break;
case DataType::BOOLEAN:
{
sal_uInt8 nBool = 0;
More information about the Libreoffice-commits
mailing list