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:
parent
fae7a3d060
commit
1bc4a49d9b
@ -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;
|
||||
|
@ -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)
|
||||
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)
|
||||
)
|
||||
|| 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
|
||||
{
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
//........................................................................
|
||||
|
@ -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
|
||||
|
@ -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()));
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -3246,6 +3246,7 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos)
|
||||
,xConnection
|
||||
,xFormatter
|
||||
,xField
|
||||
,OUString()
|
||||
,aAppLocale
|
||||
,cDecimalSeparator
|
||||
,getParseContext());
|
||||
|
Loading…
x
Reference in New Issue
Block a user