From 9830fd36dbdb72c79703b0c61efc027fba793c5a Mon Sep 17 00:00:00 2001 From: Lionel Elie Mamane Date: Sun, 17 Mar 2013 08:36:26 +0100 Subject: date/time IDL datatypes incompatible change - nanosecond precision - signed (allowed negative) year Also: assorted improvements / bugfixes in date/time handling code. Some factorisation of copy/pasted code. Change-Id: I761a1b0b8731c82f19a0c37acbcf43d3c06d6cd6 --- connectivity/inc/connectivity/dbconversion.hxx | 10 +- connectivity/source/commontools/FValue.cxx | 8 +- connectivity/source/commontools/dbconversion.cxx | 154 ++++++++++++--------- connectivity/source/drivers/calc/CTable.cxx | 20 +-- connectivity/source/drivers/dbase/DTable.cxx | 2 +- .../source/drivers/file/FDateFunctions.cxx | 4 +- connectivity/source/drivers/jdbc/ConnectionLog.cxx | 8 +- connectivity/source/drivers/kab/KResultSet.cxx | 2 +- .../source/drivers/macab/macabutilities.hxx | 2 +- .../odbcbase/ODatabaseMetaDataResultSet.cxx | 2 +- .../source/drivers/odbcbase/OPreparedStatement.cxx | 45 ++++-- .../source/drivers/odbcbase/OResultSet.cxx | 2 +- .../source/drivers/postgresql/pq_tools.cxx | 21 ++- connectivity/source/inc/odbc/OTools.hxx | 3 +- 14 files changed, 172 insertions(+), 111 deletions(-) (limited to 'connectivity') diff --git a/connectivity/inc/connectivity/dbconversion.hxx b/connectivity/inc/connectivity/dbconversion.hxx index e8516d1fcd35..9536c799ec81 100644 --- a/connectivity/inc/connectivity/dbconversion.hxx +++ b/connectivity/inc/connectivity/dbconversion.hxx @@ -111,7 +111,9 @@ namespace dbtools static ::com::sun::star::util::DateTime toDateTime(const OUString& _sSQLDate); + // TODO: consider removing getMsFromTime static sal_Int32 getMsFromTime(const ::com::sun::star::util::Time& rVal); + static sal_Int64 getNsFromTime(const ::com::sun::star::util::Time& rVal); static sal_Int32 toDays(const ::com::sun::star::util::Date& _rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate()); @@ -120,10 +122,10 @@ namespace dbtools static double toDouble(const ::com::sun::star::util::DateTime& rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate()); static sal_Int32 toINT32(const ::com::sun::star::util::Date& rVal); - static sal_Int32 toINT32(const ::com::sun::star::util::Time& rVal); + static sal_Int64 toINT64(const ::com::sun::star::util::Time& rVal); static ::com::sun::star::util::Date toDate(sal_Int32 _nVal); - static ::com::sun::star::util::Time toTime(sal_Int32 _nVal); + static ::com::sun::star::util::Time toTime(sal_Int64 _nVal); /** convert a double which is a date value relative to a given fixed date into a date value relative to the standard db null date. @@ -139,9 +141,9 @@ namespace dbtools // return the date in the format %04d-%02d-%02d static OUString toDateString(const ::com::sun::star::util::Date& rDate); - // return the time in the format %02d:%02d:%02d + // return the time in the format %02d:%02d:%02d.%09d static OUString toTimeString(const ::com::sun::star::util::Time& rTime); - // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d + // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d.%09d static OUString toDateTimeString(const ::com::sun::star::util::DateTime& _rDateTime); // return the any in an sql standard format static OUString toSQLString(sal_Int32 eType, const ::com::sun::star::uno::Any& _rVal, sal_Bool bQuote, diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index ef968fb9261e..770b34ea43c9 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -746,14 +746,14 @@ bool operator==(const Date& _rLH,const Date& _rRH) bool operator==(const Time& _rLH,const Time& _rRH) { - return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds; + return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds; } // ------------------------------------------------------------------------- bool operator==(const DateTime& _rLH,const DateTime& _rRH) { return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year && - _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds; + _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds; } // ------------------------------------------------------------------------- @@ -2020,7 +2020,7 @@ Sequence ORowSetValue::getSequence() const case DataType::TIMESTAMP: { ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue); - aValue.HundredthSeconds = pDateTime->HundredthSeconds; + aValue.NanoSeconds = pDateTime->NanoSeconds; aValue.Seconds = pDateTime->Seconds; aValue.Minutes = pDateTime->Minutes; aValue.Hours = pDateTime->Hours; @@ -2073,7 +2073,7 @@ Sequence ORowSetValue::getSequence() const case DataType::TIME: { ::com::sun::star::util::Time* pTime = static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue); - aValue.HundredthSeconds = pTime->HundredthSeconds; + aValue.NanoSeconds = pTime->NanoSeconds; aValue.Seconds = pTime->Seconds; aValue.Minutes = pTime->Minutes; aValue.Hours = pTime->Hours; diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx index 0af54185befd..cb8715102864 100644 --- a/connectivity/source/commontools/dbconversion.cxx +++ b/connectivity/source/commontools/dbconversion.cxx @@ -31,6 +31,20 @@ #define MAX_DAYS 3636532 +namespace +{ + const double fMilliSecondsPerDay = 86400000.0; + const sal_Int64 nanoSecInSec = 1000000000; + const sal_Int16 secInMin = 60; + const sal_Int16 minInHour = 60; + + const sal_Int64 secMask = 1000000000; + const sal_Int64 minMask = 100000000000; + const sal_Int64 hourMask = 10000000000000; + + const double fNanoSecondsPerDay = nanoSecInSec * secInMin * minInHour * 24.0; +} + //......................................................................... namespace dbtools { @@ -68,14 +82,15 @@ namespace dbtools //------------------------------------------------------------------ OUString DBTypeConversion::toTimeString(const Time& rTime) { - sal_Char s[9]; + const size_t buflen = 19; + sal_Char s[buflen]; snprintf(s, - sizeof(s), - "%02d:%02d:%02d", - (int)rTime.Hours, - (int)rTime.Minutes, - (int)rTime.Seconds); - s[8] = 0; + buflen, + "%02d:%02d:%02d.%09d", + rTime.Hours, + rTime.Minutes, + rTime.Seconds, + rTime.NanoSeconds); return OUString::createFromAscii(s); } @@ -85,10 +100,8 @@ namespace dbtools Date aDate(_rDateTime.Day,_rDateTime.Month,_rDateTime.Year); OUStringBuffer aTemp(toDateString(aDate)); aTemp.appendAscii(" "); - Time aTime(0,_rDateTime.Seconds,_rDateTime.Minutes,_rDateTime.Hours); + Time aTime(_rDateTime.NanoSeconds,_rDateTime.Seconds,_rDateTime.Minutes,_rDateTime.Hours); aTemp.append( toTimeString(aTime) ); - aTemp.appendAscii("."); - aTemp.append( static_cast(_rDateTime.HundredthSeconds)); return aTemp.makeStringAndClear(); } //------------------------------------------------------------------------------ @@ -102,17 +115,17 @@ namespace dbtools } //------------------------------------------------------------------------------ - Time DBTypeConversion::toTime(sal_Int32 _nVal) + Time DBTypeConversion::toTime(sal_Int64 _nVal) { Time aReturn; - aReturn.Hours = (sal_uInt16)(((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) / 1000000); - aReturn.Minutes = (sal_uInt16)((((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) / 10000) % 100); - aReturn.Seconds = (sal_uInt16)((((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) / 100) % 100); - aReturn.HundredthSeconds = (sal_uInt16)(((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) % 100); + sal_uInt64 unVal = static_cast(_nVal >= 0 ? _nVal : -_nVal); + aReturn.Hours = unVal / hourMask; + aReturn.Minutes = (unVal / minMask) % 100; + aReturn.Seconds = (unVal / secMask) % 100; + aReturn.NanoSeconds = unVal % secMask; return aReturn; } - const double fMilliSecondsPerDay = 86400000.0; //------------------------------------------------------------------------------ sal_Int32 DBTypeConversion::toINT32(const Date& rVal) { @@ -122,18 +135,21 @@ namespace dbtools } //------------------------------------------------------------------------------ - sal_Int32 DBTypeConversion::toINT32(const Time& rVal) + sal_Int64 DBTypeConversion::toINT64(const Time& rVal) { // normalize time - sal_Int32 nSeconds = rVal.Seconds + rVal.HundredthSeconds / 100; - sal_Int32 nHundredthSeconds = rVal.HundredthSeconds % 100; - sal_Int32 nMinutes = rVal.Minutes + nSeconds / 60; - nSeconds = nSeconds % 60; - sal_Int32 nHours = rVal.Hours + nMinutes / 60; - nMinutes = nMinutes % 60; + sal_Int32 nSeconds = rVal.Seconds + rVal.NanoSeconds / nanoSecInSec; + sal_Int32 nNanoSeconds = rVal.NanoSeconds % nanoSecInSec; + sal_Int32 nMinutes = rVal.Minutes + nSeconds / secInMin; + nSeconds = nSeconds % secInMin; + sal_Int32 nHours = rVal.Hours + nMinutes / minInHour; + nMinutes = nMinutes % minInHour; // assemble time - return (sal_Int32)(nHundredthSeconds + (nSeconds*100) + (nMinutes*10000) + (nHours*1000000)); + return nNanoSeconds + + nSeconds * secMask + + nMinutes * minMask + + nHours * hourMask; } //------------------------------------------------------------------------------ @@ -142,9 +158,23 @@ namespace dbtools sal_Int32 nHour = rVal.Hours; sal_Int32 nMin = rVal.Minutes; sal_Int32 nSec = rVal.Seconds; - sal_Int32 n100Sec = rVal.HundredthSeconds; + sal_Int32 nNanoSec = rVal.NanoSeconds; - return ((nHour*3600000)+(nMin*60000)+(nSec*1000)+(n100Sec*10)); + return ((nHour*3600000)+(nMin*60000)+(nSec*1000)+(nNanoSec/1000000)); + } + + //------------------------------------------------------------------------------ + sal_Int64 DBTypeConversion::getNsFromTime(const Time& rVal) + { + sal_Int32 nHour = rVal.Hours; + sal_Int32 nMin = rVal.Minutes; + sal_Int32 nSec = rVal.Seconds; + sal_Int32 nNanoSec = rVal.NanoSeconds; + + return nNanoSec + + nSec * nanoSecInSec + + nMin * (secInMin * nanoSecInSec) + + nHour * (minInHour * secInMin * nanoSecInSec); } //------------------------------------------------------------------------------ @@ -195,7 +225,7 @@ namespace dbtools return nDays; } //------------------------------------------------------------------------------ - static void implBuildFromRelative( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear) + static void implBuildFromRelative( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_Int16& rYear) { sal_Int32 nTempDays; sal_Int32 i = 0; @@ -250,7 +280,7 @@ namespace dbtools //------------------------------------------------------------------------------ double DBTypeConversion::toDouble(const Time& rVal) { - return (double)getMsFromTime(rVal) / fMilliSecondsPerDay; + return (double)getNsFromTime(rVal) / fNanoSecondsPerDay; } //------------------------------------------------------------------------------ @@ -262,7 +292,7 @@ namespace dbtools aTimePart.Hours = _rVal.Hours; aTimePart.Minutes = _rVal.Minutes; aTimePart.Seconds = _rVal.Seconds; - aTimePart.HundredthSeconds = _rVal.HundredthSeconds; + aTimePart.NanoSeconds = _rVal.NanoSeconds; return ((double)nTime) + toDouble(aTimePart); } @@ -325,12 +355,12 @@ namespace dbtools Time DBTypeConversion::toTime(double dVal) { sal_Int32 nDays = (sal_Int32)dVal; - sal_Int32 nMS = sal_Int32((dVal - (double)nDays) * fMilliSecondsPerDay + 0.5); + sal_Int32 nNS = sal_Int32((dVal - (double)nDays) * fNanoSecondsPerDay + 0.5); sal_Int16 nSign; - if ( nMS < 0 ) + if ( nNS < 0 ) { - nMS *= -1; + nNS *= -1; nSign = -1; } else @@ -339,24 +369,28 @@ namespace dbtools Time xRet; // normalize time // we have to sal_Int32 here because otherwise we get an overflow - sal_Int32 nHundredthSeconds = nMS/10; - sal_Int32 nSeconds = nHundredthSeconds / 100; - sal_Int32 nMinutes = nSeconds / 60; + sal_Int32 nNanoSeconds = nNS; + sal_Int32 nSeconds = nNanoSeconds / nanoSecInSec; + sal_Int32 nMinutes = nSeconds / secInMin; - xRet.HundredthSeconds = (sal_uInt16)(nHundredthSeconds % 100); - xRet.Seconds = (sal_uInt16)(nSeconds % 60); - xRet.Hours = (sal_uInt16)(nMinutes / 60); - xRet.Minutes = (sal_uInt16)(nMinutes % 60); + xRet.NanoSeconds = nNanoSeconds % nanoSecInSec; + xRet.Seconds = nSeconds % secInMin; + xRet.Hours = nMinutes / minInHour; + xRet.Minutes = nMinutes % minInHour; // assemble time - sal_Int32 nTime = (sal_Int32)(xRet.HundredthSeconds + (xRet.Seconds*100) + (xRet.Minutes*10000) + (xRet.Hours*1000000)) * nSign; + sal_Int64 nTime = nSign * + (xRet.NanoSeconds + + xRet.Seconds * secMask + + xRet.Minutes * minMask + + xRet.Hours * hourMask); if(nTime < 0) { - xRet.HundredthSeconds = 99; - xRet.Minutes = 59; - xRet.Seconds = 59; - xRet.Hours = 23; + xRet.NanoSeconds = nanoSecInSec-1; + xRet.Seconds = secInMin-1; + xRet.Minutes = minInHour-1; + xRet.Hours = 23; } return xRet; } @@ -368,14 +402,14 @@ namespace dbtools DateTime xRet; - xRet.Day = aDate.Day; - xRet.Month = aDate.Month; - xRet.Year = aDate.Year; + xRet.Day = aDate.Day; + xRet.Month = aDate.Month; + xRet.Year = aDate.Year; - xRet.HundredthSeconds = aTime.HundredthSeconds; - xRet.Minutes = aTime.Minutes; - xRet.Seconds = aTime.Seconds; - xRet.Hours = aTime.Hours; + xRet.NanoSeconds = aTime.NanoSeconds; + xRet.Minutes = aTime.Minutes; + xRet.Seconds = aTime.Seconds; + xRet.Hours = aTime.Hours; return xRet; @@ -415,7 +449,8 @@ namespace dbtools if ( -1 != nSeparation ) aTime = toTime( _sSQLString.copy( nSeparation ) ); - return DateTime(aTime.HundredthSeconds,aTime.Seconds,aTime.Minutes,aTime.Hours,aDate.Day,aDate.Month,aDate.Year); + return DateTime(aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours, + aDate.Day, aDate.Month, aDate.Year); } //----------------------------------------------------------------------------- @@ -426,8 +461,8 @@ namespace dbtools sal_Int32 nIndex = 0; sal_uInt16 nHour = 0, nMinute = 0, - nSecond = 0, - nHundredthSeconds = 0; + nSecond = 0; + sal_uInt32 nNanoSeconds = 0; nHour = (sal_uInt16)_sSQLString.getToken(0,sTimeSep,nIndex).toInt32(); if(nIndex != -1) { @@ -437,17 +472,10 @@ namespace dbtools nSecond = (sal_uInt16)_sSQLString.getToken(0,sTimeSep,nIndex).toInt32(); nIndex = 0; OUString sNano(_sSQLString.getToken(1,'.',nIndex)); - if ( !sNano.isEmpty() ) - { - // our time struct only supports hundredth seconds - sNano = sNano.copy(0,::std::min(sNano.getLength(),2)); - const static OUString s_Zeros("00"); - sNano += s_Zeros.copy(0,s_Zeros.getLength() - sNano.getLength()); - nHundredthSeconds = static_cast(sNano.toInt32()); - } + nNanoSeconds = sNano.toInt32(); } } - return Time(nHundredthSeconds,nSecond,nMinute,nHour); + return Time(nNanoSeconds, nSecond, nMinute, nHour); } //......................................................................... diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index 1e37cc38ecc3..b509065cf68c 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -370,12 +370,12 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference& x { double fCellVal = xCell->getValue(); double fTime = fCellVal - rtl::math::approxFloor( fCellVal ); - long nIntTime = (long)rtl::math::round( fTime * 8640000.0 ); - if ( nIntTime == 8640000 ) - nIntTime = 0; // 23:59:59.995 and above is 00:00:00.00 + sal_Int64 nIntTime = static_cast(rtl::math::round( fTime * static_cast(::Time::nanoSecPerDay) )); + if ( nIntTime == ::Time::nanoSecPerDay) + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 ::com::sun::star::util::Time aTime; - aTime.HundredthSeconds = (sal_uInt16)( nIntTime % 100 ); - nIntTime /= 100; + aTime.NanoSeconds = (sal_uInt32)( nIntTime % ::Time::nanoSecPerSec ); + nIntTime /= ::Time::nanoSecPerSec; aTime.Seconds = (sal_uInt16)( nIntTime % 60 ); nIntTime /= 60; aTime.Minutes = (sal_uInt16)( nIntTime % 60 ); @@ -394,17 +394,17 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference& x double fDays = ::rtl::math::approxFloor( fCellVal ); double fTime = fCellVal - fDays; long nIntDays = (long)fDays; - long nIntTime = (long)::rtl::math::round( fTime * 8640000.0 ); - if ( nIntTime == 8640000 ) + sal_Int64 nIntTime = ::rtl::math::round( fTime * static_cast(::Time::nanoSecPerDay) ); + if ( nIntTime == ::Time::nanoSecPerDay ) { - nIntTime = 0; // 23:59:59.995 and above is 00:00:00.00 + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 ++nIntDays; // (next day) } ::com::sun::star::util::DateTime aDateTime; - aDateTime.HundredthSeconds = (sal_uInt16)( nIntTime % 100 ); - nIntTime /= 100; + aDateTime.NanoSeconds = (sal_uInt16)( nIntTime % ::Time::nanoSecPerSec ); + nIntTime /= ::Time::nanoSecPerSec; aDateTime.Seconds = (sal_uInt16)( nIntTime % 60 ); nIntTime /= 60; aDateTime.Minutes = (sal_uInt16)( nIntTime % 60 ); diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index 61f3c8d01e71..7eef298f8f51 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -108,7 +108,7 @@ void lcl_CalcJulDate(sal_Int32& _nJulianDate,sal_Int32& _nJulianTime,const com:: aDateTime.Month++; } - _nJulianTime = ((aDateTime.Hours*3600000)+(aDateTime.Minutes*60000)+(aDateTime.Seconds*1000)+(aDateTime.HundredthSeconds*10)); + _nJulianTime = ((aDateTime.Hours*3600000)+(aDateTime.Minutes*60000)+(aDateTime.Seconds*1000)+(aDateTime.NanoSeconds/1000000)); /* conversion factors */ sal_uInt16 iy0; sal_uInt16 im0; diff --git a/connectivity/source/drivers/file/FDateFunctions.cxx b/connectivity/source/drivers/file/FDateFunctions.cxx index 03256f7ab7cc..a24c46d5c153 100644 --- a/connectivity/source/drivers/file/FDateFunctions.cxx +++ b/connectivity/source/drivers/file/FDateFunctions.cxx @@ -263,7 +263,7 @@ ORowSetValue OOp_CurTime::operate(const ::std::vector& lhs) const return ORowSetValue(); Time aCurTime( Time::SYSTEM ); - return ::com::sun::star::util::Time(aCurTime.Get100Sec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour()); + return ::com::sun::star::util::Time(aCurTime.GetNanoSec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour()); } //------------------------------------------------------------------ ORowSetValue OOp_Now::operate(const ::std::vector& lhs) const @@ -272,7 +272,7 @@ ORowSetValue OOp_Now::operate(const ::std::vector& lhs) const return ORowSetValue(); DateTime aCurTime( DateTime::SYSTEM ); - return ::com::sun::star::util::DateTime(aCurTime.Get100Sec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour(), + return ::com::sun::star::util::DateTime(aCurTime.GetNanoSec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour(), aCurTime.GetDay(),aCurTime.GetMonth(),aCurTime.GetYear()); } //------------------------------------------------------------------ diff --git a/connectivity/source/drivers/jdbc/ConnectionLog.cxx b/connectivity/source/drivers/jdbc/ConnectionLog.cxx index 550db58ec1ec..0216ad23186a 100644 --- a/connectivity/source/drivers/jdbc/ConnectionLog.cxx +++ b/connectivity/source/drivers/jdbc/ConnectionLog.cxx @@ -97,8 +97,8 @@ namespace comphelper { namespace log { namespace convert { char buffer[ 30 ]; const size_t buffer_size = sizeof( buffer ); - snprintf( buffer, buffer_size, "%02i:%02i:%02i.%02i", - (int)_rTime.Hours, (int)_rTime.Minutes, (int)_rTime.Seconds, (int)_rTime.HundredthSeconds ); + snprintf( buffer, buffer_size, "%02i:%02i:%02i.%09i", + (int)_rTime.Hours, (int)_rTime.Minutes, (int)_rTime.Seconds, (int)_rTime.NanoSeconds ); return OUString::createFromAscii( buffer ); } @@ -107,9 +107,9 @@ namespace comphelper { namespace log { namespace convert { char buffer[ 30 ]; const size_t buffer_size = sizeof( buffer ); - snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%02i", + snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%09i", (int)_rDateTime.Year, (int)_rDateTime.Month, (int)_rDateTime.Day, - (int)_rDateTime.Hours, (int)_rDateTime.Minutes, (int)_rDateTime.Seconds, (int)_rDateTime.HundredthSeconds ); + (int)_rDateTime.Hours, (int)_rDateTime.Minutes, (int)_rDateTime.Seconds, (int)_rDateTime.NanoSeconds ); return OUString::createFromAscii( buffer ); } diff --git a/connectivity/source/drivers/kab/KResultSet.cxx b/connectivity/source/drivers/kab/KResultSet.cxx index 0ba7e01518c4..faf61bc9a96c 100644 --- a/connectivity/source/drivers/kab/KResultSet.cxx +++ b/connectivity/source/drivers/kab/KResultSet.cxx @@ -344,7 +344,7 @@ DateTime SAL_CALL KabResultSet::getTimestamp(sal_Int32 columnIndex) throw(SQLExc nRet.Hours = nRevision.time().hour(); nRet.Minutes = nRevision.time().minute(); nRet.Seconds = nRevision.time().second(); - nRet.HundredthSeconds = nRevision.time().msec() / 10; + nRet.NanoSeconds = nRevision.time().msec() * ::Time::nanoPerMilli; return nRet; } } diff --git a/connectivity/source/drivers/macab/macabutilities.hxx b/connectivity/source/drivers/macab/macabutilities.hxx index b6afd1cbbe5f..a17bda266458 100644 --- a/connectivity/source/drivers/macab/macabutilities.hxx +++ b/connectivity/source/drivers/macab/macabutilities.hxx @@ -92,7 +92,7 @@ namespace connectivity nRet.Hours = ptm->tm_hour; nRet.Minutes = ptm->tm_min; nRet.Seconds = ptm->tm_sec; - nRet.HundredthSeconds = 0; + nRet.NanoSeconds = 0; return nRet; } diff --git a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx index 4e5a11350221..fec060d556c1 100644 --- a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx +++ b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx @@ -436,7 +436,7 @@ OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP,m_bWasNull,**this,&aTime,sizeof aTime); else m_bWasNull = sal_True; - return DateTime((sal_uInt16)aTime.fraction/ODBC_FRACTION_UNITS_PER_HSECOND,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year); + return DateTime(aTime.fraction,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year); } // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx b/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx index 9cca1903fe17..5d234c445ea4 100644 --- a/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx +++ b/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx @@ -411,14 +411,27 @@ void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& aVal ) throw(SQLException, RuntimeException) { - const sal_uInt16 hundredths (aVal.HundredthSeconds); SQLULEN nColSize; - if(hundredths == 0) + if(aVal.NanoSeconds == 0) nColSize = 8; - else if(hundredths % 10 == 0) + else if(aVal.NanoSeconds % 100000000 == 0) nColSize = 10; - else + else if(aVal.NanoSeconds % 10000000 == 0) nColSize = 11; + else if(aVal.NanoSeconds % 1000000 == 0) + nColSize = 12; + else if(aVal.NanoSeconds % 100000 == 0) + nColSize = 13; + else if(aVal.NanoSeconds % 10000 == 0) + nColSize = 14; + else if(aVal.NanoSeconds % 1000 == 0) + nColSize = 15; + else if(aVal.NanoSeconds % 100 == 0) + nColSize = 16; + else if(aVal.NanoSeconds % 10 == 0) + nColSize = 17; + else + nColSize = 18; TIME_STRUCT x(OTools::TimeToOdbcTime(aVal)); setScalarParameter(parameterIndex, DataType::TIME, nColSize, x); } @@ -426,20 +439,32 @@ void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& aVal ) throw(SQLException, RuntimeException) { - sal_uInt16 s(aVal.Seconds); - sal_uInt16 hundredths(aVal.HundredthSeconds); SQLULEN nColSize; - if(hundredths == 0) + if(aVal.NanoSeconds == 0) { - if (s == 0) + if (aVal.Seconds == 0) nColSize=16; else nColSize=19; } - else if(hundredths % 10 == 0) + else if(aVal.NanoSeconds % 100000000 == 0) nColSize = 21; - else + else if(aVal.NanoSeconds % 10000000 == 0) nColSize = 22; + else if(aVal.NanoSeconds % 1000000 == 0) + nColSize = 23; + else if(aVal.NanoSeconds % 100000 == 0) + nColSize = 24; + else if(aVal.NanoSeconds % 10000 == 0) + nColSize = 25; + else if(aVal.NanoSeconds % 1000 == 0) + nColSize = 26; + else if(aVal.NanoSeconds % 100 == 0) + nColSize = 27; + else if(aVal.NanoSeconds % 10 == 0) + nColSize = 28; + else + nColSize = 29; TIMESTAMP_STRUCT x(OTools::DateTimeToTimestamp(aVal)); setScalarParameter(parameterIndex, DataType::TIMESTAMP, nColSize, x); diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx index dcc7c88909b5..211ba70703ee 100644 --- a/connectivity/source/drivers/odbcbase/OResultSet.cxx +++ b/connectivity/source/drivers/odbcbase/OResultSet.cxx @@ -663,7 +663,7 @@ DateTime OResultSet::impl_getTimestamp( sal_Int32 columnIndex ) throw(SQLExcepti TIMESTAMP_STRUCT aTime = impl_getValue< TIMESTAMP_STRUCT > ( columnIndex, m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP ); - return DateTime(static_cast(aTime.fraction/ODBC_FRACTION_UNITS_PER_HSECOND), + return DateTime(aTime.fraction, aTime.second, aTime.minute, aTime.hour, diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index ccce76f018c1..a9be424d9b34 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -107,6 +107,7 @@ namespace pq_sdbc_driver OUString date2String( const com::sun::star::util::Date & x ) { + // TODO FIXME: replace by DBTypeConversion::toDateString char buffer[64]; sprintf( buffer, "%d-%02d-%02d", x.Year, x.Month, x.Day ); return OUString::createFromAscii( buffer ); @@ -114,6 +115,7 @@ OUString date2String( const com::sun::star::util::Date & x ) com::sun::star::util::Date string2Date( const OUString &date ) { + // TODO FIXME: replace by DBTypeConversion::toDate (if it parses the same format) // Format: Year-Month-Day com::sun::star::util::Date ret; @@ -135,15 +137,17 @@ com::sun::star::util::Date string2Date( const OUString &date ) OUString time2String( const com::sun::star::util::Time & x ) { - char buffer[64]; - sprintf( buffer, "%02d:%02d:%02d.%02d", x.Hours, x.Minutes, x.Seconds, x.HundredthSeconds ); + // TODO FIXME: replace by DBTypeConversion::toTimeString + const size_t buflen = 19; + char buffer[buflen]; + snprintf( buffer, buflen, "%02d:%02d:%02d.%09d", x.Hours, x.Minutes, x.Seconds, x.NanoSeconds ); return OUString::createFromAscii( buffer ); - } com::sun::star::util::Time string2Time( const OUString & time ) { + // TODO FIXME: replace by DBTypeConversion::toTime com::sun::star::util::Time ret; sal_Unicode temp[4]; @@ -163,7 +167,8 @@ com::sun::star::util::Time string2Time( const OUString & time ) if( time.getLength() >9 ) { - ret.HundredthSeconds = (sal_Int32)rtl_ustr_toInt32( &time.getStr()[9] , 10 ); + // FIXME does not take into account shorter precision + ret.NanoSeconds = (sal_Int32)rtl_ustr_toInt32( &time.getStr()[9] , 10 ); } return ret; @@ -173,16 +178,18 @@ com::sun::star::util::Time string2Time( const OUString & time ) OUString dateTime2String( const com::sun::star::util::DateTime & x ) { + // TODO FIXME: replace by DBTypeConversion::toDateTimeString char buffer[128]; - sprintf( buffer, "%d-%02d-%02d %02d:%02d:%02d.%02d", + sprintf( buffer, "%d-%02d-%02d %02d:%02d:%02d.%09d", x.Year, x.Month, x.Day, - x.Hours, x.Minutes, x.Seconds, x.HundredthSeconds ); + x.Hours, x.Minutes, x.Seconds, x.NanoSeconds ); return OUString::createFromAscii( buffer ); } com::sun::star::util::DateTime string2DateTime( const OUString & dateTime ) { + // TODO FIXME: replace by DBTypeConversion::toDateTime (if same format) int space = dateTime.indexOf( ' ' ); com::sun::star::util::DateTime ret; @@ -197,7 +204,7 @@ com::sun::star::util::DateTime string2DateTime( const OUString & dateTime ) ret.Hours = time.Hours; ret.Minutes = time.Minutes; ret.Seconds = time.Seconds; - ret.HundredthSeconds = time.HundredthSeconds; + ret.NanoSeconds = time.NanoSeconds; } return ret; } diff --git a/connectivity/source/inc/odbc/OTools.hxx b/connectivity/source/inc/odbc/OTools.hxx index 79be84caf0d2..015e5f2a13ec 100644 --- a/connectivity/source/inc/odbc/OTools.hxx +++ b/connectivity/source/inc/odbc/OTools.hxx @@ -91,7 +91,6 @@ namespace connectivity { class OConnection; - const sal_uInt32 ODBC_FRACTION_UNITS_PER_HSECOND = 10000000L; const sal_Int32 MAX_PUT_DATA_LENGTH = 2000; class OOO_DLLPUBLIC_ODBCBASE OTools @@ -166,7 +165,7 @@ namespace connectivity aVal.hour = x.Hours; aVal.minute = x.Minutes; aVal.second = x.Seconds; - aVal.fraction = x.HundredthSeconds * ODBC_FRACTION_UNITS_PER_HSECOND; + aVal.fraction = x.NanoSeconds; return aVal; } /** -- cgit v1.2.3