Commits

Anonymous committed 7d547dd Merge

sb140: merged in DEV300_m104

Comments (0)

Files changed (549)

 564e24baaaae5e18c8bfa76811993fbefa571b5c DEV300_m101
 7dbaa615ad894cfd4f9611e82783250bd0a3016d DEV300_m102
 1bdfec44e7ce902365aa7d9cb632f0adeb86262e DEV300_m103
+21b3740610dc90f5298f3bea070153020f3db8b8 DEV300_m104

Module_ooo.mk

File contents unchanged.

Repository.mk

File contents unchanged.

connectivity/inc/connectivity/predicateinput.hxx

 			::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,
 			sal_Unicode& _rDecSep,
 			sal_Unicode& _rThdSep
 		) const;
+
+        ::rtl::OUString implParseNode(::connectivity::OSQLParseNode* pParseNode,sal_Bool _bForStatementUse) const;
 	};
 
 //.........................................................................

connectivity/inc/connectivity/sqlnode.hxx

 {
     class OUStringBuffer;
 }
+#define ORDER_BY_CHILD_POS  5
+#define TABLE_EXPRESSION_CHILD_COUNT    9
 
 namespace connectivity
 {
             character_string_type,
             other_like_predicate_part_2,
             between_predicate_part_2,
-			cast_spec,
+            cast_spec,
             rule_count,             // letzter_wert
             UNKNOWN_RULE            // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID)
 		};

connectivity/qa/connectivity/tools/CRMDatabase.java

     // --------------------------------------------------------------------------------------------------------
     private void validateUnparseable()
     {
+    /*
         // The "unparseable" query should be indeed be unparseable by OOo (though a valid HSQL query)
         XSingleSelectQueryComposer composer;
         QueryDefinition unparseableQuery;
 
         if ( !caughtExpected )
             throw new RuntimeException( "Somebody improved the parser! This is bad :), since we need an unparsable query here!" );
+            */
     }
 
     // --------------------------------------------------------------------------------------------------------
 
         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();
     }
 }

connectivity/source/commontools/FValue.cxx

 
 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
 {
-	if(m_eTypeKind != _rRH.m_eTypeKind)
-		return false;
-	if ( m_bSigned != _rRH.m_bSigned )
-		return false;
-	if(m_bNull != _rRH.isNull())
-		return false;
+	if ( m_eTypeKind != _rRH.m_eTypeKind )
+    {
+        switch(m_eTypeKind)
+        {
+            case DataType::FLOAT:
+            case DataType::DOUBLE:
+            case DataType::REAL:
+                return getDouble() == _rRH.getDouble();
+            default:
+                switch(_rRH.m_eTypeKind)
+                {
+                    case DataType::FLOAT:
+                    case DataType::DOUBLE:
+                    case DataType::REAL:
+                            return getDouble() == _rRH.getDouble();
+                    default:
+                            break;
+                }
+                break;
+            }
+        return false;
+    }
+    if ( m_bNull != _rRH.isNull() )
+            return false;
 	if(m_bNull && _rRH.isNull())
 		return true;
 
 	{
 		case DataType::VARCHAR:
 		case DataType::CHAR:
-		case DataType::DECIMAL:
-		case DataType::NUMERIC:
 		case DataType::LONGVARCHAR:
 		{
 			::rtl::OUString aVal1(m_aValue.m_pString);
 			::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
-			bRet = aVal1 == aVal2;
+			return aVal1 == aVal2;
+		}
+		default:
+			if ( m_bSigned != _rRH.m_bSigned )
+				return false;
 			break;
-		}
-
+	}
+	
+	switch(m_eTypeKind)
+	{
+		case DataType::DECIMAL:
+		case DataType::NUMERIC:
+			{
+				::rtl::OUString aVal1(m_aValue.m_pString);
+				::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
+				bRet = aVal1 == aVal2;
+			}
+			break;
 		case DataType::FLOAT:
 			bRet = *(float*)m_aValue.m_pValue == *(float*)_rRH.m_aValue.m_pValue;
 			break;

connectivity/source/commontools/predicateinput.cxx

 #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>
 
 //.........................................................................
 
 			::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* pColumnRef = pParseNode->getByRule(OSQLParseNode::column_ref);
+                if ( pColumnRef )
+                {
+                }
+            }
+        }
+
+        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 )
 			{
-				OSQLParseNode* pOdbcSpec = pParseNode->getByRule( OSQLParseNode::odbc_fct_spec );
-				if ( pOdbcSpec )
+				if ( _bForStatementUse )
 				{
-					if ( !_bForStatementUse )
-					{
-						if	(	( pOdbcSpec->count() >= 2 )
-							&&	( SQL_NODE_STRING == pOdbcSpec->getChild(1)->getNodeType() )
-							)
-						{
-
-							sReturn = pOdbcSpec->getChild(1)->getTokenValue();
-						}
-						else
-							OSL_ENSURE( sal_False, "OPredicateInputController::getPredicateValue: unknown/invalid structure (odbc + param use)!" );
-					}
-					else
-					{
-						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
-							);
-					}
+                    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 )
+					OSQLParseNode* pValueNode = pOdbcSpec->getChild(1);
+					if ( SQL_NODE_STRING == pValueNode->getNodeType() )
+						sReturn = pValueNode->getTokenValue();
+					else
+						pValueNode->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;
-	}
+        return sReturn;
+    }
 //.........................................................................
 }	// namespace dbtools
 //.........................................................................

