diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2013-04-26 12:14:33 +0200 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2013-04-26 16:49:48 +0200 |
commit | 1bc4a49d9ba99ff0531bafc2cf0183f726bfe14b (patch) | |
tree | b980c3c940e1d7c233e2c6d19da7cd7d55b5ad1a | |
parent | fae7a3d060664e6540dbdfc3babd54ac9ccb45bf (diff) |
QueryDesign: in criteria, remove column_ref when table *and* column name match
As opposed to only the column name
Change-Id: I261d13f23214f950daa55a5b63cd486e59a0e127
-rw-r--r-- | connectivity/source/commontools/predicateinput.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/parse/sqlnode.cxx | 73 | ||||
-rw-r--r-- | connectivity/source/simpledbt/parsenode_s.cxx | 4 | ||||
-rw-r--r-- | connectivity/source/simpledbt/parsenode_s.hxx | 1 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx | 2 | ||||
-rw-r--r-- | include/connectivity/sqlnode.hxx | 4 | ||||
-rw-r--r-- | include/connectivity/virtualdbtools.hxx | 1 | ||||
-rw-r--r-- | svx/source/fmcomp/gridcell.cxx | 5 | ||||
-rw-r--r-- | svx/source/form/filtnav.cxx | 2 | ||||
-rw-r--r-- | svx/source/form/formcontroller.cxx | 1 |
10 files changed, 72 insertions, 23 deletions
diff --git a/connectivity/source/commontools/predicateinput.cxx b/connectivity/source/commontools/predicateinput.cxx index a7f8f04f2b57..bf8092fe5c24 100644 --- a/connectivity/source/commontools/predicateinput.cxx +++ b/connectivity/source/commontools/predicateinput.cxx @@ -268,7 +268,7 @@ namespace dbtools // translate it back into a string sTransformedText = OUString(); pParseNode->parseNodeToPredicateStr( - sTransformedText, m_xConnection, m_xFormatter, _rxField, + sTransformedText, m_xConnection, m_xFormatter, _rxField, OUString(), rParseContext.getPreferredLocale(), (sal_Char)nDecSeparator, &rParseContext ); _rPredicateValue = sTransformedText; diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index 779283f9b7c1..4c67ea3e65c6 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -140,6 +140,7 @@ namespace connectivity //----------------------------------------------------------------------------- SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection, const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField, + const OUString &_sPredicateTableAlias, const Locale& _rLocale, const IParseContext* _pContext, bool _bIntl, bool _bQuote, sal_Char _cDecSep, bool _bPredicate, bool _bParseToSDBC ) :rLocale(_rLocale) @@ -148,6 +149,7 @@ SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _r ,pSubQueryHistory( new QueryNameSet ) ,xFormatter(_xFormatter) ,xField(_xField) + ,sPredicateTableAlias(_sPredicateTableAlias) ,m_rContext( _pContext ? (const IParseContext&)(*_pContext) : (const IParseContext&)OSQLParser::s_aDefaultContext ) ,cDecSep(_cDecSep) ,bQuote(_bQuote) @@ -215,7 +217,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString, RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToStr" ); parseNodeToStr( - rString, _rxConnection, NULL, NULL, + rString, _rxConnection, NULL, NULL, OUString(), pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(), pContext, _bIntl, _bQuote, '.', false, false ); } @@ -233,7 +235,7 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString, OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!"); if (xFormatter.is()) - parseNodeToStr(rString, _rxConnection, xFormatter, NULL, rIntl, pContext, sal_True, sal_True, _cDec, true, false); + parseNodeToStr(rString, _rxConnection, xFormatter, NULL, OUString(), rIntl, pContext, sal_True, sal_True, _cDec, true, false); } //----------------------------------------------------------------------------- @@ -241,6 +243,7 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString, const Reference< XConnection > & _rxConnection, const Reference< XNumberFormatter > & xFormatter, const Reference< XPropertySet > & _xField, + const OUString &_sPredicateTableAlias, const ::com::sun::star::lang::Locale& rIntl, sal_Char _cDec, const IParseContext* pContext ) const @@ -250,7 +253,7 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString, OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!"); if (xFormatter.is()) - parseNodeToStr( rString, _rxConnection, xFormatter, _xField, rIntl, pContext, true, true, _cDec, true, false ); + parseNodeToStr( rString, _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, true, true, _cDec, true, false ); } //----------------------------------------------------------------------------- @@ -258,6 +261,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString, const Reference< XConnection > & _rxConnection, const Reference< XNumberFormatter > & xFormatter, const Reference< XPropertySet > & _xField, + const OUString &_sPredicateTableAlias, const ::com::sun::star::lang::Locale& rIntl, const IParseContext* pContext, bool _bIntl, @@ -277,7 +281,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString, { OSQLParseNode::impl_parseNodeToString_throw( sBuffer, SQLParseNodeParameter( - _rxConnection, xFormatter, _xField, rIntl, pContext, + _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, _bIntl, _bQuote, _cDecSep, _bPredicate, _bSubstitute ) ); } @@ -299,7 +303,7 @@ bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, cons RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToExecutableStatement" ); OSL_PRECOND( _rxConnection.is(), "OSQLParseNode::parseNodeToExecutableStatement: invalid connection!" ); SQLParseNodeParameter aParseParam( _rxConnection, - NULL, NULL, OParseContext::getDefaultLocale(), NULL, false, true, '.', false, true ); + NULL, NULL, OUString(), OParseContext::getDefaultLocale(), NULL, false, true, '.', false, true ); if ( aParseParam.aMetaData.supportsSubqueriesInFrom() ) { @@ -340,7 +344,7 @@ namespace //----------------------------------------------------------------------------- void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const { - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::getTableRange" ); + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::impl_parseNodeToString_throw" ); if ( isToken() ) { parseLeaf(rString,rParam); @@ -477,10 +481,17 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const // "currentFieldName" = // but only at the very beginning of the criterion // (not embedded deep in the expression). - if (rString.isEmpty() && rParam.xField.is() && SQL_ISRULE(pSubTree,column_ref)) + // TODO: replace "beginning of criterion" by "in simple expression", + // that is anything made of: + // - parentheses + // - logical operators (and, or, not) + // - comparison operators (IS, =, >, <, BETWEEN, LIKE, ...) + // (see where the parser calls inPredicateCheck for a full list) + // but *not* e.g. in function arguments + if (rParam.bPredicate && rString.isEmpty() && rParam.xField.is() && SQL_ISRULE(pSubTree,column_ref)) { - sal_Bool bFilter = sal_False; - // retrieve the fields name + bool bFilter = false; + // retrieve the field's name & table range OUString aFieldName; try { @@ -496,21 +507,47 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const if(pSubTree->count()) { const OSQLParseNode* pCol = pSubTree->m_aChildren[pSubTree->count()-1]; - if ( ( SQL_ISRULE(pCol,column_val) - && pCol->getChild(0)->getTokenValue().equalsIgnoreAsciiCase(aFieldName) - ) - || pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName) + if (SQL_ISRULE(pCol,column_val)) + { + assert(pCol->count() == 1); + pCol = pCol->getChild(0); + } + const OSQLParseNode* pTable(NULL); + switch (pSubTree->count()) + { + case 1: + break; + case 3: + pTable = pSubTree->m_aChildren[0]; + break; + case 5: + case 7: + SAL_WARN("connectivity.parse", "SQL: catalog and/or schema in column_ref in predicate"); + break; + default: + SAL_WARN("connectivity.parse", "impl_parseNodeToString_throw: SQL grammar changed; column_ref has " << pSubTree->count() << " children"); + assert(false); + break; + } + // TODO: not all DBMS match column names case-insensitively... + // see XDatabaseMetaData::supportsMixedCaseIdentifiers() + // and XDatabaseMetaData::supportsMixedCaseQuotedIdentifiers() + if ( // table name matches (or no table name)? + ( !pTable || pTable->getTokenValue().equalsIgnoreAsciiCase(rParam.sPredicateTableAlias) ) + && // column name matches? + pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName) ) - bFilter = sal_True; + bFilter = true; } - // ok we found the field, if the following node is the - // comparision operator '=' we filter it as well if (bFilter) { + // skip field + ++i; + // if the following node is the comparision operator'=', + // we filter it as well if (SQL_ISRULE(this, comparison_predicate)) { - ++i; if(i != m_aChildren.end()) { pSubTree = *i; @@ -518,8 +555,6 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const ++i; } } - else - ++i; } else { diff --git a/connectivity/source/simpledbt/parsenode_s.cxx b/connectivity/source/simpledbt/parsenode_s.cxx index 6887cf3c9d32..92cd3a23c212 100644 --- a/connectivity/source/simpledbt/parsenode_s.cxx +++ b/connectivity/source/simpledbt/parsenode_s.cxx @@ -71,9 +71,11 @@ namespace connectivity //---------------------------------------------------------------- void OSimpleParseNode::parseNodeToPredicateStr(OUString& _rString, const Reference< XConnection >& _rxConnection, const Reference< XNumberFormatter >& _rxFormatter, const Reference< XPropertySet >& _rxField, + const OUString &_sPredicateTableAlias, const Locale& _rIntl, const sal_Char _cDecSeparator,const IParseContext* _pContext) const { - m_pFullNode->parseNodeToPredicateStr( _rString, _rxConnection, _rxFormatter, _rxField, _rIntl, _cDecSeparator, _pContext ); + m_pFullNode->parseNodeToPredicateStr( _rString, _rxConnection, _rxFormatter, _rxField, _sPredicateTableAlias, + _rIntl, _cDecSeparator, _pContext ); } //........................................................................ diff --git a/connectivity/source/simpledbt/parsenode_s.hxx b/connectivity/source/simpledbt/parsenode_s.hxx index d8bd6f94a1c2..0166933d731d 100644 --- a/connectivity/source/simpledbt/parsenode_s.hxx +++ b/connectivity/source/simpledbt/parsenode_s.hxx @@ -54,6 +54,7 @@ namespace connectivity const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField, + const OUString &_sPredicateTableAlias, const ::com::sun::star::lang::Locale& _rIntl, const sal_Char _cDecSeparator, const IParseContext* _pContext diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index ad29c142780b..b54b3814b85e 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -1118,6 +1118,7 @@ sal_Bool OSelectionBrowseBox::SaveModified() xConnection, static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(), xColumn, + pEntry->GetAlias(), getDesignView()->getLocale(), static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()), &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext())); @@ -1157,6 +1158,7 @@ sal_Bool OSelectionBrowseBox::SaveModified() xConnection, static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(), xColumn, + pEntry->GetAlias(), getDesignView()->getLocale(), static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()), &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext())); diff --git a/include/connectivity/sqlnode.hxx b/include/connectivity/sqlnode.hxx index 940b27f25950..51a9ec2168ca 100644 --- a/include/connectivity/sqlnode.hxx +++ b/include/connectivity/sqlnode.hxx @@ -82,6 +82,7 @@ namespace connectivity ::boost::shared_ptr< QueryNameSet > pSubQueryHistory; ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > xFormatter; ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField; + OUString sPredicateTableAlias; ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xQueries; // see bParseToSDBCLevel const IParseContext& m_rContext; sal_Char cDecSep; @@ -94,6 +95,7 @@ namespace connectivity const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _xFormatter, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xField, + const OUString &_sPredicateTableAlias, const ::com::sun::star::lang::Locale& _rLocale, const IParseContext* _pContext, bool _bIntl, @@ -329,6 +331,7 @@ namespace connectivity const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _xField, + const OUString &_sTableAlias, const ::com::sun::star::lang::Locale& rIntl, sal_Char _cDec, const IParseContext* pContext = NULL ) const; @@ -410,6 +413,7 @@ namespace connectivity const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _xField, + const OUString &_sPredicateTableAlias, const ::com::sun::star::lang::Locale& rIntl, const IParseContext* pContext, bool _bIntl, diff --git a/include/connectivity/virtualdbtools.hxx b/include/connectivity/virtualdbtools.hxx index 352c98d7a8c4..9083016fa621 100644 --- a/include/connectivity/virtualdbtools.hxx +++ b/include/connectivity/virtualdbtools.hxx @@ -294,6 +294,7 @@ namespace connectivity const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField, + const OUString &_sPredicateTableAlias, const ::com::sun::star::lang::Locale& _rIntl, const sal_Char _cDecSeparator, const IParseContext* _pContext diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx index f7dcf1144d1b..22b4716829d8 100644 --- a/svx/source/fmcomp/gridcell.cxx +++ b/svx/source/fmcomp/gridcell.cxx @@ -2985,7 +2985,10 @@ sal_Bool DbFilterField::commitControl() xParseNode->parseNodeToPredicateStr(aPreparedText, xConnection, xNumberFormatter, - m_rColumn.GetField(),aAppLocale,'.', + m_rColumn.GetField(), + OUString(), + aAppLocale, + '.', getParseContext()); m_aText = aPreparedText; } diff --git a/svx/source/form/filtnav.cxx b/svx/source/form/filtnav.cxx index 9bd657063ea6..8b665eb9a508 100644 --- a/svx/source/form/filtnav.cxx +++ b/svx/source/form/filtnav.cxx @@ -903,7 +903,7 @@ sal_Bool FmFilterModel::ValidateText(FmFilterItem* pItem, OUString& rText, OUStr OUString aPreparedText; Locale aAppLocale = Application::GetSettings().GetUILanguageTag().getLocale(); xParseNode->parseNodeToPredicateStr( - aPreparedText, xConnection, xFormatter, xField, aAppLocale, '.', getParseContext() ); + aPreparedText, xConnection, xFormatter, xField, OUString(), aAppLocale, '.', getParseContext() ); rText = aPreparedText; return sal_True; } diff --git a/svx/source/form/formcontroller.cxx b/svx/source/form/formcontroller.cxx index c9fab0b9761c..313fcd84e7f2 100644 --- a/svx/source/form/formcontroller.cxx +++ b/svx/source/form/formcontroller.cxx @@ -3246,6 +3246,7 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos) ,xConnection ,xFormatter ,xField + ,OUString() ,aAppLocale ,cDecimalSeparator ,getParseContext()); |