summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2013-04-26 12:14:33 +0200
committerLionel Elie Mamane <lionel@mamane.lu>2013-04-26 16:49:48 +0200
commit1bc4a49d9ba99ff0531bafc2cf0183f726bfe14b (patch)
treeb980c3c940e1d7c233e2c6d19da7cd7d55b5ad1a /connectivity
parentfae7a3d060664e6540dbdfc3babd54ac9ccb45bf (diff)
QueryDesign: in criteria, remove column_ref when table *and* column name match
As opposed to only the column name Change-Id: I261d13f23214f950daa55a5b63cd486e59a0e127
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/commontools/predicateinput.cxx2
-rw-r--r--connectivity/source/parse/sqlnode.cxx73
-rw-r--r--connectivity/source/simpledbt/parsenode_s.cxx4
-rw-r--r--connectivity/source/simpledbt/parsenode_s.hxx1
4 files changed, 59 insertions, 21 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