connectivity/source/drivers/ado/AColumn.cxx

 				{
 					sal_Int32 nVal=0;
 					rValue >>= nVal;
-					m_aColumn.put_NumericScale((sal_Int8)nVal);
+                    if ( !m_IsCurrency )
+					    m_aColumn.put_NumericScale((sal_Int8)nVal);
 				}
 				break;
 			case PROPERTY_ID_ISNULLABLE:
 
 		DataTypeEnum eType	= m_aColumn.get_Type();
 		m_IsCurrency		= (eType == adCurrency);
+        if ( m_IsCurrency && !m_Scale)
+            m_Scale = 4;
 		m_Type				= ADOS::MapADOType2Jdbc(eType);
 
 		sal_Bool bForceTo = sal_True;

connectivity/source/drivers/ado/AConnection.cxx

 				aInfo->aSimpleType.aLocalTypeName	= ADOS::getField(pRecordset,nPos++).get_Value();
 				aInfo->aSimpleType.nMinimumScale	= ADOS::getField(pRecordset,nPos++).get_Value();
 				aInfo->aSimpleType.nMaximumScale	= ADOS::getField(pRecordset,nPos++).get_Value();
+                if ( adCurrency == aInfo->eType && !aInfo->aSimpleType.nMaximumScale)
+                {
+                    aInfo->aSimpleType.nMinimumScale = 4;
+                    aInfo->aSimpleType.nMaximumScale = 4;
+                }
 				aInfo->aSimpleType.nNumPrecRadix	= ADOS::getField(pRecordset,nPos++).get_Value();
 				// Now that we have the type info, save it
 				// in the Hashtable if we don't already have an

connectivity/source/drivers/file/fcomp.cxx

 		OSQLParseNode * pTableExp = pSQLParseNode->getChild(3);
 		DBG_ASSERT(pTableExp != NULL,"Fehler im Parse Tree");
 		DBG_ASSERT(SQL_ISRULE(pTableExp,table_exp)," Fehler im Parse Tree");
-		DBG_ASSERT(pTableExp->count() == 5,"Fehler im Parse Tree");
+		DBG_ASSERT(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"Fehler im Parse Tree");
 
 		// check that we don't use anything other than count(*) as function
 		OSQLParseNode* pSelection = pSQLParseNode->getChild(2);
 
 
 		pWhereClause	= pTableExp->getChild(1);
-		pOrderbyClause	= pTableExp->getChild(4);
+		pOrderbyClause	= pTableExp->getChild(ORDER_BY_CHILD_POS);
 	}
 	else if (SQL_ISRULE(pSQLParseNode,update_statement_searched))
 	{

connectivity/source/drivers/macab/MacabRecord.cxx

 			result = CFStringCompare(
 				(CFStringRef) _field1->value,
 				(CFStringRef) _field2->value,
-				0); // 0 = no options (like ignore case)
+				kCFCompareLocalized); // Specifies that the comparison should take into account differences related to locale, such as the thousands separator character.
 			break;
 
 		case kABDateProperty:

connectivity/source/parse/PColumn.cxx

         _rxResMetaData->isCurrency( _nColumnPos ),
         _rxDBMetaData->supportsMixedCaseQuotedIdentifiers()
     );
-    pColumn->setTableName(  ::dbtools::composeTableName( _rxDBMetaData,
-        _rxResMetaData->getCatalogName( _nColumnPos ),
-        _rxResMetaData->getSchemaName( _nColumnPos ),
-        _rxResMetaData->getTableName( _nColumnPos ),
-        sal_False,
-        eComplete
-    ) );
+    const ::rtl::OUString sTableName = _rxResMetaData->getTableName( _nColumnPos );
+    if ( sTableName.getLength() )
+        pColumn->setTableName(  ::dbtools::composeTableName( _rxDBMetaData,
+            _rxResMetaData->getCatalogName( _nColumnPos ),
+            _rxResMetaData->getSchemaName( _nColumnPos ),
+            sTableName,
+            sal_False,
+            eComplete
+        ) );
     pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
     pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
     pColumn->setLabel(sLabel);

connectivity/source/parse/sqlbison.y

 %token <pParseNode> SQL_TOKEN_VALUE SQL_TOKEN_CURRENT_CATALOG SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP SQL_TOKEN_CURRENT_PATH SQL_TOKEN_CURRENT_ROLE SQL_TOKEN_CURRENT_SCHEMA SQL_TOKEN_CURRENT_USER
 %token <pParseNode> SQL_TOKEN_SESSION_USER SQL_TOKEN_SYSTEM_USER SQL_TOKEN_VARCHAR SQL_TOKEN_VARBINARY SQL_TOKEN_VARYING SQL_TOKEN_OBJECT SQL_TOKEN_NCLOB SQL_TOKEN_NATIONAL
 %token <pParseNode> SQL_TOKEN_LARGE SQL_TOKEN_CLOB SQL_TOKEN_BLOB SQL_TOKEN_BIGINT SQL_TOKEN_BINARY SQL_TOKEN_WITHOUT SQL_TOKEN_BOOLEAN SQL_TOKEN_INTERVAL
+// window function
+%token <pParseNode> SQL_TOKEN_OVER SQL_TOKEN_ROW_NUMBER SQL_TOKEN_NTILE SQL_TOKEN_LEAD SQL_TOKEN_LAG SQL_TOKEN_RESPECT SQL_TOKEN_IGNORE SQL_TOKEN_NULLS 
+%token <pParseNode> SQL_TOKEN_FIRST_VALUE SQL_TOKEN_LAST_VALUE SQL_TOKEN_NTH_VALUE SQL_TOKEN_FIRST SQL_TOKEN_LAST
+%token <pParseNode> SQL_TOKEN_EXCLUDE SQL_TOKEN_OTHERS SQL_TOKEN_TIES SQL_TOKEN_FOLLOWING SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING SQL_TOKEN_RANGE SQL_TOKEN_ROWS
+%token <pParseNode> SQL_TOKEN_PARTITION SQL_TOKEN_WINDOW SQL_TOKEN_NO
+// LIMIT and OFFSEt
+%token <pParseNode> SQL_TOKEN_LIMIT SQL_TOKEN_OFFSET SQL_TOKEN_NEXT SQL_TOKEN_ONLY
+
 	/* operators */
 %left SQL_TOKEN_NAME
 %left <pParseNode> SQL_TOKEN_OR
 %type <pParseNode> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist
 %type <pParseNode> /*bit_concatenation*/ bit_value_exp bit_factor bit_primary collate_clause char_value_fct unique_spec value_exp_commalist in_predicate_value unique_test update_source 
 %type <pParseNode> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument
