QueryDesign: in criteria, remove column_ref when table *and* column name match

As opposed to only the column name

Change-Id: I261d13f23214f950daa55a5b63cd486e59a0e127
This commit is contained in:
Lionel Elie Mamane 2013-04-26 12:14:33 +02:00
parent fae7a3d060
commit 1bc4a49d9b
10 changed files with 72 additions and 23 deletions

View File

@ -268,7 +268,7 @@ namespace dbtools
// translate it back into a string // translate it back into a string
sTransformedText = OUString(); sTransformedText = OUString();
pParseNode->parseNodeToPredicateStr( pParseNode->parseNodeToPredicateStr(
sTransformedText, m_xConnection, m_xFormatter, _rxField, sTransformedText, m_xConnection, m_xFormatter, _rxField, OUString(),
rParseContext.getPreferredLocale(), (sal_Char)nDecSeparator, &rParseContext rParseContext.getPreferredLocale(), (sal_Char)nDecSeparator, &rParseContext
); );
_rPredicateValue = sTransformedText; _rPredicateValue = sTransformedText;

View File

@ -140,6 +140,7 @@ namespace connectivity
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection, SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection,
const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField, const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField,
const OUString &_sPredicateTableAlias,
const Locale& _rLocale, const IParseContext* _pContext, const Locale& _rLocale, const IParseContext* _pContext,
bool _bIntl, bool _bQuote, sal_Char _cDecSep, bool _bPredicate, bool _bParseToSDBC ) bool _bIntl, bool _bQuote, sal_Char _cDecSep, bool _bPredicate, bool _bParseToSDBC )
:rLocale(_rLocale) :rLocale(_rLocale)
@ -148,6 +149,7 @@ SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _r
,pSubQueryHistory( new QueryNameSet ) ,pSubQueryHistory( new QueryNameSet )
,xFormatter(_xFormatter) ,xFormatter(_xFormatter)
,xField(_xField) ,xField(_xField)
,sPredicateTableAlias(_sPredicateTableAlias)
,m_rContext( _pContext ? (const IParseContext&)(*_pContext) : (const IParseContext&)OSQLParser::s_aDefaultContext ) ,m_rContext( _pContext ? (const IParseContext&)(*_pContext) : (const IParseContext&)OSQLParser::s_aDefaultContext )
,cDecSep(_cDecSep) ,cDecSep(_cDecSep)
,bQuote(_bQuote) ,bQuote(_bQuote)
@ -215,7 +217,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString,
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToStr" ); RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToStr" );
parseNodeToStr( parseNodeToStr(
rString, _rxConnection, NULL, NULL, rString, _rxConnection, NULL, NULL, OUString(),
pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(), pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(),
pContext, _bIntl, _bQuote, '.', false, false ); pContext, _bIntl, _bQuote, '.', false, false );
} }
@ -233,7 +235,7 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString,
OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!"); OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
if (xFormatter.is()) 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< XConnection > & _rxConnection,
const Reference< XNumberFormatter > & xFormatter, const Reference< XNumberFormatter > & xFormatter,
const Reference< XPropertySet > & _xField, const Reference< XPropertySet > & _xField,
const OUString &_sPredicateTableAlias,
const ::com::sun::star::lang::Locale& rIntl, const ::com::sun::star::lang::Locale& rIntl,
sal_Char _cDec, sal_Char _cDec,
const IParseContext* pContext ) const const IParseContext* pContext ) const
@ -250,7 +253,7 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString,
OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!"); OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
if (xFormatter.is()) 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< XConnection > & _rxConnection,
const Reference< XNumberFormatter > & xFormatter, const Reference< XNumberFormatter > & xFormatter,
const Reference< XPropertySet > & _xField, const Reference< XPropertySet > & _xField,
const OUString &_sPredicateTableAlias,
const ::com::sun::star::lang::Locale& rIntl, const ::com::sun::star::lang::Locale& rIntl,
const IParseContext* pContext, const IParseContext* pContext,
bool _bIntl, bool _bIntl,
@ -277,7 +281,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString,
{ {
OSQLParseNode::impl_parseNodeToString_throw( sBuffer, OSQLParseNode::impl_parseNodeToString_throw( sBuffer,
SQLParseNodeParameter( SQLParseNodeParameter(
_rxConnection, xFormatter, _xField, rIntl, pContext, _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext,
_bIntl, _bQuote, _cDecSep, _bPredicate, _bSubstitute _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" ); RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToExecutableStatement" );
OSL_PRECOND( _rxConnection.is(), "OSQLParseNode::parseNodeToExecutableStatement: invalid connection!" ); OSL_PRECOND( _rxConnection.is(), "OSQLParseNode::parseNodeToExecutableStatement: invalid connection!" );
SQLParseNodeParameter aParseParam( _rxConnection, 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() ) if ( aParseParam.aMetaData.supportsSubqueriesInFrom() )
{ {
@ -340,7 +344,7 @@ namespace
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const 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() ) if ( isToken() )
{ {
parseLeaf(rString,rParam); parseLeaf(rString,rParam);
@ -477,10 +481,17 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const
// "currentFieldName" = // "currentFieldName" =
// but only at the very beginning of the criterion // but only at the very beginning of the criterion
// (not embedded deep in the expression). // (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; bool bFilter = false;
// retrieve the fields name // retrieve the field's name & table range
OUString aFieldName; OUString aFieldName;
try try
{ {
@ -496,21 +507,47 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const
if(pSubTree->count()) if(pSubTree->count())
{ {
const OSQLParseNode* pCol = pSubTree->m_aChildren[pSubTree->count()-1]; const OSQLParseNode* pCol = pSubTree->m_aChildren[pSubTree->count()-1];
if ( ( SQL_ISRULE(pCol,column_val) if (SQL_ISRULE(pCol,column_val))
&& pCol->getChild(0)->getTokenValue().equalsIgnoreAsciiCase(aFieldName) {
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)
) )
|| pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName) bFilter = true;
)
bFilter = sal_True;
} }
// ok we found the field, if the following node is the
// comparision operator '=' we filter it as well
if (bFilter) if (bFilter)
{ {
// skip field
++i;
// if the following node is the comparision operator'=',
// we filter it as well
if (SQL_ISRULE(this, comparison_predicate)) if (SQL_ISRULE(this, comparison_predicate))
{ {
++i;
if(i != m_aChildren.end()) if(i != m_aChildren.end())
{ {
pSubTree = *i; pSubTree = *i;
@ -518,8 +555,6 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const
++i; ++i;
} }
} }
else
++i;
} }
else else
{ {

View File

@ -71,9 +71,11 @@ namespace connectivity
//---------------------------------------------------------------- //----------------------------------------------------------------
void OSimpleParseNode::parseNodeToPredicateStr(OUString& _rString, const Reference< XConnection >& _rxConnection, void OSimpleParseNode::parseNodeToPredicateStr(OUString& _rString, const Reference< XConnection >& _rxConnection,
const Reference< XNumberFormatter >& _rxFormatter, const Reference< XPropertySet >& _rxField, const Reference< XNumberFormatter >& _rxFormatter, const Reference< XPropertySet >& _rxField,
const OUString &_sPredicateTableAlias,
const Locale& _rIntl, const sal_Char _cDecSeparator,const IParseContext* _pContext) const 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 );
} }
//........................................................................ //........................................................................

View File

@ -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::sdbc::XConnection >& _rxConnection,
const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 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 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
const OUString &_sPredicateTableAlias,
const ::com::sun::star::lang::Locale& _rIntl, const ::com::sun::star::lang::Locale& _rIntl,
const sal_Char _cDecSeparator, const sal_Char _cDecSeparator,
const IParseContext* _pContext const IParseContext* _pContext

View File

@ -1118,6 +1118,7 @@ sal_Bool OSelectionBrowseBox::SaveModified()
xConnection, xConnection,
static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(), static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
xColumn, xColumn,
pEntry->GetAlias(),
getDesignView()->getLocale(), getDesignView()->getLocale(),
static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()), static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()),
&(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext())); &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext()));
@ -1157,6 +1158,7 @@ sal_Bool OSelectionBrowseBox::SaveModified()
xConnection, xConnection,
static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(), static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
xColumn, xColumn,
pEntry->GetAlias(),
getDesignView()->getLocale(), getDesignView()->getLocale(),
static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()), static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()),
&(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext())); &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext()));

