/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
using ::com::sun::star::sdbc::XConnection; using ::com::sun::star::util::XNumberFormatsSupplier; using ::com::sun::star::util::NumberFormatter; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::beans::XPropertySetInfo; using ::com::sun::star::lang::Locale; using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Reference; using ::com::sun::star::i18n::LocaleData; using ::com::sun::star::i18n::LocaleDataItem; using ::com::sun::star::uno::Any;
// one more fallback: for numeric fields, and value strings containing a decimal/thousands separator // problem which is to be solved with this: // * a system locale "german" // * a column formatted with an english number format // => the output is german (as we use the system locale for this), i.e. "3,4" // => the input does not recognize the german text, as predicateTree uses the number format // of the column to determine the main locale - the locale on the context is only a fallback if ( ( DataType::FLOAT == nType )
|| ( DataType::REAL == nType )
|| ( DataType::DOUBLE == nType )
|| ( DataType::NUMERIC == nType )
|| ( DataType::DECIMAL == nType )
)
{ const IParseContext& rParseContext = m_aParser.getContext(); // get the separators for the locale of our parse context
sal_Unicode nCtxDecSep;
sal_Unicode nCtxThdSep;
getSeparatorChars( rParseContext.getPreferredLocale(), nCtxDecSep, nCtxThdSep );
// determine the locale of the column we're building a predicate string for
sal_Unicode nFmtDecSep( nCtxDecSep );
sal_Unicode nFmtThdSep( nCtxThdSep ); try
{
Reference< XPropertySetInfo > xPSI( _rxField->getPropertySetInfo() ); if ( xPSI.is() && xPSI->hasPropertyByName(u"FormatKey"_ustr) )
{
sal_Int32 nFormatKey = 0;
_rxField->getPropertyValue(u"FormatKey"_ustr) >>= nFormatKey; if ( nFormatKey && m_xFormatter.is() )
{
Locale aFormatLocale;
::comphelper::getNumberFormatProperty(
m_xFormatter,
nFormatKey,
u"Locale"_ustr
) >>= aFormatLocale;
// valid locale if ( !aFormatLocale.Language.isEmpty() )
{
getSeparatorChars( aFormatLocale, nFmtDecSep, nCtxThdSep );
}
}
}
} catch( const Exception& )
{
TOOLS_WARN_EXCEPTION( "connectivity.commontools", "OPredicateInputController::implPredicateTree: caught an exception while dealing with the formats!" );
}
bool bDecDiffers = ( nCtxDecSep != nFmtDecSep ); bool bFmtDiffers = ( nCtxThdSep != nFmtThdSep ); if ( bDecDiffers || bFmtDiffers )
{ // okay, at least one differs // "translate" the value into the "format locale"
OUString sTranslated( _rStatement ); const sal_Unicode nIntermediate( '_' );
sTranslated = sTranslated.replace( nCtxDecSep, nIntermediate );
sTranslated = sTranslated.replace( nCtxThdSep, nFmtThdSep );
sTranslated = sTranslated.replace( nIntermediate, nFmtDecSep );
// translate it back into a string
sTransformedText.clear();
pParseNode->parseNodeToPredicateStr(
sTransformedText, m_xConnection, m_xFormatter, _rxField, OUString(),
rParseContext.getPreferredLocale(), OUString(nDecSeparator), &rParseContext
);
_rPredicateValue = sTransformedText;
bSuccess = true;
}
}
return bSuccess;
}
OUString OPredicateInputController::getPredicateValueStr( const OUString& _rPredicateValue, const Reference< XPropertySet > & _rxField ) const
{
OSL_ENSURE( _rxField.is(), "OPredicateInputController::getPredicateValue: invalid params!" );
OUString sReturn; if ( _rxField.is() )
{ // The following is mostly stolen from the former implementation in the parameter dialog // (dbaccess/source/ui/dlg/paramdialog.cxx). I do not fully understand this...
if ( _rxField.is() )
{ // The following is mostly stolen from the former implementation in the parameter dialog // (dbaccess/source/ui/dlg/paramdialog.cxx). I do not fully understand this...
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.