-%type <pParseNode> date_function_0Argument date_function_1Argument function_name12 function_name23 function_name1 function_name2 function_name3 function_name0 numeric_function_0Argument numeric_function_1Argument numeric_function_2Argument date_function_3Argument
+%type <pParseNode> date_function_0Argument date_function_1Argument function_name12 function_name23 function_name1 function_name2 function_name3 function_name0 numeric_function_0Argument numeric_function_1Argument numeric_function_2Argument 
 %type <pParseNode> all query_primary sql_not for_length upper_lower comparison column_val  cross_union /*opt_schema_element_list*/
 %type <pParseNode> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist
 %type <pParseNode> column_def odbc_fct_spec	odbc_call_spec odbc_fct_type op_parameter union_statement
 %type <pParseNode> binary_string_type numeric_type boolean_type datetime_type interval_type opt_paren_precision paren_char_length opt_paren_char_large_length paren_character_large_object_length
 %type <pParseNode> large_object_length opt_multiplier character_large_object_type national_character_large_object_type binary_large_object_string_type opt_with_or_without_time_zone
 %type <pParseNode> approximate_numeric_type exact_numeric_type opt_paren_precision_scale
+/* window function rules */
+%type <pParseNode> window_function window_function_type ntile_function number_of_tiles lead_or_lag_function lead_or_lag lead_or_lag_extent offset default_expression null_treatment
+%type <pParseNode> first_or_last_value_function first_or_last_value nth_value_function nth_row from_first_or_last window_name_or_specification in_line_window_specification opt_lead_or_lag_function
+%type <pParseNode> opt_null_treatment opt_from_first_or_last simple_value_specification dynamic_parameter_specification window_name window_clause window_definition_list window_definition
+%type <pParseNode> new_window_name window_specification_details existing_window_name window_partition_clause window_partition_column_reference_list window_partition_column_reference window_frame_clause
+%type <pParseNode> window_frame_units window_frame_extent window_frame_start window_frame_preceding window_frame_between window_frame_bound_1 window_frame_bound_2 window_frame_bound window_frame_following window_frame_exclusion
+%type <pParseNode> opt_window_frame_clause opt_window_partition_clause opt_existing_window_name window_specification opt_window_frame_exclusion opt_window_clause opt_offset
+%type <pParseNode> opt_fetch_first_row_count fetch_first_clause offset_row_count fetch_first_row_count first_or_next row_or_rows opt_result_offset_clause result_offset_clause
+/* LIMIT and OFFSET */
+%type <pParseNode> opt_limit_offset_clause limit_offset_clause opt_fetch_first_clause
 %%
 
 /* Parse Tree an OSQLParser zurueckliefern
 		}
 	|	scalar_exp_commalist
 	;
+opt_result_offset_clause:
+		/* empty */ {$$ = SQL_NEW_RULE;}
+	|	result_offset_clause
+	;	
+result_offset_clause:
+	SQL_TOKEN_OFFSET offset_row_count row_or_rows
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+		$$->append($3);
+	}
+	;
+opt_fetch_first_row_count:
+		/* empty */ {$$ = SQL_NEW_RULE;}
+	|	fetch_first_row_count
+	;
+first_or_next:
+		SQL_TOKEN_FIRST 
+	|	SQL_TOKEN_NEXT
+	;
+row_or_rows:
+		SQL_TOKEN_ROW 
+	|	SQL_TOKEN_ROWS
+	;
+opt_fetch_first_clause:
+		/* empty */ {$$ = SQL_NEW_RULE;}
+	|	fetch_first_clause
+	;
+fetch_first_clause:
+	SQL_TOKEN_FETCH first_or_next opt_fetch_first_row_count row_or_rows SQL_TOKEN_ONLY
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+		$$->append($3);
+		$$->append($4);
+		$$->append($5);
+	}
+	;
+offset_row_count:
+	literal
+	;
+fetch_first_row_count:
+	literal
+	;
 
+opt_limit_offset_clause:
+		/* empty */ {$$ = SQL_NEW_RULE;}
+	|	limit_offset_clause
+	;
+opt_offset:
+		/* empty */ {$$ = SQL_NEW_RULE;}
+	|	SQL_TOKEN_OFFSET SQL_TOKEN_INTNUM
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+	}
+	;
+limit_offset_clause:
+	SQL_TOKEN_LIMIT SQL_TOKEN_INTNUM opt_offset
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+		$$->append($3);
+	}
+	;
 table_exp:
-		from_clause
-		opt_where_clause
-		opt_group_by_clause
-		opt_having_clause
-		opt_order_by_clause
-			{$$ = SQL_NEW_RULE;
+		from_clause opt_where_clause opt_group_by_clause opt_having_clause opt_window_clause opt_order_by_clause opt_limit_offset_clause opt_result_offset_clause opt_fetch_first_clause
+		{
+			$$ = SQL_NEW_RULE;
 			$$->append($1);
 			$$->append($2);
 			$$->append($3);
 			$$->append($4);
-			$$->append($5);}
+			$$->append($5);
+			$$->append($6);
+			$$->append($7);
+			$$->append($8);
+			$$->append($9);
+		}
 	;
 
 from_clause:
 	;
 function_name23:
 		SQL_TOKEN_LOCATE