View File

@ -82,6 +82,7 @@ namespace connectivity
::boost::shared_ptr< QueryNameSet > pSubQueryHistory; ::boost::shared_ptr< QueryNameSet > pSubQueryHistory;
::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > xFormatter; ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > xFormatter;
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField; ::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 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xQueries; // see bParseToSDBCLevel
const IParseContext& m_rContext; const IParseContext& m_rContext;
sal_Char cDecSep; 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::sdbc::XConnection >& _rxConnection,
const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _xFormatter, 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 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xField,
const OUString &_sPredicateTableAlias,
const ::com::sun::star::lang::Locale& _rLocale, const ::com::sun::star::lang::Locale& _rLocale,
const IParseContext* _pContext, const IParseContext* _pContext,
bool _bIntl, 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::sdbc::XConnection >& _rxConnection,
const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter, 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 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _xField,
const OUString &_sTableAlias,
const ::com::sun::star::lang::Locale& rIntl, const ::com::sun::star::lang::Locale& rIntl,
sal_Char _cDec, sal_Char _cDec,
const IParseContext* pContext = NULL ) const; 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::sdbc::XConnection >& _rxConnection,
const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter, 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 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _xField,
const OUString &_sPredicateTableAlias,
const ::com::sun::star::lang::Locale& rIntl, const ::com::sun::star::lang::Locale& rIntl,
const IParseContext* pContext, const IParseContext* pContext,
bool _bIntl, bool _bIntl,

