summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2018-04-08 08:14:52 +0200
committerLionel Elie Mamane <lionel@mamane.lu>2018-04-08 17:05:45 +0200
commite29435932d84076c4d9c443e6f6fd95a08799386 (patch)
treeaaaa4db09e3621a5d002985525ab3d6f4334d6d3 /dbaccess
parentccc57c8f8fe6a910767f07b0f077fa76fb8db740 (diff)
tdf#116772 adapt handling of LIKE conditions to cleaned up StructuredFilter
Change-Id: Ifc60da9a95833ee7820a0e03354fa1a8c006e136 Reviewed-on: https://gerrit.libreoffice.org/52573 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu>
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/source/core/api/SingleSelectQueryComposer.cxx73
-rw-r--r--dbaccess/source/core/inc/SingleSelectQueryComposer.hxx2
2 files changed, 73 insertions, 2 deletions
diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
index f35ee41c1f44..e7a7af6870e9 100644
--- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
+++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
@@ -1003,8 +1003,11 @@ bool OSingleSelectQueryComposer::setANDCriteria( OSQLParseNode const * pConditio
{
return setComparsionPredicate(pCondition,_rIterator,rFilter,xFormatter);
}
- else if (SQL_ISRULE(pCondition,like_predicate) ||
- SQL_ISRULE(pCondition,test_for_null) ||
+ else if (SQL_ISRULE(pCondition,like_predicate))
+ {
+ return setLikePredicate(pCondition,_rIterator,rFilter,xFormatter);
+ }
+ else if (SQL_ISRULE(pCondition,test_for_null) ||
SQL_ISRULE(pCondition,in_predicate) ||
SQL_ISRULE(pCondition,all_or_any_predicate) ||
SQL_ISRULE(pCondition,between_predicate))
@@ -1099,6 +1102,72 @@ sal_Int32 OSingleSelectQueryComposer::getPredicateType(OSQLParseNode const * _pP
return nPredicate;
}
+bool OSingleSelectQueryComposer::setLikePredicate(OSQLParseNode const * pCondition, OSQLParseTreeIterator const & _rIterator,
+ std::vector < PropertyValue >& rFilter, const Reference< css::util::XNumberFormatter > & xFormatter) const
+{
+ OSL_ENSURE(SQL_ISRULE(pCondition, like_predicate),"setLikePredicate: pCondition is not a LikePredicate");
+
+ assert(pCondition->count() == 2);
+ OSQLParseNode const *pRowValue = pCondition->getChild(0);
+ OSQLParseNode const *pPart2 = pCondition->getChild(1);
+
+ PropertyValue aItem;
+ if ( SQL_ISTOKEN(pPart2->getChild(0),NOT) )
+ aItem.Handle = SQLFilterOperator::NOT_LIKE;
+ else
+ aItem.Handle = SQLFilterOperator::LIKE;
+
+ if (SQL_ISRULE(pRowValue, column_ref))
+ {
+ OUString aValue;
+
+ // skip (optional "NOT") and "LIKE"
+ for (size_t i=2; i < pPart2->count(); i++)
+ {
+ pPart2->getChild(i)->parseNodeToPredicateStr(
+ aValue, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>(m_sDecimalSep.toChar() ) );
+ }
+
+ aItem.Name = getColumnName(pRowValue,_rIterator);
+ aItem.Value <<= aValue;
+ rFilter.push_back(aItem);
+ }
+ else if (SQL_ISRULE(pRowValue, set_fct_spec ) ||
+ SQL_ISRULE(pRowValue, general_set_fct))
+ {
+ OUString aValue;
+ OUString aColumnName;
+
+ pPart2->getChild(2)->parseNodeToPredicateStr(aValue, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>( m_sDecimalSep.toChar() ) );
+ pPart2->getChild(3)->parseNodeToPredicateStr(aValue, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>( m_sDecimalSep.toChar() ) );
+ pRowValue->parseNodeToPredicateStr( aColumnName, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>( m_sDecimalSep .toChar() ) );
+
+ aItem.Name = getColumnName(pRowValue,_rIterator);
+ aItem.Value <<= aValue;
+ rFilter.push_back(aItem);
+ }
+ else // Can only be an expression
+ {
+ OUString aName, aValue;
+
+ OSQLParseNode const *pValue = pPart2->getChild(2);
+
+ // Field names
+ for (size_t i=0;i< pRowValue->count();i++)
+ pRowValue->getChild(i)->parseNodeToPredicateStr( aName, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>( m_sDecimalSep.toChar() ) );
+
+ // Criterion
+ for(size_t i=0;i< pValue->count();i++)
+ pValue->getChild(i)->parseNodeToPredicateStr(aValue, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>( m_sDecimalSep.toChar() ) );
+ pPart2->getChild(3)->parseNodeToPredicateStr(aValue, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>( m_sDecimalSep.toChar() ) );
+
+ aItem.Name = aName;
+ aItem.Value <<= aValue;
+ rFilter.push_back(aItem);
+ }
+ return true;
+}
+
bool OSingleSelectQueryComposer::setComparsionPredicate(OSQLParseNode const * pCondition, OSQLParseTreeIterator const & _rIterator,
std::vector < PropertyValue >& rFilter, const Reference< css::util::XNumberFormatter > & xFormatter) const
{
diff --git a/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx b/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx
index 524ca93cdcca..c349708ceded 100644
--- a/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx
+++ b/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx
@@ -114,6 +114,8 @@ namespace dbaccess
std::vector< std::vector < css::beans::PropertyValue > >& rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;
bool setANDCriteria(::connectivity::OSQLParseNode const * pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
std::vector < css::beans::PropertyValue > & rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;
+ bool setLikePredicate(::connectivity::OSQLParseNode const * pCondition, ::connectivity::OSQLParseTreeIterator const & _rIterator,
+ std::vector < css::beans::PropertyValue > & rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;
bool setComparsionPredicate(::connectivity::OSQLParseNode const * pCondition, ::connectivity::OSQLParseTreeIterator const & _rIterator,
std::vector < css::beans::PropertyValue > & rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;