diff options
author | Ocke Janssen [oj] <Ocke.Janssen@oracle.com> | 2011-01-10 13:41:20 +0100 |
---|---|---|
committer | Ocke Janssen [oj] <Ocke.Janssen@oracle.com> | 2011-01-10 13:41:20 +0100 |
commit | 1821b0fd528c51a2f8f963a67f2e48fe457f1f27 (patch) | |
tree | 610a4ff193a8457bbe53be3e60ebca7716802254 /connectivity | |
parent | 0ca1b7ace4da7df621d38aa9df8fab3e5984577f (diff) |
dba34c: #i108415# handle structed filter handling
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/inc/connectivity/predicateinput.hxx | 8 | ||||
-rw-r--r-- | connectivity/qa/connectivity/tools/CRMDatabase.java | 5 | ||||
-rw-r--r-- | connectivity/source/commontools/predicateinput.cxx | 125 |
3 files changed, 105 insertions, 33 deletions
diff --git a/connectivity/inc/connectivity/predicateinput.hxx b/connectivity/inc/connectivity/predicateinput.hxx index 5041fd30c060..2f4dfbbd3146 100644 --- a/connectivity/inc/connectivity/predicateinput.hxx +++ b/connectivity/inc/connectivity/predicateinput.hxx @@ -104,6 +104,12 @@ namespace dbtools ::rtl::OUString* _pErrorMessage = NULL ) const; + ::rtl::OUString getPredicateValue( + const ::rtl::OUString& _sField + , const ::rtl::OUString& _rPredicateValue + , sal_Bool _bForStatementUse + , ::rtl::OUString* _pErrorMessage = NULL) const; + private: ::connectivity::OSQLParseNode* implPredicateTree( ::rtl::OUString& _rErrorMessage, @@ -116,6 +122,8 @@ namespace dbtools sal_Unicode& _rDecSep, sal_Unicode& _rThdSep ) const; + + ::rtl::OUString implParseNode(::connectivity::OSQLParseNode* pParseNode,sal_Bool _bForStatementUse) const; }; //......................................................................... diff --git a/connectivity/qa/connectivity/tools/CRMDatabase.java b/connectivity/qa/connectivity/tools/CRMDatabase.java index a1b457884948..f9b6d52a8038 100644 --- a/connectivity/qa/connectivity/tools/CRMDatabase.java +++ b/connectivity/qa/connectivity/tools/CRMDatabase.java @@ -224,6 +224,7 @@ public class CRMDatabase // -------------------------------------------------------------------------------------------------------- private void validateUnparseable() { + /* // The "unparseable" query should be indeed be unparseable by OOo (though a valid HSQL query) XSingleSelectQueryComposer composer; QueryDefinition unparseableQuery; @@ -253,6 +254,7 @@ public class CRMDatabase if ( !caughtExpected ) throw new RuntimeException( "Somebody improved the parser! This is bad :), since we need an unparsable query here!" ); + */ } // -------------------------------------------------------------------------------------------------------- @@ -284,9 +286,10 @@ public class CRMDatabase m_database.getDataSource().createQuery( "parseable", "SELECT * FROM \"customers\"" ); m_database.getDataSource().createQuery( "parseable native", "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_VIEWS", false ); +/* m_database.getDataSource().createQuery( "unparseable", "SELECT {fn DAYOFMONTH ('2001-01-01')} AS \"ID_VARCHAR\" FROM \"products\"", false ); - +*/ validateUnparseable(); } } diff --git a/connectivity/source/commontools/predicateinput.cxx b/connectivity/source/commontools/predicateinput.cxx index 73cb88b90dbf..9d088c903dcc 100644 --- a/connectivity/source/commontools/predicateinput.cxx +++ b/connectivity/source/commontools/predicateinput.cxx @@ -31,8 +31,10 @@ #include <comphelper/types.hxx> #include <connectivity/dbtools.hxx> #include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/sdbc/ColumnValue.hpp> #include <osl/diagnose.h> #include <connectivity/sqlnode.hxx> +#include <connectivity/PColumn.hxx> #include <comphelper/numbers.hxx> //......................................................................... @@ -325,54 +327,113 @@ namespace dbtools ::rtl::OUString sError; OSQLParseNode* pParseNode = implPredicateTree( sError, sValue, _rxField ); - if ( _pErrorMessage ) *_pErrorMessage = sError; + if ( _pErrorMessage ) + *_pErrorMessage = sError; - if ( pParseNode ) + sReturn = implParseNode(pParseNode,_bForStatementUse); + } + + return sReturn; + } + + ::rtl::OUString OPredicateInputController::getPredicateValue( + const ::rtl::OUString& _sField, const ::rtl::OUString& _rPredicateValue, sal_Bool _bForStatementUse, ::rtl::OUString* _pErrorMessage ) const + { + ::rtl::OUString sReturn = _rPredicateValue; + ::rtl::OUString sError; + ::rtl::OUString sField = _sField; + sal_Int32 nIndex = 0; + sField = sField.getToken(0,'(',nIndex); + if(nIndex == -1) + sField = _sField; + sal_Int32 nType = ::connectivity::OSQLParser::getFunctionReturnType(sField,&m_aParser.getContext()); + if ( nType == DataType::OTHER || !sField.getLength() ) + { + // first try the international version + ::rtl::OUString sSql; + sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT * ")); + sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM x WHERE ")); + sSql += sField; + sSql += _rPredicateValue; + ::std::auto_ptr<OSQLParseNode> pParseNode( const_cast< OSQLParser& >( m_aParser ).parseTree( sError, sSql, sal_True ) ); + nType = DataType::DOUBLE; + if ( pParseNode.get() ) { - OSQLParseNode* pOdbcSpec = pParseNode->getByRule( OSQLParseNode::odbc_fct_spec ); - if ( pOdbcSpec ) + OSQLParseNode* pColumnRef = pParseNode->getByRule(OSQLParseNode::column_ref); + if ( pColumnRef ) { - if ( _bForStatementUse ) - { - OSQLParseNode* pFuncSpecParent = pOdbcSpec->getParent(); - OSL_ENSURE( pFuncSpecParent, "OPredicateInputController::getPredicateValue: an ODBC func spec node without parent?" ); - if ( pFuncSpecParent ) - pFuncSpecParent->parseNodeToStr(sReturn, m_xConnection, &m_aParser.getContext(), sal_False, sal_True); - } - else - { - pOdbcSpec->getChild(1)->parseNodeToStr(sReturn, m_xConnection, &m_aParser.getContext(), sal_False, sal_True); - // sReturn = pOdbcSpec->getChild(1)->getTokenValue(); - } + } + } + } + + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + parse::OParseColumn* pColumn = new parse::OParseColumn( sField, + ::rtl::OUString(), + ::rtl::OUString(), + ::rtl::OUString(), + ColumnValue::NULLABLE_UNKNOWN, + 0, + 0, + nType, + sal_False, + sal_False, + xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()); + Reference<XPropertySet> xColumn = pColumn; + pColumn->setFunction(sal_True); + pColumn->setRealName(sField); + + OSQLParseNode* pParseNode = implPredicateTree( sError, _rPredicateValue, xColumn ); + if ( _pErrorMessage ) + *_pErrorMessage = sError; + return pParseNode ? implParseNode(pParseNode,_bForStatementUse) : sReturn; + } + + ::rtl::OUString OPredicateInputController::implParseNode(OSQLParseNode* pParseNode,sal_Bool _bForStatementUse) const + { + ::rtl::OUString sReturn; + if ( pParseNode ) + { + ::std::auto_ptr<OSQLParseNode> pTemp(pParseNode); + OSQLParseNode* pOdbcSpec = pParseNode->getByRule( OSQLParseNode::odbc_fct_spec ); + if ( pOdbcSpec ) + { + if ( _bForStatementUse ) + { + OSQLParseNode* pFuncSpecParent = pOdbcSpec->getParent(); + OSL_ENSURE( pFuncSpecParent, "OPredicateInputController::getPredicateValue: an ODBC func spec node without parent?" ); + if ( pFuncSpecParent ) + pFuncSpecParent->parseNodeToStr(sReturn, m_xConnection, &m_aParser.getContext(), sal_False, sal_True); } else { - if ( pParseNode->count() >= 3 ) + pOdbcSpec->getChild(1)->parseNodeToStr(sReturn, m_xConnection, &m_aParser.getContext(), sal_False, sal_True); + // sReturn = pOdbcSpec->getChild(1)->getTokenValue(); + } + } + else + { + if ( pParseNode->count() >= 3 ) + { + OSQLParseNode* pValueNode = pParseNode->getChild(2); + OSL_ENSURE( pValueNode, "OPredicateInputController::getPredicateValue: invalid node child!" ); + if ( !_bForStatementUse ) { - OSQLParseNode* pValueNode = pParseNode->getChild(2); - OSL_ENSURE( pValueNode, "OPredicateInputController::getPredicateValue: invalid node child!" ); - if ( !_bForStatementUse ) - { - if ( SQL_NODE_STRING == pValueNode->getNodeType() ) - sReturn = pValueNode->getTokenValue(); - else - pValueNode->parseNodeToStr( - sReturn, m_xConnection, &m_aParser.getContext(), sal_False, sal_True - ); - } + if ( SQL_NODE_STRING == pValueNode->getNodeType() ) + sReturn = pValueNode->getTokenValue(); else pValueNode->parseNodeToStr( sReturn, m_xConnection, &m_aParser.getContext(), sal_False, sal_True ); } else - OSL_ENSURE( sal_False, "OPredicateInputController::getPredicateValue: unknown/invalid structure (noodbc)!" ); + pValueNode->parseNodeToStr( + sReturn, m_xConnection, &m_aParser.getContext(), sal_False, sal_True + ); } - - delete pParseNode; + else + OSL_ENSURE( sal_False, "OPredicateInputController::getPredicateValue: unknown/invalid structure (noodbc)!" ); } } - return sReturn; } //......................................................................... |