+	|	SQL_TOKEN_DATEDIFF
 	;
 function_name3:
 		string_function_3Argument
-	|	date_function_3Argument
 	;
 function_name:
 		string_function
 	|	SQL_TOKEN_TIMEVALUE
 	|	SQL_TOKEN_DATEVALUE
 	;
-date_function_3Argument:
-	SQL_TOKEN_DATEDIFF
 	
 date_function:
 		SQL_TOKEN_TIMESTAMPADD        
 		SQL_TOKEN_RAND            
 	|	SQL_TOKEN_TRUNCATE
 	;
+	
+window_function:
+	window_function_type SQL_TOKEN_OVER window_name_or_specification
+	{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+			$$->append($3);
+	}
+	;
+window_function_type :
+		rank_function_type '(' ')'
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
+			$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
+		}
+	|	SQL_TOKEN_ROW_NUMBER '(' ')'
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
+			$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
+		}
+	| general_set_fct
+	| ntile_function
+	| lead_or_lag_function
+	| first_or_last_value_function
+	| nth_value_function
+;
+ntile_function :
+	SQL_TOKEN_NTILE '(' number_of_tiles ')'
+	{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
+			$$->append($3);
+			$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
+	}
+	;
+dynamic_parameter_specification:
+	parameter
+	;
+simple_value_specification:
+	literal
+	;
+number_of_tiles :
+		simple_value_specification
+	|	dynamic_parameter_specification
+	;
+opt_lead_or_lag_function:
+	/* empty */      {$$ = SQL_NEW_RULE;}
+	| ',' offset 
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1 = newNode(",", SQL_NODE_PUNCTUATION));
+			$$->append($2);
+		}
+	| ',' offset ',' default_expression
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1 = newNode(",", SQL_NODE_PUNCTUATION));
+			$$->append($2);
+			$$->append($3 = newNode(",", SQL_NODE_PUNCTUATION));
+			$$->append($4);
+		}
+	;
+opt_null_treatment:
+		/* empty */      {$$ = SQL_NEW_RULE;}
+	|	null_treatment
+	;
+	
+lead_or_lag_function:
+	lead_or_lag '(' lead_or_lag_extent opt_lead_or_lag_function ')'	opt_null_treatment
+	{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
+			$$->append($3);
+			$$->append($4);
+			$$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
+			$$->append($6);
+	}
+	;
+lead_or_lag:
+		SQL_TOKEN_LEAD 
+	|	SQL_TOKEN_LAG
+	;
+lead_or_lag_extent:
+	value_exp
+	;
+offset:
+	SQL_TOKEN_INTNUM
+	;
+default_expression:
+	value_exp
+	;
+null_treatment:
+		SQL_TOKEN_RESPECT SQL_TOKEN_NULLS 
+	|	SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
+	;
+first_or_last_value_function:
+	first_or_last_value '(' value_exp ')' opt_null_treatment
+	{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
+			$$->append($3);
+			$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
+			$$->append($5);
+	}
+	;
+first_or_last_value :
+		SQL_TOKEN_FIRST_VALUE 
+	|	SQL_TOKEN_LAST_VALUE
+	;
+opt_from_first_or_last:
+		/* empty */      {$$ = SQL_NEW_RULE;}
+	|	from_first_or_last
+	;
+nth_value_function:
+	SQL_TOKEN_NTH_VALUE '(' value_exp ',' nth_row ')' opt_from_first_or_last opt_null_treatment
+	{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
+			$$->append($3);
+			$$->append($4 = newNode(",", SQL_NODE_PUNCTUATION));
+			$$->append($5);
+			$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
+			$$->append($7);
+			$$->append($8);
+	}
+	;
+nth_row:
+		simple_value_specification
+	|	dynamic_parameter_specification
+	;
+from_first_or_last:
+		SQL_TOKEN_FROM SQL_TOKEN_FIRST
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+		}
+	|	SQL_TOKEN_FROM SQL_TOKEN_LAST
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+		}
+	;
+window_name:
+	SQL_TOKEN_NAME
+	;
+window_name_or_specification:
+		window_name
+	|	in_line_window_specification
+	;
+in_line_window_specification: 
+	window_specification
+	;
+opt_window_clause:
+		/* empty */      {$$ = SQL_NEW_RULE;}
+	|	window_clause
+	;
+window_clause:
+	SQL_TOKEN_WINDOW window_definition_list
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+	}
+	;
+window_definition_list:
+		window_definition_list ',' window_definition
+			{$1->append($3);
+			$$ = $1;}
+	|	window_definition
+			{$$ = SQL_NEW_COMMALISTRULE;
+			$$->append($1);}
+	;
+window_definition:
+	new_window_name SQL_TOKEN_AS window_specification
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+		$$->append($3);
+	}
+	;
+new_window_name:
+	window_name
+	;
+window_specification:
+	'(' window_specification_details ')'
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
+		$$->append($2);
+		$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
+	}
+	;
+opt_existing_window_name:
+		/* empty */      {$$ = SQL_NEW_RULE;}
+	|	existing_window_name
+	;
+opt_window_partition_clause:	
+	/* empty */      {$$ = SQL_NEW_RULE;}
+	|	window_partition_clause
+	;
+opt_window_frame_clause:	
+	/* empty */      {$$ = SQL_NEW_RULE;}
+	|	window_frame_clause
+	;
+window_specification_details:
+	opt_existing_window_name
+	opt_window_partition_clause
+	opt_order_by_clause
+	opt_window_frame_clause
+	;
+existing_window_name:
+	window_name
+	;
+window_partition_clause:
+	SQL_TOKEN_PARTITION SQL_TOKEN_BY window_partition_column_reference_list
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+		$$->append($3);
+	}
+	;
+window_partition_column_reference_list:
+	window_partition_column_reference_list ',' window_partition_column_reference
+			{$1->append($3);
+			$$ = $1;}
+	|	window_partition_column_reference
+			{$$ = SQL_NEW_COMMALISTRULE;
+			$$->append($1);}
+	;
+window_partition_column_reference:
+	column_ref opt_collate_clause
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+	}
+	;
+opt_window_frame_exclusion:
+	/* empty */      {$$ = SQL_NEW_RULE;}
+	|	window_frame_exclusion
+	;
+window_frame_clause:
+	window_frame_units window_frame_extent opt_window_frame_exclusion
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+		$$->append($3);
+	}	
+	;
+window_frame_units:
+		SQL_TOKEN_ROWS
+	|	SQL_TOKEN_RANGE
+	;
+window_frame_extent:
+		window_frame_start
+	|	window_frame_between
+	;
+window_frame_start:
+		SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+		}	
+	|	window_frame_preceding
+	|	SQL_TOKEN_CURRENT SQL_TOKEN_ROW
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+		}	
+	;
+window_frame_preceding:
+	unsigned_value_spec SQL_TOKEN_PRECEDING
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+	}
+	;
+window_frame_between:
+	SQL_TOKEN_BETWEEN window_frame_bound_1 SQL_TOKEN_AND window_frame_bound_2
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+		$$->append($3);
+		$$->append($4);
+	}
+	;
+window_frame_bound_1:
+	window_frame_bound
+	;
+window_frame_bound_2:
+	window_frame_bound
+	;
+window_frame_bound:
+	window_frame_start
+	| SQL_TOKEN_UNBOUNDED SQL_TOKEN_FOLLOWING
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+	}
+	| window_frame_following
+	;
+window_frame_following:
+	unsigned_value_spec SQL_TOKEN_FOLLOWING
+	{
+		$$ = SQL_NEW_RULE;
+		$$->append($1);
+		$$->append($2);
+	}
+	;
+window_frame_exclusion:
+		SQL_TOKEN_EXCLUDE SQL_TOKEN_CURRENT SQL_TOKEN_ROW
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+			$$->append($3);
+		}
+	|	SQL_TOKEN_EXCLUDE SQL_TOKEN_GROUP
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+		}
+	|	SQL_TOKEN_EXCLUDE SQL_TOKEN_TIES
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+		}
+	|	SQL_TOKEN_EXCLUDE SQL_TOKEN_NO SQL_TOKEN_OTHERS
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+			$$->append($3);
+		}
+	;
 op_parameter:
 		{$$ = SQL_NEW_RULE;}
 	|	'?' SQL_EQUAL
 			$$->append($1);
 			$$->append($2);
 		}
