diff options
author | Fabio Buso <dev.siroibaf@gmail.com> | 2016-08-09 10:25:37 +0200 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2016-08-10 14:32:32 +0000 |
commit | 2c76fd1e04441889fbc416d4e5815ef31b474193 (patch) | |
tree | cd7aea0a33a0df8a3bef79ec801db5bed2fd62bf | |
parent | d6e8d4f773d970b69baedd8523a426f18a8d8eef (diff) |
tdf#67647 getStructuredFilter returns operator
Change-Id: I010ea3c24b4d5411711a93e35d4b173f5bde9e55
Reviewed-on: https://gerrit.libreoffice.org/28000
Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu>
Tested-by: Lionel Elie Mamane <lionel@mamane.lu>
7 files changed, 15 insertions, 125 deletions
diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index 1b8f13404017..4bd1fe4fc84c 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -1115,7 +1115,7 @@ sal_Int32 OSingleSelectQueryComposer::getPredicateType(OSQLParseNode * _pPredica bool OSingleSelectQueryComposer::setComparsionPredicate(OSQLParseNode * pCondition, OSQLParseTreeIterator& _rIterator, ::std::vector < PropertyValue >& rFilter, const Reference< css::util::XNumberFormatter > & xFormatter) const { - OSL_ENSURE(SQL_ISRULE(pCondition, comparison_predicate),"setComparsionPredicate: pCondition ist kein ComparsionPredicate"); + OSL_ENSURE(SQL_ISRULE(pCondition, comparison_predicate),"setComparsionPredicate: pCondition is not a ComparsionPredicate"); if (SQL_ISRULE(pCondition->getChild(0), column_ref) || SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref)) { @@ -1128,12 +1128,9 @@ bool OSingleSelectQueryComposer::setComparsionPredicate(OSQLParseNode * pConditi sal_uInt32 i=1; aItem.Handle = getPredicateType(pCondition->getChild(i)); - // don't display the equal - if (pCondition->getChild(i)->getNodeType() == SQLNodeType::Equal) - i++; - // go forward - for (;i < pCondition->count();i++) + // go forward - don't display the operator + for (i++;i < pCondition->count();i++) pCondition->getChild(i)->parseNodeToPredicateStr( aValue, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>(m_sDecimalSep.toChar() ) ); } @@ -1145,44 +1142,33 @@ bool OSingleSelectQueryComposer::setComparsionPredicate(OSQLParseNode * pConditi switch (pCondition->getChild(i)->getNodeType()) { case SQLNodeType::Equal: - // don't display the equal - i--; aItem.Handle = SQLFilterOperator::EQUAL; break; case SQLNodeType::NotEqual: - i--; aItem.Handle = SQLFilterOperator::NOT_EQUAL; break; case SQLNodeType::Less: // take the opposite as we change the order - i--; - aValue = ">="; aItem.Handle = SQLFilterOperator::GREATER_EQUAL; break; case SQLNodeType::LessEq: // take the opposite as we change the order - i--; - aValue = ">"; aItem.Handle = SQLFilterOperator::GREATER; break; case SQLNodeType::Great: // take the opposite as we change the order - i--; - aValue = "<="; aItem.Handle = SQLFilterOperator::LESS_EQUAL; break; case SQLNodeType::GreatEq: // take the opposite as we change the order - i--; - aValue = "<"; aItem.Handle = SQLFilterOperator::LESS; break; default: break; } - // go backward - for (; i >= 0; i--) + // go backward - don't display the operator + for (i--; i >= 0; i--) pCondition->getChild(i)->parseNodeToPredicateStr( aValue, m_xConnection, xFormatter, m_aLocale, static_cast<sal_Char>( m_sDecimalSep.toChar() ) ); } @@ -1729,6 +1715,7 @@ Sequence< Sequence< PropertyValue > > OSingleSelectQueryComposer::getStructuredC Sequence< Sequence< PropertyValue > > aFilterSeq; OUString sFilter = getStatementPart( _aGetFunctor, m_aAdditiveIterator ); + if ( !sFilter.isEmpty() ) { OUString aSql(m_aPureSelectSQL + STR_WHERE + sFilter); diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index bae2bbfe1a23..c38e5b4b93ca 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -480,11 +480,7 @@ void SbaTableQueryBrowser::impl_sanitizeRowSetClauses_nothrow() // "SELECT * FROM <table> WHERE <other_table>.<column> = <value>", it will return "<column>". But // there's no API at all to retrieve the information about "<other_table>" - which is what would // be needed here. - // That'd be a chance to replace getStructuredFilter with something more reasonable. This method - // has at least one other problem: for a clause like "<column> != <value>", it will return "<column>" - // as column name, "NOT_EQUAL" as operator, and "!= <value>" as value, effectively duplicating the - // information about the operator, and begging all clients to manually remove the "!=" from the value - // string. + // That'd be a chance to replace getStructuredFilter with something more reasonable. // So, what really would be handy, is some // XNormalizedFilter getNormalizedFilter(); // with diff --git a/dbaccess/source/ui/dlg/queryfilter.cxx b/dbaccess/source/ui/dlg/queryfilter.cxx index 27bec94f4563..5193bf587ede 100644 --- a/dbaccess/source/ui/dlg/queryfilter.cxx +++ b/dbaccess/source/ui/dlg/queryfilter.cxx @@ -469,9 +469,8 @@ IMPL_LINK_TYPED( DlgFilterCrit, PredicateLoseFocus, Control&, rControl, void ) void DlgFilterCrit::SetLine( sal_uInt16 nIdx,const PropertyValue& _rItem,bool _bOr ) { - OUString aCondition; - _rItem.Value >>= aCondition; - OUString aStr = aCondition; + OUString aStr; + _rItem.Value >>= aStr; if ( _rItem.Handle == SQLFilterOperator::LIKE || _rItem.Handle == SQLFilterOperator::NOT_LIKE ) ::Replace_SQL_PlaceHolder(aStr); @@ -479,42 +478,6 @@ void DlgFilterCrit::SetLine( sal_uInt16 nIdx,const PropertyValue& _rItem,bool _b Reference< XPropertySet > xColumn = getColumn( _rItem.Name ); - // remove the predicate from the condition - switch(_rItem.Handle) - { - case SQLFilterOperator::EQUAL: - // aStr.Erase(0,1); - break; - case SQLFilterOperator::NOT_EQUAL: - aStr = aStr.copy(2); - break; - case SQLFilterOperator::LESS: - aStr = aStr.copy(1); - break; - case SQLFilterOperator::LESS_EQUAL: - aStr = aStr.copy(2); - break; - case SQLFilterOperator::GREATER: - aStr = aStr.copy(1); - break; - case SQLFilterOperator::GREATER_EQUAL: - aStr = aStr.copy(2); - break; - case SQLFilterOperator::NOT_LIKE: - aStr = aStr.copy(8); - break; - case SQLFilterOperator::LIKE: - aStr = aStr.copy(4); - break; - case SQLFilterOperator::SQLNULL: - aStr = aStr.copy(7); - break; - case SQLFilterOperator::NOT_SQLNULL: - aStr = aStr.copy(11); - break; - } - aStr = comphelper::string::stripStart(aStr, ' '); - // to make sure that we only set first three ListBox* pColumnListControl = nullptr; ListBox* pPredicateListControl = nullptr; diff --git a/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer.java b/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer.java index a69e99251580..0eb16534efb7 100644 --- a/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer.java +++ b/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer.java @@ -149,9 +149,10 @@ public class _XSingleSelectQueryAnalyzer extends MultiMethodTest { requiredMethod("getFilter()"); try{ oObj.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\""); - String complexFilter = "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )"; + String complexFilter = "( \"Identifier\" >= '1' AND \"Type\" <= '4' ) OR ( \"Identifier\" <> '2' AND \"Type\" = '5' ) OR ( \"Identifier\" < '3' AND \"Type\" > '6' AND \"Address\" = '7' ) OR ( \"Address\" >= '8' ) OR ( \"Type\" = '9' )"; xComposer.setFilter(complexFilter); PropertyValue[][] aStructuredFilter = oObj.getStructuredFilter(); + xComposer.setFilter(""); xComposer.setStructuredFilter(aStructuredFilter); tRes.tested("getStructuredFilter()", oObj.getFilter().equals(complexFilter)); @@ -233,8 +234,8 @@ public class _XSingleSelectQueryAnalyzer extends MultiMethodTest { requiredMethod("setQuery()"); requiredMethod("getFilter()"); executeMethod("getStructuredFilter()"); - String complexFilter = "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )"; + String complexFilter = "( \"Identifier\" >= '1' AND \"Type\" <= '4' ) OR ( \"Identifier\" <> '2' AND \"Type\" = '5' ) OR ( \"Identifier\" < '3' AND \"Type\" > '6' AND \"Address\" = '7' ) OR ( \"Address\" >= '8' ) OR ( \"Type\" = '9' )"; try{ xComposer.setHavingClause(complexFilter); PropertyValue[][] aStructuredHaving = oObj.getStructuredHavingClause(); diff --git a/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java b/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java index 2764574bb193..0b35515513e6 100644 --- a/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java +++ b/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer.java @@ -147,7 +147,7 @@ public class _XSingleSelectQueryComposer extends MultiMethodTest { requiredMethod("setFilter()"); try{ xQueryAna.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\""); - String complexFilter = "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )"; + String complexFilter = "( \"Identifier\" >= '1' AND \"Type\" <= '4' ) OR ( \"Identifier\" <> '2' AND \"Type\" = '5' ) OR ( \"Identifier\" < '3' AND \"Type\" > '6' AND \"Address\" = '7' ) OR ( \"Address\" >= '8' ) OR ( \"Type\" = '9' )"; oObj.setFilter(complexFilter); PropertyValue[][] aStructuredFilter = xQueryAna.getStructuredFilter(); oObj.setFilter(""); @@ -358,8 +358,7 @@ public class _XSingleSelectQueryComposer extends MultiMethodTest { public void _setStructuredHavingClause() { requiredMethod("setHavingClause()"); executeMethod("setStructuredFilter()"); - String complexFilter = "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )"; - + String complexFilter = "( \"Identifier\" >= '1' AND \"Type\" <= '4' ) OR ( \"Identifier\" <> '2' AND \"Type\" = '5' ) OR ( \"Identifier\" < '3' AND \"Type\" > '6' AND \"Address\" = '7' ) OR ( \"Address\" >= '8' ) OR ( \"Type\" = '9' )"; try{ oObj.setHavingClause(complexFilter); PropertyValue[][] aStructuredHaving = diff --git a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java index d169f7dd951a..17bc953affa9 100644 --- a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java +++ b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java @@ -429,62 +429,6 @@ public class SQLQueryComposer } } - /** - * retrieves a normalized structured filter - * - * <p>XSingleSelectQueryComposer.getStructuredFilter has a strange habit of returning the predicate (equal, not equal, etc) - * effectively twice: Once as SQLFilterOperator, and once in the value. That is, if you have a term {@literal "column <> 3"}, then - * you'll get an SQLFilterOperator.NOT_EQUAL (which is fine), <strong>and</strong> the textual value of the condition - * will read {@literal "<> 3"}. The latter is strange enough, but even more strange is that this behavior is not even consistent: - * for SQLFilterOperator.EQUAL, the "=" sign is not include in the textual value.</p> - * - * <p>To abstract from this weirdness, use this function here, which strips the unwanted tokens from the textual value - * representation.</p> - */ - public PropertyValue[][] getNormalizedStructuredFilter() - { - final PropertyValue[][] structuredFilter = m_queryComposer.getStructuredFilter(); - for (int i = 0; i < structuredFilter.length; ++i) - { - for (int j = 0; j < structuredFilter[i].length; ++j) - { - if (!(structuredFilter[i][j].Value instanceof String)) - { - continue; - } - final StringBuffer textualValue = new StringBuffer((String) structuredFilter[i][j].Value); - switch (structuredFilter[i][j].Handle) - { - case SQLFilterOperator.EQUAL: - break; - case SQLFilterOperator.NOT_EQUAL: - case SQLFilterOperator.LESS_EQUAL: - case SQLFilterOperator.GREATER_EQUAL: - textualValue.delete(0, 2); - break; - case SQLFilterOperator.LESS: - case SQLFilterOperator.GREATER: - textualValue.delete(0, 1); - break; - case SQLFilterOperator.NOT_LIKE: - textualValue.delete(0, 8); - break; - case SQLFilterOperator.LIKE: - textualValue.delete(0, 4); - break; - case SQLFilterOperator.SQLNULL: - textualValue.delete(0, 7); - break; - case SQLFilterOperator.NOT_SQLNULL: - textualValue.delete(0, 11); - break; - } - structuredFilter[i][j].Value = textualValue.toString().trim(); - } - } - return structuredFilter; - } - public XSingleSelectQueryComposer getQueryComposer() { return m_queryComposer; diff --git a/wizards/com/sun/star/wizards/ui/FilterComponent.java b/wizards/com/sun/star/wizards/ui/FilterComponent.java index ad1eb18ca318..b6c39fc55603 100644 --- a/wizards/com/sun/star/wizards/ui/FilterComponent.java +++ b/wizards/com/sun/star/wizards/ui/FilterComponent.java @@ -274,7 +274,7 @@ public class FilterComponent composer.getQueryComposer().appendFilterByColumn(columnSet, getfilterstate() == this.SOI_MATCHALL, nOperator); } } - filterconditions = composer.getNormalizedStructuredFilter(); + filterconditions = composer.getQueryComposer().getStructuredFilter(); int[] iduplicate = JavaTools.getDuplicateFieldIndex(filterconditions); if (iduplicate[0] != -1) { |