25#include <com/sun/star/util/NumberFormatter.hpp>
26#include <com/sun/star/util/Date.hpp>
27#include <com/sun/star/sdbc/XConnection.hpp>
28#include <com/sun/star/util/XNumberFormatTypes.hpp>
29#include <com/sun/star/util/NumberFormat.hpp>
30#include <com/sun/star/sdbc/DataType.hpp>
31#include <com/sun/star/sdb/XColumn.hpp>
32#include <com/sun/star/sdb/XColumnUpdate.hpp>
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::UNO_QUERY;
46 using ::com::sun::star::uno::UNO_QUERY_THROW;
47 using ::com::sun::star::uno::UNO_SET_THROW;
48 using ::com::sun::star::uno::Exception;
49 using ::com::sun::star::uno::XComponentContext;
50 using ::com::sun::star::sdbc::XRowSet;
51 using ::com::sun::star::beans::XPropertySet;
52 using ::com::sun::star::util::NumberFormatter;
53 using ::com::sun::star::util::XNumberFormatter;
54 using ::com::sun::star::util::Date;
55 using ::com::sun::star::sdbc::XConnection;
56 using ::com::sun::star::util::XNumberFormatsSupplier;
57 using ::com::sun::star::beans::XPropertySetInfo;
58 using ::com::sun::star::lang::Locale;
59 using ::com::sun::star::util::XNumberFormatTypes;
60 using ::com::sun::star::sdb::XColumn;
61 using ::com::sun::star::sdb::XColumnUpdate;
63 namespace DataType = ::com::sun::star::sdbc::DataType;
64 namespace NumberFormat = ::com::sun::star::util::NumberFormat;
92 void lcl_clear_nothrow( FormattedColumnValue_Data& _rData )
94 _rData.m_xFormatter.clear();
95 _rData.m_nFormatKey = 0;
96 _rData.m_nFieldType = DataType::OTHER;
97 _rData.m_nKeyType = NumberFormat::UNDEFINED;
98 _rData.m_bNumericField =
false;
100 _rData.m_xColumn.clear();
101 _rData.m_xColumnUpdate.clear();
105 void lcl_initColumnDataValue_nothrow( FormattedColumnValue_Data& _rData,
106 const Reference< XNumberFormatter >& i_rNumberFormatter,
const Reference< XPropertySet >& _rxColumn )
108 lcl_clear_nothrow( _rData );
110 OSL_PRECOND( i_rNumberFormatter.is(),
"lcl_initColumnDataValue_nothrow: no number formats -> no formatted values!" );
111 if ( !i_rNumberFormatter.is() )
116 Reference< XNumberFormatsSupplier > xNumberFormatsSupp( i_rNumberFormatter->getNumberFormatsSupplier(), UNO_SET_THROW );
119 _rData.m_xColumn.set( _rxColumn, UNO_QUERY_THROW );
120 _rData.m_xColumnUpdate.set( _rxColumn, UNO_QUERY );
123 OSL_VERIFY( _rxColumn->getPropertyValue(
"Type") >>= _rData.m_nFieldType );
125 switch ( _rData.m_nFieldType )
129 case DataType::TIMESTAMP:
131 case DataType::BOOLEAN:
132 case DataType::TINYINT:
133 case DataType::SMALLINT:
134 case DataType::INTEGER:
136 case DataType::BIGINT:
137 case DataType::DOUBLE:
138 case DataType::NUMERIC:
139 case DataType::DECIMAL:
140 _rData.m_bNumericField =
true;
143 _rData.m_bNumericField =
false;
148 Reference< XPropertySetInfo > xPSI( _rxColumn->getPropertySetInfo(), UNO_SET_THROW );
149 bool bHaveFieldFormat =
false;
150 static constexpr OUStringLiteral sFormatKeyProperty( u
"FormatKey" );
151 if ( xPSI->hasPropertyByName( sFormatKeyProperty ) )
153 bHaveFieldFormat = ( _rxColumn->getPropertyValue( sFormatKeyProperty ) >>= _rData.m_nFormatKey );
155 if ( !bHaveFieldFormat )
159 Reference< XNumberFormatTypes > xNumTypes( xNumberFormatsSupp->getNumberFormats(), UNO_QUERY_THROW );
164 _rData.m_nKeyType = ::comphelper::getNumberFormatType( xNumberFormatsSupp->getNumberFormats(), _rData.m_nFormatKey );
165 Reference< XPropertySet > xFormatSettings( xNumberFormatsSupp->getNumberFormatSettings(), UNO_SET_THROW );
166 OSL_VERIFY( xFormatSettings->getPropertyValue(
"NullDate") >>= _rData.m_aNullDate );
169 _rData.m_xFormatter = i_rNumberFormatter;
171 catch(
const Exception& )
178 void lcl_initColumnDataValue_nothrow(
const Reference<XComponentContext>& i_rContext, FormattedColumnValue_Data& i_rData,
179 const Reference< XRowSet >& i_rRowSet,
const Reference< XPropertySet >& i_rColumn )
181 OSL_PRECOND( i_rRowSet.is(),
"lcl_initColumnDataValue_nothrow: no row set!" );
182 if ( !i_rRowSet.is() )
185 Reference< XNumberFormatter > xNumberFormatter;
189 Reference< XConnection > xConnection(
getConnection( i_rRowSet ), UNO_SET_THROW );
190 Reference< XNumberFormatsSupplier > xSupplier(
getNumberFormats( xConnection,
true, i_rContext ), UNO_SET_THROW );
193 xNumberFormatter.set( NumberFormatter::create( i_rContext ), UNO_QUERY_THROW );
194 xNumberFormatter->attachNumberFormatsSupplier( xSupplier );
196 catch(
const Exception& )
201 lcl_initColumnDataValue_nothrow( i_rData, xNumberFormatter, i_rColumn );
206 const Reference< XRowSet >& _rxRowSet,
const Reference< XPropertySet >& i_rColumn )
207 :
m_pData( new FormattedColumnValue_Data )
209 lcl_initColumnDataValue_nothrow( _rxContext, *m_pData, _rxRowSet, i_rColumn );
214 const Reference< XPropertySet >& _rxColumn )
215 :
m_pData( new FormattedColumnValue_Data )
217 lcl_initColumnDataValue_nothrow( *m_pData, i_rNumberFormatter, _rxColumn );
239 OSL_PRECOND(
m_pData->m_xColumnUpdate.is(),
"FormattedColumnValue::setFormattedValue: no column!" );
240 if ( !
m_pData->m_xColumnUpdate.is() )
245 if (
m_pData->m_bNumericField )
248 _rFormattedStringValue,
m_pData->m_nFormatKey, ::sal::static_int_cast< sal_Int16 >(
m_pData->m_nFieldType ),
253 m_pData->m_xColumnUpdate->updateString( _rFormattedStringValue );
266 OSL_PRECOND(
m_pData->m_xColumn.is(),
"FormattedColumnValue::setFormattedValue: no column!" );
268 OUString sStringValue;
271 if (
m_pData->m_bNumericField )
279 sStringValue =
m_pData->m_xColumn->getString();
static LanguageType getConfiguredSystemLanguage()
#define DBG_UNHANDLED_EXCEPTION(...)
const LanguageTag & getLocale()