+	|	SQL_TOKEN_FN set_fct_spec
+		{
+			$$ = SQL_NEW_RULE;
+			$$->append($1);
+			$$->append($2);
+		}
 	;
 
 odbc_fct_type:
-		SQL_TOKEN_FN
-	| 	SQL_TOKEN_D
+		SQL_TOKEN_D
 	| 	SQL_TOKEN_T
 	| 	SQL_TOKEN_TS
 	;
 	  | set_fct_spec
 	  | scalar_subquery
 	  | case_expression
+	  | window_function
 	  | '(' value_exp ')'
 		{
 			$$ = SQL_NEW_RULE;

connectivity/source/parse/sqlflex.l

 EVERY               {SQL_NEW_KEYWORD(SQL_TOKEN_EVERY);  }
 ESCAPE				{SQL_NEW_KEYWORD(SQL_TOKEN_ESCAPE);  }
 EXCEPT				{SQL_NEW_KEYWORD(SQL_TOKEN_EXCEPT);  }
+EXCLUDE				{SQL_NEW_KEYWORD(SQL_TOKEN_EXCLUDE);  }	
 EXISTS				{SQL_NEW_KEYWORD(SQL_TOKEN_EXISTS);  }
 EXP					{SQL_NEW_KEYWORD(SQL_TOKEN_EXP);  }
 EXTRACT				{SQL_NEW_KEYWORD(SQL_TOKEN_EXTRACT);  }
 
 FALSE				{SQL_NEW_KEYWORD(SQL_TOKEN_FALSE);  }
 FETCH				{SQL_NEW_KEYWORD(SQL_TOKEN_FETCH);  }
+FIRST				{SQL_NEW_KEYWORD(SQL_TOKEN_FIRST);  }
+FIRST_VALUE			{SQL_NEW_KEYWORD(SQL_TOKEN_FIRST_VALUE);  }
 FLOAT				{SQL_NEW_KEYWORD(SQL_TOKEN_FLOAT);  }
 FLOOR				{SQL_NEW_KEYWORD(SQL_TOKEN_FLOOR);  }
 FN					{SQL_NEW_KEYWORD(SQL_TOKEN_FN);  }
+FOLLOWING			{SQL_NEW_KEYWORD(SQL_TOKEN_FOLLOWING);  }
 FOR					{SQL_NEW_KEYWORD(SQL_TOKEN_FOR);  }
 FOREIGN				{SQL_NEW_KEYWORD(SQL_TOKEN_FOREIGN);  }
 FOUND				{SQL_NEW_KEYWORD(SQL_TOKEN_FOUND);  }
 HAVING				{SQL_NEW_KEYWORD(SQL_TOKEN_HAVING);  }
 HOUR				{SQL_NEW_KEYWORD(SQL_TOKEN_HOUR);  }
 
+IGNORE				{SQL_NEW_KEYWORD(SQL_TOKEN_IGNORE);  }
 IN					{SQL_NEW_KEYWORD(SQL_TOKEN_IN);  }
 INNER				{SQL_NEW_KEYWORD(SQL_TOKEN_INNER);  }
 INSERT				{SQL_NEW_KEYWORD(SQL_TOKEN_INSERT);  }
 
 KEY					{SQL_NEW_KEYWORD(SQL_TOKEN_KEY);  }
 
+LAG					{SQL_NEW_KEYWORD(SQL_TOKEN_LAG);  }
 LARGE				{SQL_NEW_KEYWORD(SQL_TOKEN_LARGE);  }
+LAST				{SQL_NEW_KEYWORD(SQL_TOKEN_LAST);  }
+LAST_VALUE			{SQL_NEW_KEYWORD(SQL_TOKEN_LAST_VALUE);  }
 LCASE				{SQL_NEW_KEYWORD(SQL_TOKEN_LCASE);  }
+LEAD				{SQL_NEW_KEYWORD(SQL_TOKEN_LEAD);  }
 LEADING				{SQL_NEW_KEYWORD(SQL_TOKEN_LEADING);  }
 LEFT				{SQL_NEW_KEYWORD(SQL_TOKEN_LEFT);  }
 LENGTH				{SQL_NEW_KEYWORD(SQL_TOKEN_LENGTH);  }
 LIKE				{SQL_NEW_KEYWORD(SQL_TOKEN_LIKE);  }
+LIMIT				{SQL_NEW_KEYWORD(SQL_TOKEN_LIMIT);  }
 LN					{SQL_NEW_KEYWORD(SQL_TOKEN_LN);  }
 LOCAL				{SQL_NEW_KEYWORD(SQL_TOKEN_LOCAL);  }
 LOCATE				{SQL_NEW_KEYWORD(SQL_TOKEN_LOCATE);  }
 NCHAR				{SQL_NEW_KEYWORD(SQL_TOKEN_NCHAR);  }
 NCLOB				{SQL_NEW_KEYWORD(SQL_TOKEN_NCLOB);  }
 NEW					{SQL_NEW_KEYWORD(SQL_TOKEN_NEW);  }
+NEXT				{SQL_NEW_KEYWORD(SQL_TOKEN_NEXT);  }
+NO					{SQL_NEW_KEYWORD(SQL_TOKEN_NO);  }
 NOT					{SQL_NEW_KEYWORD(SQL_TOKEN_NOT);  }
 NOW					{SQL_NEW_KEYWORD(SQL_TOKEN_NOW);  }
+NTH_VALUE			{SQL_NEW_KEYWORD(SQL_TOKEN_NTH_VALUE);  }
+NTILE				{SQL_NEW_KEYWORD(SQL_TOKEN_NTILE);  }
 NULL				{SQL_NEW_KEYWORD(SQL_TOKEN_NULL);  }
 NULLIF				{SQL_NEW_KEYWORD(SQL_TOKEN_NULLIF);  }
+NULLS				{SQL_NEW_KEYWORD(SQL_TOKEN_NULLS);  }
 NUMERIC				{SQL_NEW_KEYWORD(SQL_TOKEN_NUMERIC);  }
 
 OBJECT				{SQL_NEW_KEYWORD(SQL_TOKEN_OBJECT);  }
 OCTET_LENGTH		{SQL_NEW_KEYWORD(SQL_TOKEN_OCTET_LENGTH);  }
 OF					{SQL_NEW_KEYWORD(SQL_TOKEN_OF);  }
+OFFSET				{SQL_NEW_KEYWORD(SQL_TOKEN_OFFSET);  }
 OJ					{SQL_NEW_KEYWORD(SQL_TOKEN_OJ);  }
 OLD					{SQL_NEW_KEYWORD(SQL_TOKEN_OLD);  }
 ON					{SQL_NEW_KEYWORD(SQL_TOKEN_ON);  }
+ONLY				{SQL_NEW_KEYWORD(SQL_TOKEN_ONLY);  }
 OPTION				{SQL_NEW_KEYWORD(SQL_TOKEN_OPTION);  }
 OR					{SQL_NEW_KEYWORD(SQL_TOKEN_OR);  }
 ORDER				{SQL_NEW_KEYWORD(SQL_TOKEN_ORDER);  }
+OTHERS				{SQL_NEW_KEYWORD(SQL_TOKEN_OTHERS);  }
 OUTER				{SQL_NEW_KEYWORD(SQL_TOKEN_OUTER);  }
+OVER				{SQL_NEW_KEYWORD(SQL_TOKEN_OVER);  }
 
+PARTITION			{SQL_NEW_KEYWORD(SQL_TOKEN_PARTITION);  }
 PERCENT_RANK		{SQL_NEW_KEYWORD(SQL_TOKEN_PERCENT_RANK);  }
 PERCENTILE_CONT		{SQL_NEW_KEYWORD(SQL_TOKEN_PERCENTILE_CONT);  }
 PERCENTILE_DISC		{SQL_NEW_KEYWORD(SQL_TOKEN_PERCENTILE_DISC);  }
 PI					{SQL_NEW_KEYWORD(SQL_TOKEN_PI);  }
 POSITION	        {SQL_NEW_KEYWORD(SQL_TOKEN_POSITION);  }
 POWER				{SQL_NEW_KEYWORD(SQL_TOKEN_POWER);  }
+PRECEDING           {SQL_NEW_KEYWORD(SQL_TOKEN_PRECEDING);  }
 PRECISION           {SQL_NEW_KEYWORD(SQL_TOKEN_PRECISION);  }
 PRIMARY				{SQL_NEW_KEYWORD(SQL_TOKEN_PRIMARY);  }
 PRIVILEGES			{SQL_NEW_KEYWORD(SQL_TOKEN_PRIVILEGES);  }
 
 RADIANS				{SQL_NEW_KEYWORD(SQL_TOKEN_RADIANS);  }
 RAND				{SQL_NEW_KEYWORD(SQL_TOKEN_RAND);  }
+RANGE				{SQL_NEW_KEYWORD(SQL_TOKEN_RANGE);  }
 RANK				{SQL_NEW_KEYWORD(SQL_TOKEN_RANK);  }
 REAL				{SQL_NEW_KEYWORD(SQL_TOKEN_REAL);  }
 REFERENCES			{SQL_NEW_KEYWORD(SQL_TOKEN_REFERENCES);  }
 REFERENCING			{SQL_NEW_KEYWORD(SQL_TOKEN_REFERENCING);  }
 REPEAT				{SQL_NEW_KEYWORD(SQL_TOKEN_REPEAT);  }
 REPLACE				{SQL_NEW_KEYWORD(SQL_TOKEN_REPLACE);  }
+RESPECT				{SQL_NEW_KEYWORD(SQL_TOKEN_RESPECT);  }
 ROLLBACK            {SQL_NEW_KEYWORD(SQL_TOKEN_ROLLBACK);  }
 ROUND			    {SQL_NEW_KEYWORD(SQL_TOKEN_ROUND);  }
 ROUNDMAGIC			{SQL_NEW_KEYWORD(SQL_TOKEN_ROUNDMAGIC);  }
 ROW					{SQL_NEW_KEYWORD(SQL_TOKEN_ROW);  }
+ROWS					{SQL_NEW_KEYWORD(SQL_TOKEN_ROWS);  }
+ROW_NUMBER			{SQL_NEW_KEYWORD(SQL_TOKEN_ROW_NUMBER);  }
 RIGHT				{SQL_NEW_KEYWORD(SQL_TOKEN_RIGHT);  }
 RTRIM				{SQL_NEW_KEYWORD(SQL_TOKEN_RTRIM);  }
 
 TABLE				{SQL_NEW_KEYWORD(SQL_TOKEN_TABLE);  }
 TAN					{SQL_NEW_KEYWORD(SQL_TOKEN_TAN);  }
 THEN				{SQL_NEW_KEYWORD(SQL_TOKEN_THEN);  }
+TIES				{SQL_NEW_KEYWORD(SQL_TOKEN_TIES);  }
 TIME				{SQL_NEW_KEYWORD(SQL_TOKEN_TIME);  }
 TIMESTAMP			{SQL_NEW_KEYWORD(SQL_TOKEN_TIMESTAMP);  }
 TIMESTAMPADD		{SQL_NEW_KEYWORD(SQL_TOKEN_TIMESTAMPADD);  }
 T					{SQL_NEW_KEYWORD(SQL_TOKEN_T);  }
 
 UCASE				{SQL_NEW_KEYWORD(SQL_TOKEN_UCASE);  }
+UNBOUNDED			{SQL_NEW_KEYWORD(SQL_TOKEN_UNBOUNDED);  }
 UNION				{SQL_NEW_KEYWORD(SQL_TOKEN_UNION);  }
 UNIQUE				{SQL_NEW_KEYWORD(SQL_TOKEN_UNIQUE);  }
 UNKNOWN				{SQL_NEW_KEYWORD(SQL_TOKEN_UNKNOWN);  }

connectivity/source/parse/sqliterator.cxx

 	OSQLParseNode * pTableExp = pSelectNode->getChild(3);
 	OSL_ENSURE(pTableExp != NULL,"OSQLParseTreeIterator: error in parse tree!");
 	OSL_ENSURE(SQL_ISRULE(pTableExp,table_exp),"OSQLParseTreeIterator:table_exp error in parse tree!");
-	OSL_ENSURE(pTableExp->count() == 5,"OSQLParseTreeIterator: error in parse tree!");
+	OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator: error in parse tree!");
 
-	sal_uInt32 nPos = ( _bOrder ? 4 : 2 );
+	sal_uInt32 nPos = ( _bOrder ? ORDER_BY_CHILD_POS : 2 );
 
 	OSQLParseNode * pOptByClause = pTableExp->getChild(nPos);
 	OSL_ENSURE(pOptByClause != NULL,"OSQLParseTreeIterator: error in parse tree!");
 		OSQLParseNode * pTableExp = pSelectNode->getChild(3);
 		OSL_ENSURE(pTableExp != NULL,"OSQLParseTreeIterator: error in parse tree!");
 		OSL_ENSURE(SQL_ISRULE(pTableExp,table_exp),"OSQLParseTreeIterator: error in parse tree!");
-		OSL_ENSURE(pTableExp->count() == 5,"OSQLParseTreeIterator: error in parse tree!");
+		OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator: error in parse tree!");
 
 		pWhereClause = pTableExp->getChild(1);
 	} else if (SQL_ISRULE(pSelectNode,update_statement_searched)) {
 }
 //-----------------------------------------------------------------------------
 void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode
