From 9a53b5ccdc0bac5393ac70082beb25a2f1378edd Mon Sep 17 00:00:00 2001 From: Terrence Enger Date: Fri, 30 Sep 2011 17:18:48 -0400 Subject: [PATCH] fdo#34309 timestamp via ODBC OResultSet.cxx::getTimestamp to get timestamp as string first --- .../source/drivers/odbcbase/OResultSet.cxx | 68 +++++++++++++++++--- 1 files changed, 59 insertions(+), 9 deletions(-) diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx index 3c13671..1918c39 100644 --- a/connectivity/source/drivers/odbcbase/OResultSet.cxx +++ b/connectivity/source/drivers/odbcbase/OResultSet.cxx @@ -647,15 +647,65 @@ Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, R DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getTimestamp" ); - TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0}; - const ORowSetValue& aValue = getValue(columnIndex, - m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP, - &aTime,sizeof aTime); - return (&aValue == &m_aEmptyValue) - ? - DateTime(static_cast(aTime.fraction*1000),aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year) - : - (DateTime)aValue; + + DateTime retVal; + + // TODO: Ask if the code needs a justifying comment like this + // reference to C451. + + // "Data Management: SQL Call Level Interface", X/Open Company + // Ltd., 1995. in section "4.8.4 Transfers and Conversions > + // Transfers with Conversion to/from String" + // , + // page 62, says "C programs must specify SQL_CHAR, forcing + // string conversion, for SQL data types ... TIMESTAMP + // ... because there is no direct equivalent for DECIMAL and + // NUMERIC in C." This function accepts that declaration, + // even though I (tje, 2011-09-14) find it hard to believe. + // + // So, I (tje, 2011-09-14) wonder what database delivers a TIME + // with fraction of a second? From experimentation, not DB2 + // for IBM i. + + rtl::OUString tsString = getString( columnIndex ); + sal_uInt32 tsStringLen = tsString.getLength(); + OSL_ENSURE( 0 == tsStringLen || + 19 == tsStringLen || + 21 == tsStringLen || + 22 <= tsStringLen + , "Length of character representation of timestamp is unexpected" + ); + + sal_uInt16 centiseconds = 0; + // TODO: Ask if it is right to truncate milliseconds. It would be + // really funny to let a few milliseconds--milliseconds not + // right at midnight--change the date. Then again, that could + // happen only if we knew how many seconds there are in the + // last minute of the day; but we do not know that. + if ( 21 == tsStringLen ) + { + centiseconds = static_cast + ( tsString.copy( 20, 1 ).toInt32( 10 )) * 10; + }; + if ( 22 <= tsStringLen ) + { + centiseconds = static_cast + ( tsString.copy( 20, 2 ).toInt32( 10 )); + }; + + if ( 19 <= tsStringLen ) + retVal = DateTime + ( centiseconds + , static_cast( tsString.copy( 17, 2 ).toInt32( 10 )) + , static_cast( tsString.copy( 14, 2 ).toInt32( 10 )) + , static_cast( tsString.copy( 11, 2 ).toInt32( 10 )) + , static_cast( tsString.copy( 8, 2 ).toInt32( 10 )) + , static_cast( tsString.copy( 5, 2 ).toInt32( 10 )) + , static_cast( tsString.copy( 0, 4 ).toInt32( 10 )) + ); + + return retVal; + } // ------------------------------------------------------------------------- -- 1.7.4.1