summaryrefslogtreecommitdiff
path: root/connectivity/source/commontools/DateConversion.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/commontools/DateConversion.cxx')
-rwxr-xr-x[-rw-r--r--]connectivity/source/commontools/DateConversion.cxx73
1 files changed, 37 insertions, 36 deletions
diff --git a/connectivity/source/commontools/DateConversion.cxx b/connectivity/source/commontools/DateConversion.cxx
index 531df746045f..cd335987c121 100644..100755
--- a/connectivity/source/commontools/DateConversion.cxx
+++ b/connectivity/source/commontools/DateConversion.cxx
@@ -44,6 +44,7 @@
#include "diagnose_ex.h"
#include <comphelper/numbers.hxx>
#include <rtl/ustrbuf.hxx>
+#include <tools/diagnose_ex.h>
using namespace ::connectivity;
@@ -364,56 +365,59 @@ void DBTypeConversion::setValue(const Reference<XColumnUpdate>& xVariant,
}
//------------------------------------------------------------------------------
-double DBTypeConversion::getValue(const Reference<XColumn>& xVariant,
- const Date& rNullDate,
- sal_Int16 nKeyType)
+double DBTypeConversion::getValue( const Reference< XColumn >& i_column, const Date& i_relativeToNullDate )
{
try
{
- switch (nKeyType & ~NumberFormat::DEFINED)
+ const Reference< XPropertySet > xProp( i_column, UNO_QUERY_THROW );
+
+ const sal_Int32 nColumnType = ::comphelper::getINT32( xProp->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_TYPE ) ) );
+ switch ( nColumnType )
{
- case NumberFormat::DATE:
- return toDouble( xVariant->getDate(), rNullDate);
- case NumberFormat::DATETIME:
- return toDouble(xVariant->getTimestamp(),rNullDate);
- case NumberFormat::TIME:
- return toDouble(xVariant->getTime());
- default:
+ case DataType::DATE:
+ return toDouble( i_column->getDate(), i_relativeToNullDate );
+
+ case DataType::TIME:
+ return toDouble( i_column->getTime() );
+
+ case DataType::TIMESTAMP:
+ return toDouble( i_column->getTimestamp(), i_relativeToNullDate );
+
+ default:
{
- Reference<XPropertySet> xProp(xVariant,UNO_QUERY);
- if ( xProp.is()
- && xProp->getPropertySetInfo()->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSIGNED))
- && !::comphelper::getBOOL(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSIGNED))) )
+ sal_Bool bIsSigned = sal_True;
+ OSL_VERIFY( xProp->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ISSIGNED ) ) >>= bIsSigned );
+ if ( !bIsSigned )
{
- switch (::comphelper::getINT32(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
+ switch ( nColumnType)
{
case DataType::TINYINT:
- return static_cast<double>(static_cast<sal_uInt8>(xVariant->getByte()));
+ return static_cast<double>(static_cast<sal_uInt8>(i_column->getByte()));
case DataType::SMALLINT:
- return static_cast<double>(static_cast<sal_uInt16>(xVariant->getShort()));
+ return static_cast<double>(static_cast<sal_uInt16>(i_column->getShort()));
case DataType::INTEGER:
- return static_cast<double>(static_cast<sal_uInt32>(xVariant->getInt()));
+ return static_cast<double>(static_cast<sal_uInt32>(i_column->getInt()));
case DataType::BIGINT:
- return static_cast<double>(static_cast<sal_uInt64>(xVariant->getLong()));
+ return static_cast<double>(static_cast<sal_uInt64>(i_column->getLong()));
}
}
-
- return xVariant->getDouble();
}
+ return i_column->getDouble();
}
}
- catch(const Exception& )
+ catch( const Exception& )
{
+ DBG_UNHANDLED_EXCEPTION();
return 0.0;
}
}
//------------------------------------------------------------------------------
-::rtl::OUString DBTypeConversion::getValue(const Reference< XPropertySet>& _xColumn,
+::rtl::OUString DBTypeConversion::getFormattedValue(const Reference< XPropertySet>& _xColumn,
const Reference<XNumberFormatter>& _xFormatter,
const ::com::sun::star::lang::Locale& _rLocale,
const Date& _rNullDate)
{
- OSL_ENSURE(_xColumn.is() && _xFormatter.is(), "DBTypeConversion::getValue: invalid arg !");
+ OSL_ENSURE(_xColumn.is() && _xFormatter.is(), "DBTypeConversion::getFormattedValue: invalid arg !");
if (!_xColumn.is() || !_xFormatter.is())
return ::rtl::OUString();
@@ -424,7 +428,7 @@ double DBTypeConversion::getValue(const Reference<XColumn>& xVariant,
}
catch (const Exception& )
{
- OSL_ENSURE(false, "DBTypeConversion::getValue: caught an exception while asking for the format key!");
+ OSL_ENSURE(false, "DBTypeConversion::getFormattedValue: caught an exception while asking for the format key!");
}
if (!nKey)
@@ -440,11 +444,11 @@ double DBTypeConversion::getValue(const Reference<XColumn>& xVariant,
sal_Int16 nKeyType = getNumberFormatType(_xFormatter, nKey) & ~NumberFormat::DEFINED;
- return DBTypeConversion::getValue(Reference< XColumn > (_xColumn, UNO_QUERY), _xFormatter, _rNullDate, nKey, nKeyType);
+ return DBTypeConversion::getFormattedValue(Reference< XColumn > (_xColumn, UNO_QUERY), _xFormatter, _rNullDate, nKey, nKeyType);
}
//------------------------------------------------------------------------------
-::rtl::OUString DBTypeConversion::getValue(const Reference<XColumn>& xVariant,
+::rtl::OUString DBTypeConversion::getFormattedValue(const Reference<XColumn>& xVariant,
const Reference<XNumberFormatter>& xFormatter,
const Date& rNullDate,
sal_Int32 nKey,
@@ -461,23 +465,20 @@ double DBTypeConversion::getValue(const Reference<XColumn>& xVariant,
case NumberFormat::DATETIME:
{
// get a value which represents the given date, relative to the given null date
- double fValue = getValue(xVariant, rNullDate, nKeyType);
+ double fValue = getValue( xVariant, rNullDate );
if ( !xVariant->wasNull() )
{
// get the null date of the formatter
Date aFormatterNullDate( rNullDate );
try
{
- Reference< XPropertySet > xFormatterSettings;
- Reference< XNumberFormatsSupplier > xSupplier( xFormatter->getNumberFormatsSupplier( ) );
- if ( xSupplier.is() )
- xFormatterSettings = xSupplier->getNumberFormatSettings();
- if ( xFormatterSettings.is() )
- xFormatterSettings->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NullDate" ) ) ) >>= aFormatterNullDate;
+ Reference< XNumberFormatsSupplier > xSupplier( xFormatter->getNumberFormatsSupplier(), UNO_SET_THROW );
+ Reference< XPropertySet > xFormatterSettings( xSupplier->getNumberFormatSettings(), UNO_SET_THROW );
+ OSL_VERIFY( xFormatterSettings->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NullDate" ) ) ) >>= aFormatterNullDate );
}
catch( const Exception& )
{
- OSL_ENSURE( sal_False, "DBTypeConversion::getValue: caught an exception while retrieving the formatter's NullDate!" );
+ DBG_UNHANDLED_EXCEPTION();
}
// get a value which represents the given date, relative to the null date of the formatter
fValue -= toDays( rNullDate, aFormatterNullDate );