-											  ,const OSQLParseNode* _pColumnRef
+											  ,const OSQLParseNode* _pParentNode
 											  ,const ::rtl::OUString& _aColumnName
 											  ,const ::rtl::OUString& _aTableRange
 											  ,const ::rtl::OUString& _rColumnAlias)
 	}
 
 	// found a parameter
-	if ( _pColumnRef && (SQL_ISRULE(_pColumnRef,general_set_fct) || SQL_ISRULE(_pColumnRef,set_fct_spec)) )
+	if ( _pParentNode && (SQL_ISRULE(_pParentNode,general_set_fct) || SQL_ISRULE(_pParentNode,set_fct_spec)) )
 	{// found a function as column_ref
 		::rtl::OUString sFunctionName;
-		_pColumnRef->getChild(0)->parseNodeToStr( sFunctionName, m_pImpl->m_xConnection, NULL, sal_False, sal_False );
-        const sal_uInt32 nCount = _pColumnRef->count();
+		_pParentNode->getChild(0)->parseNodeToStr( sFunctionName, m_pImpl->m_xConnection, NULL, sal_False, sal_False );
+        const sal_uInt32 nCount = _pParentNode->count();
         sal_uInt32 i = 0;
         for(; i < nCount;++i)
         {
-            if ( _pColumnRef->getChild(i) == _pParseNode )
+            if ( _pParentNode->getChild(i) == _pParseNode )
                 break;
         }
-        sal_Int32 nType = ::connectivity::OSQLParser::getFunctionParameterType( _pColumnRef->getParent()->getChild(0)->getTokenID(), i+1);
+        sal_Int32 nType = ::connectivity::OSQLParser::getFunctionParameterType( _pParentNode->getChild(0)->getTokenID(), i-1);
 
 		OParseColumn* pColumn = new OParseColumn(	sParameterName,
 													::rtl::OUString(),
 		if ( bNotFound )
 		{
             sal_Int32 nType = DataType::VARCHAR;
-            OSQLParseNode* pParent = _pColumnRef ? _pColumnRef->getParent() : NULL;
+            OSQLParseNode* pParent = _pParentNode ? _pParentNode->getParent() : NULL;
             if ( pParent && (SQL_ISRULE(pParent,general_set_fct) || SQL_ISRULE(pParent,set_fct_spec)) )
             {
-                const sal_uInt32 nCount = _pColumnRef->count();
+                const sal_uInt32 nCount = _pParentNode->count();
                 sal_uInt32 i = 0;
                 for(; i < nCount;++i)
                 {
-                    if ( _pColumnRef->getChild(i) == _pParseNode )
+                    if ( _pParentNode->getChild(i) == _pParseNode )
                         break;
                 }
                 nType = ::connectivity::OSQLParser::getFunctionParameterType( pParent->getChild(0)->getTokenID(), i+1);
 		OSQLParseNode * pTableExp = m_pParseTree->getChild(3);
 		OSL_ENSURE(pTableExp != NULL,"OSQLParseTreeIterator: error in parse tree!");
 		OSL_ENSURE(SQL_ISRULE(pTableExp,table_exp),"OSQLParseTreeIterator: error in parse tree!");
-		OSL_ENSURE(pTableExp->count() == 5,"OSQLParseTreeIterator: error in parse tree!");
+		OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator: error in parse tree!");
 
 		pWhereClause = pTableExp->getChild(1);
 	}
 	OSQLParseNode * pTableExp = m_pParseTree->getChild(3);
 	OSL_ENSURE(pTableExp != NULL,"OSQLParseTreeIterator: error in parse tree!");
 	OSL_ENSURE(SQL_ISRULE(pTableExp,table_exp),"OSQLParseTreeIterator: error in parse tree!");
-	OSL_ENSURE(pTableExp->count() == 5,"OSQLParseTreeIterator: error in parse tree!");
+	OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator: error in parse tree!");
 
-	pOrderClause = pTableExp->getChild(4);
+	pOrderClause = pTableExp->getChild(ORDER_BY_CHILD_POS);
 	// Wenn es aber eine order_by ist, dann darf sie nicht leer sein:
 	if(pOrderClause->count() != 3)
 		pOrderClause = NULL;
 	OSQLParseNode * pTableExp = m_pParseTree->getChild(3);
 	OSL_ENSURE(pTableExp != NULL,"OSQLParseTreeIterator: error in parse tree!");
 	OSL_ENSURE(SQL_ISRULE(pTableExp,table_exp),"OSQLParseTreeIterator: error in parse tree!");
-	OSL_ENSURE(pTableExp->count() == 5,"OSQLParseTreeIterator: error in parse tree!");
+	OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator: error in parse tree!");
 
 	pGroupClause = pTableExp->getChild(2);
 	// Wenn es aber eine order_by ist, dann darf sie nicht leer sein:
 	OSQLParseNode * pTableExp = m_pParseTree->getChild(3);
 	OSL_ENSURE(pTableExp != NULL,"OSQLParseTreeIterator: error in parse tree!");
 	OSL_ENSURE(SQL_ISRULE(pTableExp,table_exp),"OSQLParseTreeIterator: error in parse tree!");
-	OSL_ENSURE(pTableExp->count() == 5,"OSQLParseTreeIterator: error in parse tree!");
+	OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator: error in parse tree!");
 
 	pHavingClause = pTableExp->getChild(3);
 	// Wenn es aber eine order_by ist, dann darf sie nicht leer sein:

connectivity/source/parse/sqlnode.cxx

             { OSQLParseNode::character_string_type, "character_string_type" },
             { OSQLParseNode::other_like_predicate_part_2, "other_like_predicate_part_2" },
             { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2" },
-			{ OSQLParseNode::cast_spec, "cast_spec" }
+            { OSQLParseNode::cast_spec, "cast_spec" }
         };
         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!" );
             if (rString.getLength())
                 rString.appendAscii(" ");
 
-            const ::rtl::OString sT = OSQLParser::TokenIDToStr(m_nNodeID, &rParam.m_rContext);