diff options
author | Ocke Janssen <Ocke.Janssen@sun.com> | 2009-11-12 09:35:14 +0100 |
---|---|---|
committer | Ocke Janssen <Ocke.Janssen@sun.com> | 2009-11-12 09:35:14 +0100 |
commit | 8421bb9bf5894fb7043747876172a89c6e5a4820 (patch) | |
tree | d08772d5cb57743901d2502fe0efefc61cdfc44b /connectivity | |
parent | 7394a76726b564824c2671452e9a86754a9e5813 (diff) |
#i99566# type of min and max depends on the parameter
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/inc/connectivity/sqliterator.hxx | 3 | ||||
-rw-r--r-- | connectivity/inc/connectivity/sqlnode.hxx | 4 | ||||
-rw-r--r-- | connectivity/source/parse/sqliterator.cxx | 96 | ||||
-rw-r--r-- | connectivity/source/parse/sqlnode.cxx | 6 |
4 files changed, 93 insertions, 16 deletions
diff --git a/connectivity/inc/connectivity/sqliterator.hxx b/connectivity/inc/connectivity/sqliterator.hxx index ddbf3e24af3c..e8e4c8e6a6f2 100644 --- a/connectivity/inc/connectivity/sqliterator.hxx +++ b/connectivity/inc/connectivity/sqliterator.hxx @@ -279,6 +279,9 @@ namespace connectivity // return true when the tableNode is a rule like catalog_name, schema_name or table_name sal_Bool isTableNode(const OSQLParseNode* _pTableNode) const; + + // tries to find the correct type of the function + sal_Int32 getFunctionReturnType(const OSQLParseNode* _pNode ); private: /** traverses the list of table names, and filles _rTables */ diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx index 0adcae01d966..cc1b27cf4f57 100644 --- a/connectivity/inc/connectivity/sqlnode.hxx +++ b/connectivity/inc/connectivity/sqlnode.hxx @@ -225,6 +225,10 @@ namespace connectivity as, op_column_commalist, table_primary_as_range_column, + datetime_primary, + concatenation, + char_factor, + bit_value_fct, rule_count, // letzter_wert UNKNOWN_RULE // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID) }; diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx index 6b839f0116dd..e8111f174486 100644 --- a/connectivity/source/parse/sqliterator.cxx +++ b/connectivity/source/parse/sqliterator.cxx @@ -952,21 +952,7 @@ bool OSQLParseTreeIterator::traverseSelectColumnNames(const OSQLParseNode* pSele if ( pColumnRef->isRule() ) { bFkt = sal_True; - if ( SQL_ISRULE(pColumnRef,num_value_exp) || SQL_ISRULE(pColumnRef,term) || SQL_ISRULE(pColumnRef,factor) ) - { - nType = DataType::DOUBLE; - } - else - { - ::rtl::OUString sFunctionName; - if ( SQL_ISRULE(pColumnRef,length_exp) ) - pColumnRef->getChild(0)->getChild(0)->parseNodeToStr( - sFunctionName, m_pImpl->m_xConnection, NULL, sal_False, sal_False ); - else - pColumnRef->getChild(0)->parseNodeToStr( - sFunctionName, m_pImpl->m_xConnection, NULL, sal_False, sal_False ); - nType = ::connectivity::OSQLParser::getFunctionReturnType( sFunctionName, &m_rParser.getContext() ); - } + nType = getFunctionReturnType(pColumnRef); } } /* @@ -2103,3 +2089,83 @@ void OSQLParseTreeIterator::impl_appendError( const SQLException& _rError ) m_aErrors = _rError; } // ----------------------------------------------------------------------------- +sal_Int32 OSQLParseTreeIterator::getFunctionReturnType(const OSQLParseNode* _pNode ) +{ + sal_Int32 nType = DataType::OTHER; + ::rtl::OUString sFunctionName; + if ( SQL_ISRULE(_pNode,length_exp) ) + { + _pNode->getChild(0)->getChild(0)->parseNodeToStr(sFunctionName, m_pImpl->m_xConnection, NULL, sal_False, sal_False ); + nType = ::connectivity::OSQLParser::getFunctionReturnType( sFunctionName, &m_rParser.getContext() ); + } + else if ( SQL_ISRULE(_pNode,num_value_exp) || SQL_ISRULE(_pNode,term) || SQL_ISRULE(_pNode,factor) ) + { + nType = DataType::DOUBLE; + } + else + { + _pNode->getChild(0)->parseNodeToStr(sFunctionName, m_pImpl->m_xConnection, NULL, sal_False, sal_False ); + + // MIN and MAX have another return type, we have to check the expression itself. + // @see http://qa.openoffice.org/issues/show_bug.cgi?id=99566 + if ( SQL_ISRULE(_pNode,general_set_fct) && (SQL_ISTOKEN(_pNode->getChild(0),MIN) || SQL_ISTOKEN(_pNode->getChild(0),MAX) )) + { + const OSQLParseNode* pValueExp = _pNode->getChild(3); + if (SQL_ISRULE(pValueExp,column_ref)) + { + ::rtl::OUString sColumnName; + ::rtl::OUString aTableRange; + getColumnRange(pValueExp,sColumnName,aTableRange); + OSL_ENSURE(sColumnName.getLength(),"Columnname darf nicht leer sein"); + Reference<XPropertySet> xColumn = findColumn( sColumnName, aTableRange, true ); + + if ( xColumn.is() ) + { + xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_TYPE)) >>= nType; + } + } + else + { + if ( SQL_ISRULE(pValueExp,num_value_exp) || SQL_ISRULE(pValueExp,term) || SQL_ISRULE(pValueExp,factor) ) + { + nType = DataType::DOUBLE; + } + else if ( SQL_ISRULE(pValueExp,datetime_primary) ) + { + switch(pValueExp->getChild(0)->getTokenID() ) + { + case SQL_TOKEN_CURRENT_DATE: + nType = DataType::DATE; + break; + case SQL_TOKEN_CURRENT_TIME: + nType = DataType::TIME; + break; + case SQL_TOKEN_CURRENT_TIMESTAMP: + nType = DataType::TIMESTAMP; + break; + } + } + else if ( SQL_ISRULE(pValueExp,value_exp_primary) ) + { + nType = getFunctionReturnType(pValueExp->getChild(1)); + } + else if ( SQL_ISRULE(pValueExp,concatenation) + || SQL_ISRULE(pValueExp,char_factor) + || SQL_ISRULE(pValueExp,bit_value_fct) + || SQL_ISRULE(pValueExp,char_value_fct) + || SQL_ISRULE(pValueExp,char_substring_fct) + || SQL_ISRULE(pValueExp,fold) + || SQL_ISTOKEN(pValueExp,STRING) ) + { + nType = DataType::VARCHAR; + } + } + if ( nType == DataType::OTHER ) + nType = DataType::DOUBLE; + } + else + nType = ::connectivity::OSQLParser::getFunctionReturnType( sFunctionName, &m_rParser.getContext() ); + } + + return nType; +}
\ No newline at end of file diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index 8e915d8ead72..c76dd44e3d18 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -1421,7 +1421,11 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star: { OSQLParseNode::table_node, "table_node" }, { OSQLParseNode::as, "as" }, { OSQLParseNode::op_column_commalist, "op_column_commalist" }, - { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column" } + { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column" }, + { OSQLParseNode::datetime_primary, "datetime_primary" }, + { OSQLParseNode::concatenation, "concatenation" }, + { OSQLParseNode::char_factor, "char_factor" }, + { OSQLParseNode::bit_value_fct, "bit_value_fct" } }; size_t nRuleMapCount = sizeof( aRuleDescriptions ) / sizeof( aRuleDescriptions[0] ); OSL_ENSURE( nRuleMapCount == size_t( OSQLParseNode::rule_count ), "OSQLParser::OSQLParser: added a new rule? Adjust this map!" ); |