View File

@ -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::sdbc::XConnection >& _rxConnection,
const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, 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 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField,
const OUString &_sPredicateTableAlias,
const ::com::sun::star::lang::Locale& _rIntl, const ::com::sun::star::lang::Locale& _rIntl,
const sal_Char _cDecSeparator, const sal_Char _cDecSeparator,
const IParseContext* _pContext const IParseContext* _pContext

View File

@ -2985,7 +2985,10 @@ sal_Bool DbFilterField::commitControl()
xParseNode->parseNodeToPredicateStr(aPreparedText, xParseNode->parseNodeToPredicateStr(aPreparedText,
xConnection, xConnection,
xNumberFormatter, xNumberFormatter,
m_rColumn.GetField(),aAppLocale,'.', m_rColumn.GetField(),
OUString(),
aAppLocale,
'.',
getParseContext()); getParseContext());
m_aText = aPreparedText; m_aText = aPreparedText;
} }

View File

@ -903,7 +903,7 @@ sal_Bool FmFilterModel::ValidateText(FmFilterItem* pItem, OUString& rText, OUStr
OUString aPreparedText; OUString aPreparedText;
Locale aAppLocale = Application::GetSettings().GetUILanguageTag().getLocale(); Locale aAppLocale = Application::GetSettings().GetUILanguageTag().getLocale();
xParseNode->parseNodeToPredicateStr( xParseNode->parseNodeToPredicateStr(
aPreparedText, xConnection, xFormatter, xField, aAppLocale, '.', getParseContext() ); aPreparedText, xConnection, xFormatter, xField, OUString(), aAppLocale, '.', getParseContext() );
rText = aPreparedText; rText = aPreparedText;
return sal_True; return sal_True;
} }

View File

@ -3246,6 +3246,7 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos)
,xConnection ,xConnection
,xFormatter ,xFormatter
,xField ,xField
,OUString()
,aAppLocale ,aAppLocale
,cDecimalSeparator ,cDecimalSeparator
,getParseContext()); ,getParseContext());