24#include <com/sun/star/i18n/LocaleData.hpp>
25#include <com/sun/star/sdbc/DataType.hpp>
26#include <com/sun/star/sdbc/ColumnValue.hpp>
27#include <com/sun/star/sdbc/XConnection.hpp>
28#include <com/sun/star/util/NumberFormatter.hpp>
29#include <osl/diagnose.h>
42 using ::com::sun::star::sdbc::XConnection;
43 using ::com::sun::star::util::XNumberFormatsSupplier;
44 using ::com::sun::star::util::NumberFormatter;
45 using ::com::sun::star::uno::UNO_QUERY_THROW;
46 using ::com::sun::star::uno::XComponentContext;
47 using ::com::sun::star::beans::XPropertySet;
48 using ::com::sun::star::beans::XPropertySetInfo;
49 using ::com::sun::star::lang::Locale;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::i18n::LocaleData;
53 using ::com::sun::star::i18n::LocaleDataItem;
54 using ::com::sun::star::uno::Any;
59 using ::connectivity::OSQLParseNode;
63 std::u16string_view _rSeparator,
sal_Unicode _nFallback )
65 OSL_ENSURE( !_rSeparator.empty(),
"::lcl_getSeparatorChar: invalid separator string!" );
68 if ( !_rSeparator.empty() )
69 nReturn = _rSeparator[0];
79 LocaleDataItem aLocaleData;
90 TOOLS_WARN_EXCEPTION(
"connectivity.commontools",
"OPredicateInputController::getSeparatorChars" );
97 const Reference< XComponentContext >& rxContext,
const Reference< XConnection >& _rxConnection,
const IParseContext* _pParseContext )
99 ,m_aParser( rxContext, _pParseContext )
104 OSL_ENSURE( rxContext.is(),
"OPredicateInputController::OPredicateInputController: need a service factory!" );
105 if ( rxContext.is() )
107 m_xFormatter.set( NumberFormatter::create(rxContext), UNO_QUERY_THROW );
111 if ( !xNumberFormats.is() )
114 m_xFormatter->attachNumberFormatsSupplier( xNumberFormats );
117 if ( rxContext.is() )
124 TOOLS_WARN_EXCEPTION(
"connectivity.commontools",
"OPredicateInputController::OPredicateInputController" );
134 sal_Int32
nType = DataType::OTHER;
135 _rxField->getPropertyValue(
"Type") >>=
nType;
137 if ( ( DataType::CHAR ==
nType )
138 || ( DataType::VARCHAR ==
nType )
139 || ( DataType::LONGVARCHAR ==
nType )
140 || ( DataType::CLOB ==
nType )
143 OUString sQuoted( _rStatement );
144 if ( !sQuoted.isEmpty()
145 && ( !sQuoted.startsWith(
"'")
146 || !sQuoted.endsWith(
"'")
150 sQuoted =
u"'" + sQuoted.replaceAll(
u"'",
u"''") +
u"'";
162 if ( ( DataType::FLOAT ==
nType )
163 || ( DataType::REAL ==
nType )
164 || ( DataType::DOUBLE ==
nType )
165 || ( DataType::NUMERIC ==
nType )
166 || ( DataType::DECIMAL ==
nType )
180 Reference< XPropertySetInfo > xPSI( _rxField->getPropertySetInfo() );
181 if ( xPSI.is() && xPSI->hasPropertyByName(
"FormatKey") )
183 sal_Int32 nFormatKey = 0;
184 _rxField->getPropertyValue(
"FormatKey") >>= nFormatKey;
188 ::comphelper::getNumberFormatProperty(
195 if ( !aFormatLocale.Language.isEmpty() )
204 TOOLS_WARN_EXCEPTION(
"connectivity.commontools",
"OPredicateInputController::implPredicateTree: caught an exception while dealing with the formats!" );
207 bool bDecDiffers = ( nCtxDecSep != nFmtDecSep );
208 bool bFmtDiffers = ( nCtxThdSep != nFmtThdSep );
209 if ( bDecDiffers || bFmtDiffers )
212 OUString sTranslated( _rStatement );
214 sTranslated = sTranslated.replace( nCtxDecSep, nIntermediate );
215 sTranslated = sTranslated.replace( nCtxThdSep, nFmtThdSep );
216 sTranslated = sTranslated.replace( nIntermediate, nFmtDecSep );
227 OUString& _rPredicateValue,
const Reference< XPropertySet > & _rxField, OUString* _pErrorMessage )
const
230 "OPredicateInputController::normalizePredicateString: invalid state or params!" );
232 bool bSuccess =
false;
237 OUString sTransformedText( _rPredicateValue );
238 std::unique_ptr<OSQLParseNode> pParseNode =
implPredicateTree( sError, sTransformedText, _rxField );
239 if ( _pErrorMessage ) *_pErrorMessage = sError;
248 sTransformedText.clear();
249 pParseNode->parseNodeToPredicateStr(
253 _rPredicateValue = sTransformedText;
264 const OUString& _rPredicateValue,
const Reference< XPropertySet > & _rxField )
const
266 OSL_ENSURE( _rxField.is(),
"OPredicateInputController::getPredicateValue: invalid params!" );
274 std::unique_ptr<OSQLParseNode> pParseNode =
implPredicateTree( sError, _rPredicateValue, _rxField );
283 const OUString& _sField,
const OUString& _rPredicateValue )
const
285 OUString sReturn = _rPredicateValue;
288 OUString sField = _sField.getToken(0,
'(',
nIndex);
292 if (
nType == DataType::OTHER || sField.isEmpty() )
295 OUString sSql =
"SELECT * FROM x WHERE " + sField + _rPredicateValue;
297 nType = DataType::DOUBLE;
300 Reference<XDatabaseMetaData> xMeta =
m_xConnection->getMetaData();
305 ColumnValue::NULLABLE_UNKNOWN,
311 xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
315 Reference<XPropertySet>
xColumn = pColumn;
316 pColumn->setFunction(
true);
317 pColumn->setRealName(sField);
328 const OUString& _rPredicateValue,
const Reference< XPropertySet > & _rxField )
const
330 OSL_ENSURE( _rxField.is(),
"OPredicateInputController::getPredicateValue: invalid params!" );
338 std::unique_ptr<OSQLParseNode> pParseNode =
implPredicateTree( sError, _rPredicateValue, _rxField );
356 if ( _bForStatementUse )
359 OSL_ENSURE( pFuncSpecParent,
"OPredicateInputController::getPredicateValue: an ODBC func spec node without parent?" );
360 if ( pFuncSpecParent )
376 assert(pParseNode->count() == 2);
380 else if (pParseNode->count() >= 3)
383 assert(pValueNode &&
"OPredicateInputController::getPredicateValue: invalid node child!");
384 if ( !_bForStatementUse )
400 OSL_FAIL(
"OPredicateInputController::getPredicateValue: unknown/invalid structure (noodbc)!" );
virtual css::lang::Locale getPreferredLocale() const =0
gets a locale instance which should be used when parsing in the context specified by this instance
void parseNodeToStr(OUString &rString, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const IParseContext *pContext=nullptr, bool _bIntl=false, bool _bQuote=true) const
const OUString & getTokenValue() const
OSQLParseNode * getParent() const
OSQLParseNode * getChild(sal_uInt32 nPos) const
OSQLParseNode * getByRule(OSQLParseNode::Rule eRule) const
SQLNodeType getNodeType() const
static sal_Int32 getFunctionReturnType(std::u16string_view _sFunctionName, const IParseContext *pContext)
const IParseContext & getContext() const
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XConnection > m_xConnection