LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - QueryDesignView.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 3 1794 0.2 %
Date: 2014-11-03 Functions: 2 83 2.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "QueryDesignView.hxx"
      21             : #include "QueryTableView.hxx"
      22             : #include "QTableWindow.hxx"
      23             : #include <vcl/toolbox.hxx>
      24             : #include "querycontroller.hxx"
      25             : #include <vcl/split.hxx>
      26             : #include <svl/undo.hxx>
      27             : #include <tools/diagnose_ex.h>
      28             : #include <osl/diagnose.h>
      29             : #include "adtabdlg.hxx"
      30             : #include <vcl/svapp.hxx>
      31             : #include <vcl/combobox.hxx>
      32             : #include <vcl/msgbox.hxx>
      33             : #include <vcl/layout.hxx>
      34             : #include "browserids.hxx"
      35             : #include "SelectionBrowseBox.hxx"
      36             : #include "dbu_qry.hrc"
      37             : #include <unotools/configmgr.hxx>
      38             : #include <comphelper/extract.hxx>
      39             : #include <comphelper/string.hxx>
      40             : #include <comphelper/types.hxx>
      41             : #include <connectivity/dbtools.hxx>
      42             : #include <connectivity/dbexception.hxx>
      43             : #include <com/sun/star/i18n/XLocaleData.hpp>
      44             : #include <com/sun/star/sdbc/DataType.hpp>
      45             : #include <com/sun/star/container/XNameAccess.hpp>
      46             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      47             : #include <connectivity/PColumn.hxx>
      48             : #include "QTableConnection.hxx"
      49             : #include "ConnectionLine.hxx"
      50             : #include "ConnectionLineData.hxx"
      51             : #include "QTableConnectionData.hxx"
      52             : #include "dbustrings.hrc"
      53             : #include "UITools.hxx"
      54             : #include "querycontainerwindow.hxx"
      55             : #include "sqlmessage.hxx"
      56             : #include <unotools/syslocale.hxx>
      57             : #include <boost/scoped_ptr.hpp>
      58             : 
      59             : using namespace ::dbaui;
      60             : using namespace ::utl;
      61             : using namespace ::connectivity;
      62             : using namespace ::dbtools;
      63             : using namespace ::com::sun::star::uno;
      64             : using namespace ::com::sun::star::lang;
      65             : using namespace ::com::sun::star::i18n;
      66             : using namespace ::com::sun::star::sdbc;
      67             : using namespace ::com::sun::star::beans;
      68             : using namespace ::com::sun::star::container;
      69             : 
      70             : // here we define our functions used in the anonymous namespace to get our header file smaller
      71             : // please look at the book LargeScale C++ to know why
      72             : namespace
      73             : {
      74          24 :     static const OUString C_AND(" AND ");
      75          24 :     static const OUString C_OR(" OR ");
      76             : 
      77             :     // forward declarations
      78             :     bool InsertJoin(    const OQueryDesignView* _pView,
      79             :                             const ::connectivity::OSQLParseNode *pNode);
      80             : 
      81             :     SqlParseError InstallFields(OQueryDesignView* _pView,
      82             :                                 const ::connectivity::OSQLParseNode* pNode,
      83             :                                 OJoinTableView::OTableWindowMap* pTabList );
      84             : 
      85             :     SqlParseError GetGroupCriteria( OQueryDesignView* _pView,
      86             :                                     OSelectionBrowseBox* _pSelectionBrw,
      87             :                                     const ::connectivity::OSQLParseNode* pSelectRoot );
      88             : 
      89             :     SqlParseError GetHavingCriteria(OQueryDesignView* _pView,
      90             :                                     OSelectionBrowseBox* _pSelectionBrw,
      91             :                                     const ::connectivity::OSQLParseNode* pSelectRoot,
      92             :                                     sal_uInt16& rLevel );
      93             : 
      94             :     SqlParseError GetOrderCriteria( OQueryDesignView* _pView,
      95             :                                     OSelectionBrowseBox* _pSelectionBrw,
      96             :                                     const ::connectivity::OSQLParseNode* pParseRoot );
      97             : 
      98             :     SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
      99             :                                     OSelectionBrowseBox* _pSelectionBrw,
     100             :                                     const ::connectivity::OSQLParseNode * pCondition,
     101             :                                     const sal_uInt16 nLevel,
     102             :                                     bool bHaving,
     103             :                                     bool _bAddOrOnOneLine);
     104             : 
     105           0 :     OUString quoteTableAlias(bool _bQuote, const OUString& _sAliasName, const OUString& _sQuote)
     106             :     {
     107           0 :         OUString sRet;
     108           0 :         if ( _bQuote && !_sAliasName.isEmpty() )
     109             :         {
     110           0 :             sRet = ::dbtools::quoteName(_sQuote,_sAliasName);
     111           0 :             const static OUString sTableSeparater('.');
     112           0 :             sRet += sTableSeparater;
     113             :         }
     114           0 :         return sRet;
     115             :     }
     116           0 :     OUString getTableRange(const OQueryDesignView* _pView,const ::connectivity::OSQLParseNode* _pTableRef)
     117             :     {
     118           0 :         Reference< XConnection> xConnection = static_cast<OQueryController&>(_pView->getController()).getConnection();
     119           0 :         OUString sTableRange;
     120           0 :         if ( _pTableRef )
     121             :         {
     122           0 :             sTableRange = ::connectivity::OSQLParseNode::getTableRange(_pTableRef);
     123           0 :             if ( sTableRange.isEmpty() )
     124           0 :                 _pTableRef->parseNodeToStr(sTableRange,xConnection,NULL,false,false);
     125             :         }
     126           0 :         return sTableRange;
     127             :     }
     128           0 :     void insertConnection(const OQueryDesignView* _pView,const EJoinType& _eJoinType,OTableFieldDescRef _aDragLeft,OTableFieldDescRef _aDragRight,bool _bNatural = false)
     129             :     {
     130           0 :         OQueryTableView* pTableView = static_cast<OQueryTableView*>(_pView->getTableView());
     131           0 :         OQueryTableConnection* pConn = static_cast<OQueryTableConnection*>( pTableView->GetTabConn(static_cast<OTableWindow*>(_aDragLeft->GetTabWindow()),static_cast<OTableWindow*>(_aDragRight->GetTabWindow()),true));
     132             : 
     133           0 :         if ( !pConn )
     134             :         {
     135           0 :             OQueryTableConnectionData* pInfoData = new OQueryTableConnectionData();
     136           0 :             TTableConnectionData::value_type aInfoData(pInfoData);
     137           0 :             pInfoData->InitFromDrag(_aDragLeft, _aDragRight);
     138           0 :             pInfoData->SetJoinType(_eJoinType);
     139             : 
     140           0 :             if ( _bNatural )
     141             :             {
     142           0 :                 aInfoData->ResetConnLines();
     143           0 :                 pInfoData->setNatural(_bNatural);
     144             :                 try
     145             :                 {
     146           0 :                     Reference<XNameAccess> xReferencedTableColumns(aInfoData->getReferencedTable()->getColumns());
     147           0 :                     Sequence< OUString> aSeq = aInfoData->getReferencingTable()->getColumns()->getElementNames();
     148           0 :                     const OUString* pIter = aSeq.getConstArray();
     149           0 :                     const OUString* pEnd   = pIter + aSeq.getLength();
     150           0 :                     for(;pIter != pEnd;++pIter)
     151             :                     {
     152           0 :                         if ( xReferencedTableColumns->hasByName(*pIter) )
     153           0 :                             aInfoData->AppendConnLine(*pIter,*pIter);
     154           0 :                     }
     155             :                 }
     156           0 :                 catch( const Exception& )
     157             :                 {
     158             :                     DBG_UNHANDLED_EXCEPTION();
     159             :                 }
     160             :             }
     161             : 
     162           0 :             OQueryTableConnection aInfo(pTableView, aInfoData);
     163             :             // Because OQueryTableConnection never takes ownership of the data passed to it, but only remembers the pointer,
     164             :             // this pointer to a local variable is not critical, as aInfoData and aInfo have the same lifetime
     165           0 :             pTableView->NotifyTabConnection( aInfo );
     166             :         }
     167             :         else
     168             :         {
     169           0 :             OUString aSourceFieldName(_aDragLeft->GetField());
     170           0 :             OUString aDestFieldName(_aDragRight->GetField());
     171             :             // the connection could point on the other side
     172           0 :             if(pConn->GetSourceWin() == _aDragRight->GetTabWindow())
     173             :             {
     174           0 :                 OUString aTmp(aSourceFieldName);
     175           0 :                 aSourceFieldName = aDestFieldName;
     176           0 :                 aDestFieldName = aTmp;
     177             :             }
     178           0 :             pConn->GetData()->AppendConnLine( aSourceFieldName,aDestFieldName);
     179           0 :             pConn->UpdateLineList();
     180             :             // Modified-Flag
     181             :             //  SetModified();
     182             :             // and redraw
     183           0 :             pConn->RecalcLines();
     184             :                 // for the following Invalidate, the new Connection must first be able
     185             :                 // to determine its BoundingRect
     186           0 :             pConn->InvalidateConnection();
     187             :         }
     188           0 :     }
     189           0 :     OUString ParseCondition( OQueryController& rController
     190             :                                     ,const ::connectivity::OSQLParseNode* pCondition
     191             :                                     ,const OUString& _sDecimal
     192             :                                     ,const ::com::sun::star::lang::Locale& _rLocale
     193             :                                     ,sal_uInt32 _nStartIndex)
     194             :     {
     195           0 :         OUString aCondition;
     196           0 :         Reference< XConnection> xConnection = rController.getConnection();
     197           0 :         if ( xConnection.is() )
     198             :         {
     199           0 :             sal_uInt32 nCount = pCondition->count();
     200           0 :             for(sal_uInt32 i = _nStartIndex ; i < nCount ; ++i)
     201             :                 pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
     202             :                                 xConnection,
     203             :                                 rController.getNumberFormatter(),
     204             :                                 _rLocale,
     205           0 :                                 static_cast<sal_Char>(_sDecimal.toChar()),
     206           0 :                                 &rController.getParser().getContext());
     207             :         }
     208           0 :         return aCondition;
     209             :     }
     210           0 :     SqlParseError FillOuterJoins(OQueryDesignView* _pView,
     211             :                                 const ::connectivity::OSQLParseNode* pTableRefList)
     212             :     {
     213           0 :         SqlParseError eErrorCode = eOk;
     214           0 :         sal_uInt32 nCount = pTableRefList->count();
     215           0 :         bool bError = false;
     216           0 :         for (sal_uInt32 i=0; !bError && i < nCount; ++i)
     217             :         {
     218           0 :             const ::connectivity::OSQLParseNode* pParseNode = pTableRefList->getChild(i);
     219           0 :             const ::connectivity::OSQLParseNode* pJoinNode = NULL;
     220             : 
     221           0 :             if ( SQL_ISRULE( pParseNode, qualified_join ) || SQL_ISRULE( pParseNode, joined_table ) || SQL_ISRULE( pParseNode, cross_union ) )
     222           0 :                 pJoinNode = pParseNode;
     223           0 :             else if(    SQL_ISRULE(pParseNode,table_ref)
     224           0 :                     &&  pParseNode->count() == 4 ) // '{' SQL_TOKEN_OJ joined_table '}'
     225           0 :                 pJoinNode = pParseNode->getChild(2);
     226             : 
     227           0 :             if ( pJoinNode )
     228             :             {
     229           0 :                 if ( !InsertJoin(_pView,pJoinNode) )
     230           0 :                     bError = true;
     231             :             }
     232             :         }
     233             :         // check if error occurred
     234           0 :         if ( bError )
     235           0 :             eErrorCode = eIllegalJoin;
     236             : 
     237           0 :         return eErrorCode;
     238             :     }
     239             : 
     240             :     /** FillDragInfo fills the field description out of the table
     241             :     */
     242           0 :     SqlParseError FillDragInfo( const OQueryDesignView* _pView,
     243             :                             const ::connectivity::OSQLParseNode* pColumnRef,
     244             :                             OTableFieldDescRef& _rDragInfo)
     245             :     {
     246           0 :         SqlParseError eErrorCode = eOk;
     247             : 
     248           0 :         bool bErg = false;
     249             : 
     250           0 :         OUString aTableRange,aColumnName;
     251             :         sal_uInt16 nCntAccount;
     252           0 :         ::connectivity::OSQLParseTreeIterator& rParseIter = static_cast<OQueryController&>(_pView->getController()).getParseIterator();
     253           0 :         rParseIter.getColumnRange( pColumnRef, aColumnName, aTableRange );
     254             : 
     255           0 :         if ( !aTableRange.isEmpty() )
     256             :         {
     257           0 :             OQueryTableWindow*  pSTW = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( aTableRange );
     258           0 :             bErg = (pSTW && pSTW->ExistsField( aColumnName, _rDragInfo ) );
     259             :         }
     260           0 :         if ( !bErg )
     261             :         {
     262           0 :             bErg = static_cast<OQueryTableView*>(_pView->getTableView())->FindTableFromField(aColumnName, _rDragInfo, nCntAccount);
     263           0 :             if ( !bErg )
     264           0 :                 bErg = _pView->HasFieldByAliasName(aColumnName, _rDragInfo);
     265             :         }
     266           0 :         if ( !bErg )
     267             :         {
     268           0 :             eErrorCode = eColumnNotFound;
     269           0 :             OUString sError(ModuleRes(STR_QRY_COLUMN_NOT_FOUND));
     270           0 :             sError = sError.replaceFirst("$name$",aColumnName);
     271           0 :             _pView->getController().appendError( sError );
     272             : 
     273             :             try
     274             :             {
     275           0 :                 Reference<XDatabaseMetaData> xMeta = _pView->getController().getConnection()->getMetaData();
     276           0 :                 if ( xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers() )
     277           0 :                     _pView->getController().appendError( OUString( ModuleRes( STR_QRY_CHECK_CASESENSITIVE ) ) );
     278             :             }
     279           0 :             catch(Exception&)
     280             :             {
     281           0 :             }
     282             :         }
     283             : 
     284           0 :         return eErrorCode;
     285             :     }
     286           0 :     OUString BuildJoinCriteria(  const Reference< XConnection>& _xConnection,
     287             :                                         const OConnectionLineDataVec* pLineDataList,
     288             :                                         const OQueryTableConnectionData* pData)
     289             :     {
     290           0 :         OUStringBuffer aCondition;
     291           0 :         if ( _xConnection.is() )
     292             :         {
     293           0 :             OConnectionLineDataVec::const_iterator aIter = pLineDataList->begin();
     294           0 :             OConnectionLineDataVec::const_iterator aEnd = pLineDataList->end();
     295             :             try
     296             :             {
     297           0 :                 const Reference< XDatabaseMetaData >  xMetaData = _xConnection->getMetaData();
     298           0 :                 const OUString aQuote = xMetaData->getIdentifierQuoteString();
     299           0 :                 const OUString sEqual(" = ");
     300             : 
     301           0 :                 for(;aIter != aEnd;++aIter)
     302             :                 {
     303           0 :                     OConnectionLineDataRef pLineData = *aIter;
     304           0 :                     if(!aCondition.isEmpty())
     305           0 :                         aCondition.append(C_AND);
     306           0 :                     aCondition.append(quoteTableAlias(true,pData->GetAliasName(JTCS_FROM),aQuote));
     307           0 :                     aCondition.append(::dbtools::quoteName(aQuote, pLineData->GetFieldName(JTCS_FROM) ));
     308           0 :                     aCondition.append(sEqual);
     309           0 :                     aCondition.append(quoteTableAlias(true,pData->GetAliasName(JTCS_TO),aQuote));
     310           0 :                     aCondition.append(::dbtools::quoteName(aQuote, pLineData->GetFieldName(JTCS_TO) ));
     311           0 :                 }
     312             :             }
     313           0 :             catch(SQLException&)
     314             :             {
     315             :                 OSL_FAIL("Failure while building Join criteria!");
     316             :             }
     317             :         }
     318             : 
     319           0 :         return aCondition.makeStringAndClear();
     320             :     }
     321             :     /** JoinCycle looks for a join cycle and append it to the string
     322             :         @param  _xConnection    the connection
     323             :         @param  _pEntryConn     the table connection which holds the data
     324             :         @param  _pEntryTabTo    the corresponding table window
     325             :         @param  _rJoin          the String which will contain the resulting string
     326             :     */
     327           0 :     void JoinCycle( const Reference< XConnection>& _xConnection,
     328             :                     OQueryTableConnection* _pEntryConn,
     329             :                     const OQueryTableWindow* _pEntryTabTo,
     330             :                     OUString& _rJoin )
     331             :     {
     332             :         OSL_ENSURE(_pEntryConn,"TableConnection can not be null!");
     333             : 
     334           0 :         OQueryTableConnectionData* pData = static_cast< OQueryTableConnectionData*>(_pEntryConn->GetData().get());
     335           0 :         if ( pData->GetJoinType() != INNER_JOIN && _pEntryTabTo->ExistsAVisitedConn() )
     336             :         {
     337           0 :             bool bBrace = false;
     338           0 :             if(_rJoin.endsWith(")"))
     339             :             {
     340           0 :                 bBrace = true;
     341           0 :                 _rJoin = _rJoin.replaceAt(_rJoin.getLength()-1,1,OUString(' '));
     342             :             }
     343           0 :             (_rJoin += C_AND) += BuildJoinCriteria(_xConnection,&pData->GetConnLineDataList(),pData);
     344           0 :             if(bBrace)
     345           0 :                 _rJoin += ")";
     346           0 :             _pEntryConn->SetVisited(true);
     347             :         }
     348           0 :     }
     349           0 :     OUString BuildTable( const Reference< XConnection>& _xConnection,
     350             :                                 const OQueryTableWindow* pEntryTab,
     351             :                                 bool _bForce = false
     352             :                                 )
     353             :     {
     354           0 :         OUString aDBName(pEntryTab->GetComposedName());
     355             : 
     356           0 :         if( _xConnection.is() )
     357             :         {
     358             :             try
     359             :             {
     360           0 :                 Reference< XDatabaseMetaData >  xMetaData = _xConnection->getMetaData();
     361             : 
     362           0 :                 OUString sCatalog, sSchema, sTable;
     363           0 :                 ::dbtools::qualifiedNameComponents( xMetaData, aDBName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
     364           0 :                 OUString aTableListStr = ::dbtools::composeTableNameForSelect( _xConnection, sCatalog, sSchema, sTable );
     365             : 
     366           0 :                 OUString aQuote = xMetaData->getIdentifierQuoteString();
     367           0 :                 if ( _bForce || isAppendTableAliasEnabled( _xConnection ) || pEntryTab->GetAliasName() != aDBName )
     368             :                 {
     369           0 :                     aTableListStr += " ";
     370           0 :                     if ( generateAsBeforeTableAlias( _xConnection ) )
     371           0 :                         aTableListStr += "AS ";
     372           0 :                     aTableListStr += ::dbtools::quoteName( aQuote, pEntryTab->GetAliasName() );
     373             :                 }
     374           0 :                 aDBName = aTableListStr;
     375             :             }
     376           0 :             catch(const SQLException&)
     377             :             {
     378             :                 DBG_UNHANDLED_EXCEPTION();
     379             :             }
     380             :         }
     381           0 :         return aDBName;
     382             :     }
     383           0 :     OUString BuildJoin(  const Reference< XConnection>& _xConnection,
     384             :                                 const OUString& rLh,
     385             :                                 const OUString& rRh,
     386             :                                 const OQueryTableConnectionData* pData)
     387             :     {
     388             : 
     389           0 :         OUString aErg(rLh);
     390           0 :         if ( pData->isNatural() && pData->GetJoinType() != CROSS_JOIN )
     391           0 :             aErg += " NATURAL ";
     392           0 :         switch(pData->GetJoinType())
     393             :         {
     394             :             case LEFT_JOIN:
     395           0 :                 aErg += " LEFT OUTER ";
     396           0 :                 break;
     397             :             case RIGHT_JOIN:
     398           0 :                 aErg += " RIGHT OUTER ";
     399           0 :                 break;
     400             :             case CROSS_JOIN:
     401             :                 OSL_ENSURE(!pData->isNatural(),"OQueryDesignView::BuildJoin: This should not happen!");
     402           0 :                 aErg += " CROSS ";
     403           0 :                 break;
     404             :             case INNER_JOIN:
     405             :                 OSL_ENSURE(pData->isNatural(),"OQueryDesignView::BuildJoin: This should not happen!");
     406           0 :                 aErg += " INNER ";
     407           0 :                 break;
     408             :             default:
     409           0 :                 aErg += " FULL OUTER ";
     410           0 :                 break;
     411             :         }
     412           0 :         aErg += "JOIN ";
     413           0 :         aErg += rRh;
     414           0 :         if ( CROSS_JOIN != pData->GetJoinType() && !pData->isNatural() )
     415             :         {
     416           0 :             aErg += " ON ";
     417           0 :             aErg += BuildJoinCriteria(_xConnection,&pData->GetConnLineDataList(),pData);
     418             :         }
     419             : 
     420           0 :         return aErg;
     421             :     }
     422           0 :     OUString BuildJoin(  const Reference< XConnection>& _xConnection,
     423             :                                 const OQueryTableWindow* pLh,
     424             :                                 const OQueryTableWindow* pRh,
     425             :                                 const OQueryTableConnectionData* pData
     426             :                                 )
     427             :     {
     428           0 :         bool bForce = pData->GetJoinType() == CROSS_JOIN || pData->isNatural();
     429           0 :         return BuildJoin(_xConnection,BuildTable(_xConnection,pLh,bForce),BuildTable(_xConnection,pRh,bForce),pData);
     430             :     }
     431           0 :     OUString BuildJoin(  const Reference< XConnection>& _xConnection,
     432             :                                 const OUString &rLh,
     433             :                                 const OQueryTableWindow* pRh,
     434             :                                 const OQueryTableConnectionData* pData
     435             :                                 )
     436             :     {
     437           0 :         return BuildJoin(_xConnection,rLh,BuildTable(_xConnection,pRh),pData);
     438             :     }
     439           0 :     OUString BuildJoin(  const Reference< XConnection>& _xConnection,
     440             :                                 const OQueryTableWindow* pLh,
     441             :                                 const OUString &rRh,
     442             :                                 const OQueryTableConnectionData* pData
     443             :                                 )
     444             :     {
     445             :         // strict ANSI SQL:
     446             :         // - does not support any bracketing of JOINS
     447             :         // - supports nested joins only in the LEFT HAND SIDE
     448             :         // In this case, we are trying to build a join with a nested join
     449             :         // in the right hand side.
     450             :         // So switch the direction of the join and both hand sides.
     451           0 :         OQueryTableConnectionData data(*pData);
     452           0 :         switch (data.GetJoinType())
     453             :         {
     454             :         case LEFT_JOIN:
     455           0 :             data.SetJoinType(RIGHT_JOIN);
     456           0 :             break;
     457             :         case RIGHT_JOIN:
     458           0 :             data.SetJoinType(LEFT_JOIN);
     459           0 :             break;
     460             :         default:
     461             :             // the other join types are symmetric, so nothing to change
     462           0 :             break;
     463             :         }
     464           0 :         return BuildJoin(_xConnection, rRh, BuildTable(_xConnection,pLh), &data);
     465             :     }
     466             :     typedef ::std::map< OUString,sal_Bool,::comphelper::UStringMixLess> tableNames_t;
     467           0 :     void addConnectionTableNames( const Reference< XConnection>& _xConnection,
     468             :                                   const OQueryTableConnection* const pEntryConn,
     469             :                                   tableNames_t &_rTableNames )
     470             :     {
     471             :             // insert tables into table list to avoid double entries
     472           0 :             const OQueryTableWindow* const pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
     473           0 :             const OQueryTableWindow* const pEntryTabTo = static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin());
     474             : 
     475           0 :             OUString sTabName(BuildTable(_xConnection,pEntryTabFrom));
     476           0 :             if(_rTableNames.find(sTabName) == _rTableNames.end())
     477           0 :                 _rTableNames[sTabName] = sal_True;
     478           0 :             sTabName = BuildTable(_xConnection,pEntryTabTo);
     479           0 :             if(_rTableNames.find(sTabName) == _rTableNames.end())
     480           0 :                 _rTableNames[sTabName] = sal_True;
     481           0 :     }
     482           0 :     void GetNextJoin(   const Reference< XConnection>& _xConnection,
     483             :                         OQueryTableConnection* pEntryConn,
     484             :                         OQueryTableWindow* pEntryTabTo,
     485             :                         OUString &aJoin,
     486             :                         tableNames_t &_rTableNames)
     487             :     {
     488           0 :         OQueryTableConnectionData* pEntryConnData = static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get());
     489           0 :         if ( pEntryConnData->GetJoinType() == INNER_JOIN && !pEntryConnData->isNatural() )
     490           0 :             return;
     491             : 
     492           0 :         if(aJoin.isEmpty())
     493             :         {
     494           0 :             addConnectionTableNames(_xConnection, pEntryConn, _rTableNames);
     495           0 :             OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
     496           0 :             aJoin = BuildJoin(_xConnection,pEntryTabFrom,pEntryTabTo,pEntryConnData);
     497             :         }
     498           0 :         else if(pEntryTabTo == pEntryConn->GetDestWin())
     499             :         {
     500           0 :             addConnectionTableNames(_xConnection, pEntryConn, _rTableNames);
     501           0 :             aJoin = BuildJoin(_xConnection,aJoin,pEntryTabTo,pEntryConnData);
     502             :         }
     503           0 :         else if(pEntryTabTo == pEntryConn->GetSourceWin())
     504             :         {
     505           0 :             addConnectionTableNames(_xConnection, pEntryConn, _rTableNames);
     506           0 :             aJoin = BuildJoin(_xConnection,pEntryTabTo,aJoin,pEntryConnData);
     507             :         }
     508             : 
     509           0 :         pEntryConn->SetVisited(true);
     510             : 
     511             :         // first search for the "to" window
     512           0 :         const ::std::vector<OTableConnection*>& rConnections = pEntryConn->GetParent()->getTableConnections();
     513           0 :         ::std::vector<OTableConnection*>::const_iterator aIter = rConnections.begin();
     514           0 :         ::std::vector<OTableConnection*>::const_iterator aEnd = rConnections.end();
     515           0 :         for(;aIter != aEnd;++aIter)
     516             :         {
     517           0 :             OQueryTableConnection* pNext = static_cast<OQueryTableConnection*>(*aIter);
     518           0 :             if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabTo || pNext->GetDestWin() == pEntryTabTo))
     519             :             {
     520           0 :                 OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabTo ? static_cast<OQueryTableWindow*>(pNext->GetDestWin()) : static_cast<OQueryTableWindow*>(pNext->GetSourceWin());
     521             :                 // exists there a connection to a OQueryTableWindow that holds a connection that has been already visited
     522           0 :                 JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
     523           0 :                 if(!pNext->IsVisited())
     524           0 :                     GetNextJoin(_xConnection, pNext, pEntryTab, aJoin, _rTableNames);
     525             :             }
     526             :         }
     527             : 
     528             :         // when nothing found found look for the "from" window
     529           0 :         if(aIter == aEnd)
     530             :         {
     531           0 :             OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
     532           0 :             aIter = rConnections.begin();
     533           0 :             for(;aIter != aEnd;++aIter)
     534             :             {
     535           0 :                 OQueryTableConnection* pNext = static_cast<OQueryTableConnection*>(*aIter);
     536           0 :                 if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabFrom || pNext->GetDestWin() == pEntryTabFrom))
     537             :                 {
     538           0 :                     OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabFrom ? static_cast<OQueryTableWindow*>(pNext->GetDestWin()) : static_cast<OQueryTableWindow*>(pNext->GetSourceWin());
     539             :                     // exists there a connection to a OQueryTableWindow that holds a connection that has been already visited
     540           0 :                     JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
     541           0 :                     if(!pNext->IsVisited())
     542           0 :                         GetNextJoin(_xConnection, pNext, pEntryTab, aJoin, _rTableNames);
     543             :                 }
     544             :             }
     545             :         }
     546             :     }
     547           0 :     SqlParseError InsertJoinConnection( const OQueryDesignView* _pView,
     548             :                                     const ::connectivity::OSQLParseNode *pNode,
     549             :                                     const EJoinType& _eJoinType,
     550             :                                     const ::connectivity::OSQLParseNode *pLeftTable,
     551             :                                     const ::connectivity::OSQLParseNode *pRightTable)
     552             :     {
     553           0 :         SqlParseError eErrorCode = eOk;
     554           0 :         if (pNode->count() == 3 &&  // statement between brackets
     555           0 :             SQL_ISPUNCTUATION(pNode->getChild(0),"(") &&
     556           0 :             SQL_ISPUNCTUATION(pNode->getChild(2),")"))
     557             :         {
     558           0 :             eErrorCode = InsertJoinConnection(_pView,pNode->getChild(1), _eJoinType,pLeftTable,pRightTable);
     559             :         }
     560           0 :         else if (SQL_ISRULEOR2(pNode,search_condition,boolean_term) &&          // AND/OR-joints:
     561           0 :                  pNode->count() == 3)
     562             :         {
     563             :             // only allow AND joints
     564           0 :             if (!SQL_ISTOKEN(pNode->getChild(1),AND))
     565           0 :                 eErrorCode = eIllegalJoinCondition;
     566           0 :             else if ( eOk == (eErrorCode = InsertJoinConnection(_pView,pNode->getChild(0), _eJoinType,pLeftTable,pRightTable)) )
     567           0 :                     eErrorCode = InsertJoinConnection(_pView,pNode->getChild(2), _eJoinType,pLeftTable,pRightTable);
     568             :         }
     569           0 :         else if (SQL_ISRULE(pNode,comparison_predicate))
     570             :         {
     571             :             // only the comparison of columns is allowed
     572             :             OSL_ENSURE(pNode->count() == 3,"OQueryDesignView::InsertJoinConnection: Error in Parse Tree");
     573           0 :             if (!(SQL_ISRULE(pNode->getChild(0),column_ref) &&
     574           0 :                   SQL_ISRULE(pNode->getChild(2),column_ref) &&
     575           0 :                    pNode->getChild(1)->getNodeType() == SQL_NODE_EQUAL))
     576             :             {
     577           0 :                 OUString sError(ModuleRes(STR_QRY_JOIN_COLUMN_COMPARE));
     578           0 :                 _pView->getController().appendError( sError );
     579           0 :                 return eIllegalJoin;
     580             :             }
     581             : 
     582           0 :             OTableFieldDescRef aDragLeft  = new OTableFieldDesc();
     583           0 :             OTableFieldDescRef aDragRight = new OTableFieldDesc();
     584           0 :             if ( eOk != ( eErrorCode = FillDragInfo(_pView,pNode->getChild(0),aDragLeft)) ||
     585           0 :                 eOk != ( eErrorCode = FillDragInfo(_pView,pNode->getChild(2),aDragRight)))
     586           0 :                 return eErrorCode;
     587             : 
     588           0 :             if ( pLeftTable )
     589             :             {
     590           0 :                 OQueryTableWindow*  pLeftWindow = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( getTableRange(_pView,pLeftTable->getByRule(OSQLParseNode::table_ref) ));
     591           0 :                 if ( pLeftWindow == aDragLeft->GetTabWindow() )
     592           0 :                     insertConnection(_pView,_eJoinType,aDragLeft,aDragRight);
     593             :                 else
     594           0 :                     insertConnection(_pView,_eJoinType,aDragRight,aDragLeft);
     595             :             }
     596             :             else
     597           0 :                 insertConnection(_pView,_eJoinType,aDragLeft,aDragRight);
     598             :         }
     599             :         else
     600           0 :             eErrorCode = eIllegalJoin;
     601           0 :         return eErrorCode;
     602             :     }
     603           0 :     bool GetInnerJoinCriteria(  const OQueryDesignView* _pView,
     604             :                                     const ::connectivity::OSQLParseNode *pCondition)
     605             :     {
     606           0 :         return InsertJoinConnection(_pView,pCondition, INNER_JOIN,NULL,NULL) != eOk;
     607             :     }
     608           0 :     OUString GenerateSelectList( const OQueryDesignView* _pView,
     609             :                                         OTableFields&   _rFieldList,
     610             :                                         bool bAlias)
     611             :     {
     612           0 :         Reference< XConnection> xConnection = static_cast<OQueryController&>(_pView->getController()).getConnection();
     613           0 :         if ( !xConnection.is() )
     614           0 :             return OUString();
     615             : 
     616           0 :         OUStringBuffer aTmpStr,aFieldListStr;
     617             : 
     618           0 :         bool bAsterisk = false;
     619           0 :         int nVis = 0;
     620           0 :         OTableFields::iterator aIter = _rFieldList.begin();
     621           0 :         OTableFields::iterator aEnd = _rFieldList.end();
     622           0 :         for(;aIter != aEnd;++aIter)
     623             :         {
     624           0 :             OTableFieldDescRef pEntryField = *aIter;
     625           0 :             if ( pEntryField->IsVisible() )
     626             :             {
     627           0 :                 if ( pEntryField->GetField().toChar() == '*' )
     628           0 :                     bAsterisk = true;
     629           0 :                 ++nVis;
     630             :             }
     631           0 :         }
     632           0 :         if(nVis == 1)
     633           0 :             bAsterisk = false;
     634             : 
     635             :         try
     636             :         {
     637           0 :             const Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
     638           0 :             const OUString aQuote = xMetaData->getIdentifierQuoteString();
     639             : 
     640           0 :             OJoinTableView::OTableWindowMap& rTabList = _pView->getTableView()->GetTabWinMap();
     641             : 
     642           0 :             const static OUString sFieldSeparator(", ");
     643           0 :             const static OUString s_sAs(" AS ");
     644             : 
     645           0 :             aIter = _rFieldList.begin();
     646           0 :             for(;aIter != aEnd;++aIter)
     647             :             {
     648           0 :                 OTableFieldDescRef pEntryField = *aIter;
     649           0 :                 OUString rFieldName = pEntryField->GetField();
     650           0 :                 if ( !rFieldName.isEmpty() && pEntryField->IsVisible() )
     651             :                 {
     652           0 :                     aTmpStr = "";
     653           0 :                     const OUString rAlias = pEntryField->GetAlias();
     654           0 :                     const OUString rFieldAlias = pEntryField->GetFieldAlias();
     655             : 
     656           0 :                     aTmpStr.append(quoteTableAlias((bAlias || bAsterisk),rAlias,aQuote));
     657             : 
     658             :                     // if we have a none numeric field, the table alias could be in the name
     659             :                     // otherwise we are not allowed to do this (e.g. 0.1 * PRICE )
     660           0 :                     if  ( !pEntryField->isOtherFunction() )
     661             :                     {
     662             :                         // we have to look if we have alias.* here but before we have to check if the column doesn't already exist
     663           0 :                         OTableFieldDescRef  aInfo = new OTableFieldDesc();
     664           0 :                         OJoinTableView::OTableWindowMap::iterator tableIter = rTabList.begin();
     665           0 :                         OJoinTableView::OTableWindowMap::iterator tableEnd = rTabList.end();
     666           0 :                         bool bFound = false;
     667           0 :                         for(;!bFound && tableIter != tableEnd ;++tableIter)
     668             :                         {
     669           0 :                             OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(tableIter->second);
     670             : 
     671           0 :                             bFound = pTabWin->ExistsField( rFieldName, aInfo );
     672           0 :                             if ( bFound )
     673           0 :                                 rFieldName = aInfo->GetField();
     674             :                         }
     675           0 :                         if ( ( rFieldName.toChar() != '*' ) && ( rFieldName.indexOf( aQuote ) == -1 ) )
     676             :                         {
     677             :                             OSL_ENSURE(!pEntryField->GetTable().isEmpty(),"No table field name!");
     678           0 :                             aTmpStr.append(::dbtools::quoteName(aQuote, rFieldName));
     679             :                         }
     680             :                         else
     681           0 :                             aTmpStr.append(rFieldName);
     682             :                     }
     683             :                     else
     684           0 :                         aTmpStr.append(rFieldName);
     685             : 
     686           0 :                     if  ( pEntryField->isAggreateFunction() )
     687             :                     {
     688             :                         OSL_ENSURE(!pEntryField->GetFunction().isEmpty(),"Function name must not be empty! ;-(");
     689           0 :                         OUStringBuffer aTmpStr2( pEntryField->GetFunction());
     690           0 :                         aTmpStr2.appendAscii("(");
     691           0 :                         aTmpStr2.append(aTmpStr.makeStringAndClear());
     692           0 :                         aTmpStr2.appendAscii(")");
     693           0 :                         aTmpStr = aTmpStr2;
     694             :                     }
     695             : 
     696           0 :                     if (!rFieldAlias.isEmpty()                         &&
     697           0 :                         (rFieldName.toChar() != '*'                     ||
     698           0 :                         pEntryField->isNumericOrAggreateFunction()      ||
     699           0 :                         pEntryField->isOtherFunction()))
     700             :                     {
     701           0 :                         aTmpStr.append(s_sAs);
     702           0 :                         aTmpStr.append(::dbtools::quoteName(aQuote, rFieldAlias));
     703             :                     }
     704           0 :                     aFieldListStr.append(aTmpStr.makeStringAndClear());
     705           0 :                     aFieldListStr.append(sFieldSeparator);
     706             :                 }
     707           0 :             }
     708           0 :             if(!aFieldListStr.isEmpty())
     709           0 :                 aFieldListStr.setLength(aFieldListStr.getLength()-2);
     710             :         }
     711           0 :         catch(SQLException&)
     712             :         {
     713             :             OSL_FAIL("Failure while building select list!");
     714             :         }
     715           0 :         return aFieldListStr.makeStringAndClear();
     716             :     }
     717           0 :     bool GenerateCriterias( OQueryDesignView* _pView,
     718             :                                 OUStringBuffer& rRetStr,
     719             :                                 OUStringBuffer& rHavingStr,
     720             :                                 OTableFields& _rFieldList,
     721             :                                 bool bMulti )
     722             :     {
     723             :         // * must not contain a filter : have I already shown the correct warning ?
     724           0 :         bool bCritsOnAsterikWarning = false;        // ** TMFS **
     725             : 
     726           0 :         OUString aFieldName,aCriteria,aWhereStr,aHavingStr,aWork/*,aOrderStr*/;
     727             :         // print line by line joined with AND
     728           0 :         sal_uInt16 nMaxCriteria = 0;
     729           0 :         OTableFields::iterator aIter = _rFieldList.begin();
     730           0 :         OTableFields::iterator aEnd = _rFieldList.end();
     731           0 :         for(;aIter != aEnd;++aIter)
     732             :         {
     733           0 :             nMaxCriteria = ::std::max<sal_uInt16>(nMaxCriteria,(sal_uInt16)(*aIter)->GetCriteria().size());
     734             :         }
     735           0 :         Reference< XConnection> xConnection = static_cast<OQueryController&>(_pView->getController()).getConnection();
     736           0 :         if(!xConnection.is())
     737           0 :             return false;
     738             :         try
     739             :         {
     740           0 :             const Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
     741           0 :             const OUString aQuote = xMetaData->getIdentifierQuoteString();
     742           0 :             const IParseContext& rContext = static_cast<OQueryController&>(_pView->getController()).getParser().getContext();
     743             : 
     744           0 :             for (sal_uInt16 i=0 ; i < nMaxCriteria ; i++)
     745             :             {
     746           0 :                 aHavingStr = aWhereStr = "";
     747             : 
     748           0 :                 for(aIter = _rFieldList.begin();aIter != aEnd;++aIter)
     749             :                 {
     750           0 :                     OTableFieldDescRef  pEntryField = *aIter;
     751           0 :                     aFieldName = pEntryField->GetField();
     752             : 
     753           0 :                     if (aFieldName.isEmpty())
     754           0 :                         continue;
     755           0 :                     aCriteria = pEntryField->GetCriteria( i );
     756           0 :                     if ( !aCriteria.isEmpty() )
     757             :                     {
     758             :                         // * is not allowed to contain any filter, only when used in combination an aggregate function
     759           0 :                         if ( aFieldName.toChar() == '*' && pEntryField->isNoneFunction() )
     760             :                         {
     761             :                             // only show the messagebox the first time
     762           0 :                             if (!bCritsOnAsterikWarning)
     763           0 :                                 MessageDialog(_pView, ModuleRes( STR_QRY_CRITERIA_ON_ASTERISK)).Execute();
     764           0 :                             bCritsOnAsterikWarning = true;
     765           0 :                             continue;
     766             :                         }
     767           0 :                         aWork = quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
     768             : 
     769           0 :                         if ( (pEntryField->GetFunctionType() & (FKT_OTHER|FKT_NUMERIC)) || (aFieldName.toChar() == '*') )
     770           0 :                             aWork += aFieldName;
     771             :                         else
     772           0 :                             aWork += ::dbtools::quoteName(aQuote, aFieldName);
     773             : 
     774           0 :                         if ( pEntryField->isAggreateFunction() || pEntryField->IsGroupBy() )
     775             :                         {
     776           0 :                             if (aHavingStr.isEmpty())            // no more criteria
     777           0 :                                 aHavingStr += "(";               // bracket
     778             :                             else
     779           0 :                                 aHavingStr += C_AND;
     780             : 
     781           0 :                             if ( pEntryField->isAggreateFunction() )
     782             :                             {
     783             :                                 OSL_ENSURE(!pEntryField->GetFunction().isEmpty(),"No function name for aggregate given!");
     784           0 :                                 aHavingStr += pEntryField->GetFunction();
     785           0 :                                 aHavingStr += "(";              // bracket
     786           0 :                                 aHavingStr += aWork;
     787           0 :                                 aHavingStr += ")";             // bracket
     788             :                             }
     789             :                             else
     790           0 :                                 aHavingStr += aWork;
     791             : 
     792           0 :                             OUString aTmp = aCriteria;
     793           0 :                             OUString aErrorMsg;
     794           0 :                             Reference<XPropertySet> xColumn;
     795           0 :                             boost::scoped_ptr< ::connectivity::OSQLParseNode> pParseNode(_pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn));
     796           0 :                             if (pParseNode.get())
     797             :                             {
     798           0 :                                 if (bMulti && !(pEntryField->isOtherFunction() || (aFieldName.toChar() == '*')))
     799           0 :                                     pParseNode->replaceNodeValue(pEntryField->GetAlias(),aFieldName);
     800           0 :                                 OUString sHavingStr = aHavingStr;
     801             : 
     802           0 :                                 sal_uInt32 nCount = pParseNode->count();
     803           0 :                                 for( sal_uInt32 node = 1 ; node < nCount ; ++node)
     804             :                                     pParseNode->getChild(node)->parseNodeToStr( sHavingStr,
     805             :                                                                 xConnection,
     806             :                                                                 &rContext,
     807             :                                                                 false,
     808           0 :                                                                 !pEntryField->isOtherFunction());
     809           0 :                                 aHavingStr = sHavingStr;
     810             :                             }
     811             :                             else
     812           0 :                                 aHavingStr += aCriteria;
     813             :                         }
     814             :                         else
     815             :                         {
     816           0 :                             if ( aWhereStr.isEmpty() )           // no more criteria
     817           0 :                                 aWhereStr += "(";                // bracket
     818             :                             else
     819           0 :                                 aWhereStr += C_AND;
     820             : 
     821           0 :                             aWhereStr += " ";
     822             :                             // aCriteria could have some german numbers so I have to be sure here
     823           0 :                             OUString aTmp = aCriteria;
     824           0 :                             OUString aErrorMsg;
     825           0 :                             Reference<XPropertySet> xColumn;
     826           0 :                             boost::scoped_ptr< ::connectivity::OSQLParseNode> pParseNode( _pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn));
     827           0 :                             if (pParseNode.get())
     828             :                             {
     829           0 :                                 if (bMulti && !(pEntryField->isOtherFunction() || (aFieldName.toChar() == '*')))
     830           0 :                                     pParseNode->replaceNodeValue(pEntryField->GetAlias(),aFieldName);
     831           0 :                                 OUString aWhere = aWhereStr;
     832             :                                 pParseNode->parseNodeToStr( aWhere,
     833             :                                                             xConnection,
     834             :                                                             &rContext,
     835             :                                                             false,
     836           0 :                                                             !pEntryField->isOtherFunction() );
     837           0 :                                 aWhereStr = aWhere;
     838             :                             }
     839             :                             else
     840             :                             {
     841           0 :                                 aWhereStr += aWork + "=" + aCriteria;
     842           0 :                             }
     843             :                         }
     844             :                     }
     845             :                     // only once for each field
     846           0 :                     else if ( !i && pEntryField->isCondition() )
     847             :                     {
     848           0 :                         if (aWhereStr.isEmpty())         // no more criteria
     849           0 :                             aWhereStr += "(";            // bracket
     850             :                         else
     851           0 :                             aWhereStr += C_AND;
     852           0 :                         aWhereStr += pEntryField->GetField();
     853             :                     }
     854           0 :                 }
     855           0 :                 if (!aWhereStr.isEmpty())
     856             :                 {
     857           0 :                     aWhereStr += ")";                          // close bracket for the AND branch
     858           0 :                     if (!rRetStr.isEmpty())                            // are there conditions on the field?
     859           0 :                         rRetStr.append(C_OR);
     860             :                     else                                        // open bracket for the OR branch
     861           0 :                         rRetStr.append('(');
     862           0 :                     rRetStr.append(aWhereStr);
     863             :                 }
     864           0 :                 if (!aHavingStr.isEmpty())
     865             :                 {
     866           0 :                     aHavingStr +=  ")";                        // close bracket for the AND branch
     867           0 :                     if (!rHavingStr.isEmpty())                         // are there conditions on the field?
     868           0 :                         rHavingStr.append(C_OR);
     869             :                     else                                        // Open bracket for the OR branch
     870           0 :                         rHavingStr.append('(');
     871           0 :                     rHavingStr.append(aHavingStr);
     872             :                 }
     873             :             }
     874             : 
     875           0 :             if (!rRetStr.isEmpty())
     876           0 :                 rRetStr.append(')');                               // close bracket for the OR branch
     877           0 :             if (!rHavingStr.isEmpty())
     878           0 :                 rHavingStr.append(')');                                // close bracket for the OR branch
     879             :         }
     880           0 :         catch(SQLException&)
     881             :         {
     882             :             OSL_FAIL("Failure while building where clause!");
     883             :         }
     884           0 :         return true;
     885             :     }
     886           0 :     SqlParseError GenerateOrder(    OQueryDesignView* _pView,
     887             :                                     OTableFields& _rFieldList,
     888             :                                     bool bMulti,
     889             :                                     OUString& _rsRet)
     890             :     {
     891           0 :         const OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
     892           0 :         Reference< XConnection> xConnection = rController.getConnection();
     893           0 :         if ( !xConnection.is() )
     894           0 :             return eNoConnection;
     895             : 
     896           0 :         SqlParseError eErrorCode = eOk;
     897             : 
     898           0 :         OUString aColumnName;
     899           0 :         OUString aWorkStr;
     900             :         try
     901             :         {
     902           0 :             const bool bColumnAliasInOrderBy = rController.getSdbMetaData().supportsColumnAliasInOrderBy();
     903           0 :             Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
     904           0 :             OUString aQuote = xMetaData->getIdentifierQuoteString();
     905             :             // * must not containa  filter - have I already shown the warning?
     906           0 :             bool bCritsOnAsterikWarning = false;        // ** TMFS **
     907           0 :             OTableFields::iterator aIter = _rFieldList.begin();
     908           0 :             OTableFields::iterator aEnd = _rFieldList.end();
     909           0 :             for(;aIter != aEnd;++aIter)
     910             :             {
     911           0 :                 OTableFieldDescRef  pEntryField = *aIter;
     912           0 :                 EOrderDir eOrder = pEntryField->GetOrderDir();
     913             :                 // only create a sort expression when the table name and the sort criteria are defined
     914             :                 // otherwise they will be built in GenerateCriteria
     915           0 :                 if ( eOrder != ORDER_NONE )
     916             :                 {
     917           0 :                     aColumnName = pEntryField->GetField();
     918           0 :                     if(aColumnName.toChar() == '*')
     919             :                     {
     920             :                         // only show the  MessageBox the first time
     921           0 :                         if (!bCritsOnAsterikWarning)
     922           0 :                             MessageDialog(_pView, ModuleRes( STR_QRY_ORDERBY_ON_ASTERISK)).Execute();
     923           0 :                         bCritsOnAsterikWarning = true;
     924           0 :                         continue;
     925             :                     }
     926             : 
     927           0 :                     if ( bColumnAliasInOrderBy && !pEntryField->GetFieldAlias().isEmpty() )
     928             :                     {
     929           0 :                         aWorkStr += ::dbtools::quoteName(aQuote, pEntryField->GetFieldAlias());
     930             :                     }
     931           0 :                     else if ( pEntryField->isNumericOrAggreateFunction() )
     932             :                     {
     933             :                         OSL_ENSURE(!pEntryField->GetFunction().isEmpty(),"Function name cannot be empty! ;-(");
     934           0 :                         aWorkStr += pEntryField->GetFunction();
     935           0 :                         aWorkStr +=  OUString('(');
     936           0 :                         aWorkStr += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
     937             :                         // only quote column name when we don't have a numeric
     938           0 :                         if ( pEntryField->isNumeric() )
     939           0 :                             aWorkStr += aColumnName;
     940             :                         else
     941           0 :                             aWorkStr += ::dbtools::quoteName(aQuote, aColumnName);
     942             : 
     943           0 :                         aWorkStr +=  OUString(')');
     944             :                     }
     945           0 :                     else if ( pEntryField->isOtherFunction() )
     946             :                     {
     947           0 :                         aWorkStr += aColumnName;
     948             :                     }
     949             :                     else
     950             :                     {
     951           0 :                         aWorkStr += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
     952           0 :                         aWorkStr += ::dbtools::quoteName(aQuote, aColumnName);
     953             :                     }
     954           0 :                     aWorkStr += " ";
     955           0 :                     aWorkStr += OUString( ";ASC;DESC" ).getToken( (sal_uInt16)eOrder, ';' );
     956           0 :                     aWorkStr += ",";
     957             :                 }
     958           0 :             }
     959             : 
     960             :             {
     961           0 :                 OUString sTemp(comphelper::string::stripEnd(aWorkStr, ','));
     962           0 :                 aWorkStr = sTemp;
     963             :             }
     964             : 
     965           0 :             if ( !aWorkStr.isEmpty() )
     966             :             {
     967           0 :                 const sal_Int32 nMaxOrder = xMetaData->getMaxColumnsInOrderBy();
     968           0 :                 OUString sToken(aWorkStr);
     969           0 :                 if ( nMaxOrder && nMaxOrder < comphelper::string::getTokenCount(sToken, ',') )
     970           0 :                     eErrorCode = eStatementTooLong;
     971             :                 else
     972             :                 {
     973           0 :                     _rsRet = " ORDER BY " + aWorkStr;
     974           0 :                 }
     975           0 :             }
     976             :         }
     977           0 :         catch(SQLException&)
     978             :         {
     979             :             OSL_FAIL("Failure while building group by!");
     980             :         }
     981             : 
     982           0 :         return eErrorCode;
     983             :     }
     984             : 
     985           0 :     void GenerateInnerJoinCriterias(const Reference< XConnection>& _xConnection,
     986             :                                     OUString& _rJoinCrit,
     987             :                                     const ::std::vector<OTableConnection*>* _pConnList)
     988             :     {
     989           0 :         ::std::vector<OTableConnection*>::const_iterator aIter = _pConnList->begin();
     990           0 :         ::std::vector<OTableConnection*>::const_iterator aEnd = _pConnList->end();
     991           0 :         for(;aIter != aEnd;++aIter)
     992             :         {
     993           0 :             const OQueryTableConnection* pEntryConn = static_cast<const OQueryTableConnection*>(*aIter);
     994           0 :             OQueryTableConnectionData* pEntryConnData = static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get());
     995           0 :             if ( pEntryConnData->GetJoinType() == INNER_JOIN && !pEntryConnData->isNatural() )
     996             :             {
     997           0 :                 if(!_rJoinCrit.isEmpty())
     998           0 :                     _rJoinCrit += C_AND;
     999           0 :                 _rJoinCrit += BuildJoinCriteria(_xConnection,&pEntryConnData->GetConnLineDataList(),pEntryConnData);
    1000             :             }
    1001             :         }
    1002           0 :     }
    1003           0 :     void searchAndAppendName(const Reference< XConnection>& _xConnection,
    1004             :                              const OQueryTableWindow* _pTableWindow,
    1005             :                              tableNames_t& _rTableNames,
    1006             :                              OUString& _rsTableListStr
    1007             :                              )
    1008             :     {
    1009           0 :         OUString sTabName(BuildTable(_xConnection,_pTableWindow));
    1010             : 
    1011           0 :         if(_rTableNames.find(sTabName) == _rTableNames.end())
    1012             :         {
    1013           0 :             _rTableNames[sTabName] = sal_True;
    1014           0 :             _rsTableListStr += sTabName;
    1015           0 :             _rsTableListStr += ",";
    1016           0 :         }
    1017           0 :     }
    1018           0 :     OUString GenerateFromClause( const Reference< XConnection>& _xConnection,
    1019             :                                         const OQueryTableView::OTableWindowMap* pTabList,
    1020             :                                         const ::std::vector<OTableConnection*>* pConnList
    1021             :                                         )
    1022             :     {
    1023             : 
    1024           0 :         OUString aTableListStr;
    1025             :         // used to avoid putting a table twice in FROM clause
    1026           0 :         tableNames_t aTableNames;
    1027             : 
    1028             :         // generate outer join clause in from
    1029           0 :         if(!pConnList->empty())
    1030             :         {
    1031           0 :             ::std::vector<OTableConnection*>::const_iterator aIter = pConnList->begin();
    1032           0 :             ::std::vector<OTableConnection*>::const_iterator aEnd = pConnList->end();
    1033           0 :             ::std::map<OTableWindow*,sal_Int32> aConnectionCount;
    1034           0 :             for(;aIter != aEnd;++aIter)
    1035             :             {
    1036           0 :                 static_cast<OQueryTableConnection*>(*aIter)->SetVisited(false);
    1037           0 :                 ++aConnectionCount[(*aIter)->GetSourceWin()];
    1038           0 :                 ++aConnectionCount[(*aIter)->GetDestWin()];
    1039             :             }
    1040           0 :             ::std::multimap<sal_Int32 , OTableWindow*> aMulti;
    1041           0 :             ::std::map<OTableWindow*,sal_Int32>::iterator aCountIter = aConnectionCount.begin();
    1042           0 :             ::std::map<OTableWindow*,sal_Int32>::iterator aCountEnd = aConnectionCount.end();
    1043           0 :             for(;aCountIter != aCountEnd;++aCountIter)
    1044             :             {
    1045           0 :                 aMulti.insert(::std::multimap<sal_Int32 , OTableWindow*>::value_type(aCountIter->second,aCountIter->first));
    1046             :             }
    1047             : 
    1048           0 :             const bool bUseEscape = ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_OUTERJOINESCAPE );
    1049           0 :             ::std::multimap<sal_Int32 , OTableWindow*>::reverse_iterator aRIter = aMulti.rbegin();
    1050           0 :             ::std::multimap<sal_Int32 , OTableWindow*>::reverse_iterator aREnd = aMulti.rend();
    1051           0 :             for(;aRIter != aREnd;++aRIter)
    1052             :             {
    1053           0 :                 ::std::vector<OTableConnection*>::const_iterator aConIter = aRIter->second->getTableView()->getTableConnections(aRIter->second);
    1054           0 :                 for(;aConIter != aEnd;++aConIter)
    1055             :                 {
    1056           0 :                     OQueryTableConnection* pEntryConn = static_cast<OQueryTableConnection*>(*aConIter);
    1057           0 :                     if(!pEntryConn->IsVisited() && pEntryConn->GetSourceWin() == aRIter->second )
    1058             :                     {
    1059           0 :                         OUString aJoin;
    1060             :                         GetNextJoin(_xConnection,
    1061             :                                     pEntryConn,
    1062           0 :                                     static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin()),
    1063             :                                     aJoin,
    1064           0 :                                     aTableNames);
    1065             : 
    1066           0 :                         if(!aJoin.isEmpty())
    1067             :                         {
    1068           0 :                             OUString aStr;
    1069           0 :                             switch(static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get())->GetJoinType())
    1070             :                             {
    1071             :                                 case LEFT_JOIN:
    1072             :                                 case RIGHT_JOIN:
    1073             :                                 case FULL_JOIN:
    1074             :                                     {
    1075             :                                         // create outer join
    1076           0 :                                         if ( bUseEscape )
    1077           0 :                                             aStr += "{ oj ";
    1078           0 :                                         aStr += aJoin;
    1079           0 :                                         if ( bUseEscape )
    1080           0 :                                             aStr += " }";
    1081             :                                     }
    1082           0 :                                     break;
    1083             :                                 default:
    1084           0 :                                     aStr += aJoin;
    1085           0 :                                     break;
    1086             :                             }
    1087           0 :                             aStr += ",";
    1088           0 :                             aTableListStr += aStr;
    1089           0 :                         }
    1090             :                     }
    1091             :                 }
    1092             :             }
    1093             : 
    1094             :             // and now all inner joins
    1095             :             // these are implemented as
    1096             :             // "FROM tbl1, tbl2 WHERE tbl1.col1=tlb2.col2"
    1097             :             // rather than
    1098             :             // "FROM tbl1 INNER JOIN tbl2 ON tbl1.col1=tlb2.col2"
    1099           0 :             aIter = pConnList->begin();
    1100           0 :             for(;aIter != aEnd;++aIter)
    1101             :             {
    1102           0 :                 OQueryTableConnection* pEntryConn = static_cast<OQueryTableConnection*>(*aIter);
    1103           0 :                 if(!pEntryConn->IsVisited())
    1104             :                 {
    1105             :                     searchAndAppendName(_xConnection,
    1106           0 :                                         static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin()),
    1107             :                                         aTableNames,
    1108           0 :                                         aTableListStr);
    1109             : 
    1110             :                     searchAndAppendName(_xConnection,
    1111           0 :                                         static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin()),
    1112             :                                         aTableNames,
    1113           0 :                                         aTableListStr);
    1114             :                 }
    1115           0 :             }
    1116             :         }
    1117             :         // all tables that haven't a connection to anyone
    1118           0 :         OQueryTableView::OTableWindowMap::const_iterator aTabIter = pTabList->begin();
    1119           0 :         OQueryTableView::OTableWindowMap::const_iterator aTabEnd = pTabList->end();
    1120           0 :         for(;aTabIter != aTabEnd;++aTabIter)
    1121             :         {
    1122           0 :             const OQueryTableWindow* pEntryTab = static_cast<const OQueryTableWindow*>(aTabIter->second);
    1123           0 :             if(!pEntryTab->ExistsAConn())
    1124             :             {
    1125           0 :                 aTableListStr += BuildTable(_xConnection,pEntryTab);
    1126           0 :                 aTableListStr += ",";
    1127             :             }
    1128             :         }
    1129             : 
    1130           0 :         if(!aTableListStr.isEmpty())
    1131           0 :             aTableListStr = aTableListStr.replaceAt(aTableListStr.getLength()-1,1, OUString() );
    1132           0 :         return aTableListStr;
    1133             :     }
    1134           0 :     OUString GenerateGroupBy(const OQueryDesignView* _pView,OTableFields& _rFieldList, bool bMulti )
    1135             :     {
    1136           0 :         OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    1137           0 :         const Reference< XConnection> xConnection = rController.getConnection();
    1138           0 :         if(!xConnection.is())
    1139           0 :             return OUString();
    1140             : 
    1141           0 :         ::std::map< OUString,bool> aGroupByNames;
    1142             : 
    1143           0 :         OUString aGroupByStr;
    1144             :         try
    1145             :         {
    1146           0 :             const Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1147           0 :             const OUString aQuote = xMetaData->getIdentifierQuoteString();
    1148             : 
    1149           0 :             OTableFields::iterator aIter = _rFieldList.begin();
    1150           0 :             OTableFields::iterator aEnd = _rFieldList.end();
    1151           0 :             for(;aIter != aEnd;++aIter)
    1152             :             {
    1153           0 :                 OTableFieldDescRef  pEntryField = *aIter;
    1154           0 :                 if ( pEntryField->IsGroupBy() )
    1155             :                 {
    1156             :                     OSL_ENSURE(!pEntryField->GetField().isEmpty(),"No Field Name available!;-(");
    1157           0 :                     OUString sGroupByPart = quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
    1158             : 
    1159             :                     // only quote the field name when it isn't calculated
    1160           0 :                     if ( pEntryField->isNoneFunction() )
    1161             :                     {
    1162           0 :                         sGroupByPart += ::dbtools::quoteName(aQuote, pEntryField->GetField());
    1163             :                     }
    1164             :                     else
    1165             :                     {
    1166           0 :                         OUString aTmp = pEntryField->GetField();
    1167           0 :                         OUString aErrorMsg;
    1168           0 :                         Reference<XPropertySet> xColumn;
    1169           0 :                         boost::scoped_ptr< ::connectivity::OSQLParseNode> pParseNode(_pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn));
    1170           0 :                         if (pParseNode.get())
    1171             :                         {
    1172           0 :                             OUString sGroupBy;
    1173             :                             pParseNode->getChild(0)->parseNodeToStr(    sGroupBy,
    1174             :                                                         xConnection,
    1175           0 :                                                         &rController.getParser().getContext(),
    1176             :                                                         false,
    1177           0 :                                                         !pEntryField->isOtherFunction());
    1178           0 :                             sGroupByPart += sGroupBy;
    1179             :                         }
    1180             :                         else
    1181           0 :                             sGroupByPart += pEntryField->GetField();
    1182             :                     }
    1183           0 :                     if ( aGroupByNames.find(sGroupByPart) == aGroupByNames.end() )
    1184             :                     {
    1185           0 :                         aGroupByNames.insert(::std::map< OUString,bool>::value_type(sGroupByPart,true));
    1186           0 :                         aGroupByStr += sGroupByPart;
    1187           0 :                         aGroupByStr += ",";
    1188           0 :                     }
    1189             :                 }
    1190           0 :             }
    1191           0 :             if ( !aGroupByStr.isEmpty() )
    1192             :             {
    1193           0 :                 aGroupByStr = aGroupByStr.replaceAt(aGroupByStr.getLength()-1,1, OUString(' ') );
    1194           0 :                 OUString aGroupByStr2(" GROUP BY ");
    1195           0 :                 aGroupByStr2 += aGroupByStr;
    1196           0 :                 aGroupByStr = aGroupByStr2;
    1197           0 :             }
    1198             :         }
    1199           0 :         catch(SQLException&)
    1200             :         {
    1201             :             OSL_FAIL("Failure while building group by!");
    1202             :         }
    1203           0 :         return aGroupByStr;
    1204             :     }
    1205             :     SqlParseError GetORCriteria(OQueryDesignView* _pView,
    1206             :                                 OSelectionBrowseBox* _pSelectionBrw,
    1207             :                                 const ::connectivity::OSQLParseNode * pCondition,
    1208             :                                 sal_uInt16& nLevel ,
    1209             :                                 bool bHaving = false,
    1210             :                                 bool bAddOrOnOneLine = false);
    1211           0 :     SqlParseError GetSelectionCriteria( OQueryDesignView* _pView,
    1212             :                                         OSelectionBrowseBox* _pSelectionBrw,
    1213             :                                         const ::connectivity::OSQLParseNode* pNode,
    1214             :                                         sal_uInt16& rLevel )
    1215             :     {
    1216           0 :         if (!pNode || !SQL_ISRULE(pNode, select_statement))
    1217           0 :             return eNoSelectStatement;
    1218             : 
    1219             :         // nyi: more checking for the correct structure!
    1220           0 :         pNode = pNode->getChild(3)->getChild(1);
    1221             :         // no where clause found
    1222           0 :         if (!pNode || pNode->isLeaf())
    1223           0 :             return eOk;
    1224             : 
    1225             :         // Next free sentence...
    1226           0 :         SqlParseError eErrorCode = eOk;
    1227           0 :         ::connectivity::OSQLParseNode * pCondition = pNode->getChild(1);
    1228           0 :         if ( pCondition ) // no where clause
    1229             :         {
    1230             :             // now we have to check the other conditions
    1231             :             // first make the logical easier
    1232           0 :             ::connectivity::OSQLParseNode::negateSearchCondition(pCondition);
    1233           0 :             ::connectivity::OSQLParseNode *pNodeTmp = pNode->getChild(1);
    1234             : 
    1235           0 :             ::connectivity::OSQLParseNode::disjunctiveNormalForm(pNodeTmp);
    1236           0 :             pNodeTmp = pNode->getChild(1);
    1237           0 :             ::connectivity::OSQLParseNode::absorptions(pNodeTmp);
    1238           0 :             pNodeTmp = pNode->getChild(1);
    1239             :             // compress sort the criteria @see http://www.openoffice.org/issues/show_bug.cgi?id=24079
    1240           0 :             OSQLParseNode::compress(pNodeTmp);
    1241           0 :             pNodeTmp = pNode->getChild(1);
    1242             : 
    1243             :             // first extract the inner joins conditions
    1244           0 :             GetInnerJoinCriteria(_pView,pNodeTmp);
    1245             :             // now simplify again, join are checked in ComparisonPredicate
    1246           0 :             ::connectivity::OSQLParseNode::absorptions(pNodeTmp);
    1247           0 :             pNodeTmp = pNode->getChild(1);
    1248             : 
    1249             :             // it could happen that pCondition is not more valid
    1250           0 :             eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pNodeTmp, rLevel);
    1251             :         }
    1252           0 :         return eErrorCode;
    1253             :     }
    1254             :     SqlParseError GetANDCriteria(   OQueryDesignView* _pView,
    1255             :                                     OSelectionBrowseBox* _pSelectionBrw,
    1256             :                                     const  ::connectivity::OSQLParseNode * pCondition,
    1257             :                                     sal_uInt16& nLevel,
    1258             :                                     bool bHaving,
    1259             :                                     bool bAddOrOnOneLine);
    1260             :     SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
    1261             :                             OSelectionBrowseBox* _pSelectionBrw,
    1262             :                             const ::connectivity::OSQLParseNode * pCondition,
    1263             :                             const sal_uInt16 nLevel,
    1264             :                             bool bHaving,
    1265             :                             bool bAddOrOnOneLine);
    1266           0 :     SqlParseError GetORCriteria(OQueryDesignView* _pView,
    1267             :                                 OSelectionBrowseBox* _pSelectionBrw,
    1268             :                                 const ::connectivity::OSQLParseNode * pCondition,
    1269             :                                 sal_uInt16& nLevel ,
    1270             :                                 bool bHaving,
    1271             :                                 bool bAddOrOnOneLine)
    1272             :     {
    1273           0 :         SqlParseError eErrorCode = eOk;
    1274             : 
    1275             :         // round brackets around the printout
    1276           0 :         if (pCondition->count() == 3 &&
    1277           0 :             SQL_ISPUNCTUATION(pCondition->getChild(0),"(") &&
    1278           0 :             SQL_ISPUNCTUATION(pCondition->getChild(2),")"))
    1279             :         {
    1280           0 :             eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1),nLevel,bHaving,bAddOrOnOneLine);
    1281             :         }
    1282             :         // OR condition
    1283             :         // a searchcondition can only look like this: search_condition SQL_TOKEN_OR boolean_term
    1284           0 :         else if (SQL_ISRULE(pCondition,search_condition))
    1285             :         {
    1286           0 :             for (int i = 0; i < 3 && eErrorCode == eOk ; i+=2)
    1287             :             {
    1288           0 :                 const  ::connectivity::OSQLParseNode* pChild = pCondition->getChild(i);
    1289           0 :                 if ( SQL_ISRULE(pChild,search_condition) )
    1290           0 :                     eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pChild,nLevel,bHaving,bAddOrOnOneLine);
    1291             :                 else
    1292             :                 {
    1293           0 :                     eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pChild, nLevel,bHaving, i == 0 ? false : bAddOrOnOneLine);
    1294           0 :                     if ( !bAddOrOnOneLine)
    1295           0 :                         nLevel++;
    1296             :                 }
    1297             :             }
    1298             :         }
    1299             :         else
    1300           0 :             eErrorCode = GetANDCriteria( _pView,_pSelectionBrw,pCondition, nLevel, bHaving,bAddOrOnOneLine );
    1301             : 
    1302           0 :         return eErrorCode;
    1303             :     }
    1304           0 :     bool CheckOrCriteria(const ::connectivity::OSQLParseNode* _pCondition,::connectivity::OSQLParseNode* _pFirstColumnRef)
    1305             :     {
    1306           0 :         bool bRet = true;
    1307           0 :         ::connectivity::OSQLParseNode* pFirstColumnRef = _pFirstColumnRef;
    1308           0 :         for (int i = 0; i < 3 && bRet; i+=2)
    1309             :         {
    1310           0 :             const  ::connectivity::OSQLParseNode* pChild = _pCondition->getChild(i);
    1311           0 :             if ( SQL_ISRULE(pChild,search_condition) )
    1312           0 :                 bRet = CheckOrCriteria(pChild,pFirstColumnRef);
    1313             :             else
    1314             :             {
    1315             :                 // this is a simple way to test columns are the same, may be we have to adjust this algo a little bit in future. :-)
    1316           0 :                 ::connectivity::OSQLParseNode* pSecondColumnRef = pChild->getByRule(::connectivity::OSQLParseNode::column_ref);
    1317           0 :                 if ( pFirstColumnRef && pSecondColumnRef )
    1318           0 :                     bRet = *pFirstColumnRef == *pSecondColumnRef;
    1319           0 :                 else if ( !pFirstColumnRef )
    1320           0 :                     pFirstColumnRef = pSecondColumnRef;
    1321             :             }
    1322             :         }
    1323           0 :         return bRet;
    1324             :     }
    1325           0 :     SqlParseError GetANDCriteria(   OQueryDesignView* _pView,
    1326             :                                     OSelectionBrowseBox* _pSelectionBrw,
    1327             :                                     const  ::connectivity::OSQLParseNode * pCondition,
    1328             :                                     sal_uInt16& nLevel,
    1329             :                                     bool bHaving,
    1330             :                                     bool bAddOrOnOneLine)
    1331             :     {
    1332           0 :         const ::com::sun::star::lang::Locale    aLocale = _pView->getLocale();
    1333           0 :         const OUString sDecimal = _pView->getDecimalSeparator();
    1334             : 
    1335             :         // I will need a cast pointer to my com::sun::star::sdbcx::Container
    1336           0 :         OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    1337           0 :         SqlParseError eErrorCode = eOk;
    1338             : 
    1339             :         // round brackets
    1340           0 :         if (SQL_ISRULE(pCondition,boolean_primary))
    1341             :         {
    1342             :             // check if we have to put the or criteria on one line.
    1343           0 :             const  ::connectivity::OSQLParseNode* pSearchCondition = pCondition->getChild(1);
    1344           0 :             bool bMustAddOrOnOneLine = CheckOrCriteria(pSearchCondition,NULL);
    1345           0 :             if ( SQL_ISRULE( pSearchCondition, search_condition) ) // we have a or
    1346             :             {
    1347           0 :                 _pSelectionBrw->DuplicateConditionLevel( nLevel);
    1348           0 :                 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition->getChild(0), nLevel,bHaving,bMustAddOrOnOneLine );
    1349           0 :                 ++nLevel;
    1350           0 :                 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition->getChild(2), nLevel,bHaving,bMustAddOrOnOneLine );
    1351             :             }
    1352             :             else
    1353           0 :                 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition, nLevel,bHaving,bMustAddOrOnOneLine );
    1354             :         }
    1355             :         // The first element is (again) an AND condition
    1356           0 :         else if ( SQL_ISRULE(pCondition,boolean_term) )
    1357             :         {
    1358             :             OSL_ENSURE(pCondition->count() == 3,"Illegal definifiton of boolean_term");
    1359           0 :             eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(0), nLevel,bHaving,bAddOrOnOneLine );
    1360           0 :             if ( eErrorCode == eOk )
    1361           0 :                 eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(2), nLevel,bHaving,bAddOrOnOneLine );
    1362             :         }
    1363           0 :         else if (SQL_ISRULE( pCondition, comparison_predicate))
    1364             :         {
    1365           0 :             eErrorCode = ComparisonPredicate(_pView,_pSelectionBrw,pCondition,nLevel,bHaving,bAddOrOnOneLine);
    1366             :         }
    1367           0 :         else if( SQL_ISRULE(pCondition,like_predicate) )
    1368             :         {
    1369           0 :             const  ::connectivity::OSQLParseNode* pValueExp = pCondition->getChild(0);
    1370           0 :             if (SQL_ISRULE(pValueExp, column_ref ) )
    1371             :             {
    1372           0 :                 OUString aColumnName;
    1373           0 :                 OUString aCondition;
    1374           0 :                 Reference< XConnection> xConnection = rController.getConnection();
    1375           0 :                 if ( xConnection.is() )
    1376             :                 {
    1377           0 :                     Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1378             :                     // the international doesn't matter I have a string
    1379             :                     pCondition->parseNodeToPredicateStr(aCondition,
    1380             :                                                         xConnection,
    1381             :                                                         rController.getNumberFormatter(),
    1382             :                                                         aLocale,
    1383           0 :                                                         static_cast<sal_Char>(sDecimal.toChar()),
    1384           0 :                                                         &rController.getParser().getContext());
    1385             : 
    1386             :                     pValueExp->parseNodeToPredicateStr( aColumnName,
    1387             :                                                         xConnection,
    1388             :                                                         rController.getNumberFormatter(),
    1389             :                                                         aLocale,
    1390           0 :                                                         static_cast<sal_Char>(sDecimal.toChar()),
    1391           0 :                                                         &rController.getParser().getContext());
    1392             : 
    1393             :                     // don't display the column name
    1394           0 :                     aCondition = aCondition.copy(aColumnName.getLength());
    1395           0 :                     aCondition = aCondition.trim();
    1396             :                 }
    1397             : 
    1398           0 :                 OTableFieldDescRef aDragLeft = new OTableFieldDesc();
    1399           0 :                 if ( eOk == ( eErrorCode = FillDragInfo(_pView,pValueExp,aDragLeft) ))
    1400             :                 {
    1401           0 :                     if ( bHaving )
    1402           0 :                         aDragLeft->SetGroupBy(true);
    1403           0 :                     _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
    1404           0 :                 }
    1405             :             }
    1406           0 :             else if(SQL_ISRULEOR3(pValueExp, general_set_fct, set_fct_spec, position_exp)  ||
    1407           0 :                       SQL_ISRULEOR3(pValueExp, extract_exp, fold, char_substring_fct)       ||
    1408           0 :                       SQL_ISRULEOR2(pValueExp, length_exp, char_value_fct))
    1409             :             {
    1410             :                 AddFunctionCondition(   _pView,
    1411             :                                         _pSelectionBrw,
    1412             :                                         pCondition,
    1413             :                                         nLevel,
    1414             :                                         bHaving,
    1415           0 :                                         bAddOrOnOneLine);
    1416             :             }
    1417             :             else
    1418             :             {
    1419           0 :                 eErrorCode = eNoColumnInLike;
    1420           0 :                 OUString sError(ModuleRes(STR_QRY_LIKE_LEFT_NO_COLUMN));
    1421           0 :                 _pView->getController().appendError( sError );
    1422             :             }
    1423             :         }
    1424           0 :         else if(    SQL_ISRULEOR2(pCondition,test_for_null,in_predicate)
    1425           0 :                 ||  SQL_ISRULEOR2(pCondition,all_or_any_predicate,between_predicate))
    1426             :         {
    1427           0 :             if ( SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
    1428             :             {
    1429             :                 AddFunctionCondition(   _pView,
    1430             :                                         _pSelectionBrw,
    1431             :                                         pCondition,
    1432             :                                         nLevel,
    1433             :                                         bHaving,
    1434           0 :                                         bAddOrOnOneLine);
    1435             :             }
    1436           0 :             else if ( SQL_ISRULE(pCondition->getChild(0), column_ref ) )
    1437             :             {
    1438             :                 // parse condition
    1439           0 :                 OUString sCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,1);
    1440           0 :                 OTableFieldDescRef  aDragLeft = new OTableFieldDesc();
    1441           0 :                 if ( eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) )
    1442             :                 {
    1443           0 :                     if ( bHaving )
    1444           0 :                         aDragLeft->SetGroupBy(true);
    1445           0 :                     _pSelectionBrw->AddCondition(aDragLeft, sCondition, nLevel,bAddOrOnOneLine);
    1446           0 :                 }
    1447             :             }
    1448             :             else
    1449             :             {
    1450             :                 // Parse the function condition
    1451           0 :                 OUString sCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,1);
    1452           0 :                 Reference< XConnection> xConnection = rController.getConnection();
    1453           0 :                 Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1454             :                     // the international doesn't matter I have a string
    1455           0 :                 OUString sName;
    1456             :                 pCondition->getChild(0)->parseNodeToPredicateStr(sName,
    1457             :                                                     xConnection,
    1458             :                                                     rController.getNumberFormatter(),
    1459             :                                                     aLocale,
    1460           0 :                                                     static_cast<sal_Char>(sDecimal.toChar()),
    1461           0 :                                                     &rController.getParser().getContext());
    1462             : 
    1463           0 :                 OTableFieldDescRef aDragLeft = new OTableFieldDesc();
    1464           0 :                 aDragLeft->SetField(sName);
    1465           0 :                 aDragLeft->SetFunctionType(FKT_OTHER);
    1466             : 
    1467           0 :                 if ( bHaving )
    1468           0 :                     aDragLeft->SetGroupBy(true);
    1469           0 :                 _pSelectionBrw->AddCondition(aDragLeft, sCondition, nLevel,bAddOrOnOneLine);
    1470             :             }
    1471             :         }
    1472           0 :         else if( SQL_ISRULEOR2(pCondition,existence_test,unique_test) )
    1473             :         {
    1474             :             // Parse the function condition
    1475           0 :             OUString aCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,0);
    1476             : 
    1477           0 :             OTableFieldDescRef aDragLeft = new OTableFieldDesc();
    1478           0 :             aDragLeft->SetField(aCondition);
    1479           0 :             aDragLeft->SetFunctionType(FKT_CONDITION);
    1480             : 
    1481           0 :             eErrorCode = _pSelectionBrw->InsertField(aDragLeft,BROWSER_INVALIDID,false,true).is() ? eOk : eTooManyColumns;
    1482             :         }
    1483             :         else //! TODO not supported yet
    1484           0 :             eErrorCode = eStatementTooComplex;
    1485             :         // Pass on the error code
    1486           0 :         return eErrorCode;
    1487             :     }
    1488           0 :     SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
    1489             :                             OSelectionBrowseBox* _pSelectionBrw,
    1490             :                             const ::connectivity::OSQLParseNode * pCondition,
    1491             :                             const sal_uInt16 nLevel,
    1492             :                             bool bHaving,
    1493             :                             bool bAddOrOnOneLine)
    1494             :     {
    1495           0 :         SqlParseError eErrorCode = eOk;
    1496           0 :         OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    1497             : 
    1498           0 :         OSQLParseNode* pFunction = pCondition->getChild(0);
    1499             : 
    1500             :         OSL_ENSURE(SQL_ISRULEOR3(pFunction, general_set_fct, set_fct_spec, position_exp)  ||
    1501             :                      SQL_ISRULEOR3(pFunction, extract_exp, fold, char_substring_fct)      ||
    1502             :                      SQL_ISRULEOR2(pFunction,length_exp,char_value_fct),
    1503             :                    "Illegal call!");
    1504           0 :         OUString aCondition;
    1505           0 :         OTableFieldDescRef aDragLeft = new OTableFieldDesc();
    1506             : 
    1507           0 :         OUString aColumnName;
    1508           0 :         Reference< XConnection> xConnection = rController.getConnection();
    1509           0 :         if(xConnection.is())
    1510             :         {
    1511           0 :             Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1512             :             pCondition->parseNodeToPredicateStr(aCondition,
    1513             :                                                 xConnection,
    1514             :                                                 rController.getNumberFormatter(),
    1515             :                                                 _pView->getLocale(),
    1516           0 :                                                 static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
    1517           0 :                                                 &rController.getParser().getContext());
    1518             : 
    1519             :             pFunction->parseNodeToStr(  aColumnName,
    1520             :                                         xConnection,
    1521           0 :                                         &rController.getParser().getContext(),
    1522             :                                         true,
    1523           0 :                                         true); // quote is to true because we need quoted elements inside the function
    1524             :             // don't display the column name
    1525           0 :             aCondition = aCondition.copy(aColumnName.getLength());
    1526           0 :             aCondition = aCondition.trim();
    1527           0 :             if ( aCondition.startsWith("=") ) // ignore the equal sign
    1528           0 :                 aCondition = aCondition.copy(1);
    1529             : 
    1530           0 :             if ( SQL_ISRULE(pFunction, general_set_fct ) )
    1531             :             {
    1532           0 :                 sal_Int32 nFunctionType = FKT_AGGREGATE;
    1533           0 :                 OSQLParseNode* pParamNode = pFunction->getChild(pFunction->count()-2);
    1534           0 :                 if ( pParamNode && pParamNode->getTokenValue().toChar() == '*' )
    1535             :                 {
    1536           0 :                     OJoinTableView::OTableWindowMap& rTabList = _pView->getTableView()->GetTabWinMap();
    1537           0 :                     OJoinTableView::OTableWindowMap::iterator aIter = rTabList.begin();
    1538           0 :                     OJoinTableView::OTableWindowMap::iterator aTabEnd = rTabList.end();
    1539           0 :                     for(;aIter != aTabEnd;++aIter)
    1540             :                     {
    1541           0 :                         OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
    1542           0 :                         if (pTabWin->ExistsField( OUString("*"), aDragLeft ))
    1543             :                         {
    1544           0 :                             aDragLeft->SetAlias(OUString());
    1545           0 :                             aDragLeft->SetTable(OUString());
    1546           0 :                             break;
    1547             :                         }
    1548             :                     }
    1549             :                 }
    1550           0 :                 else if( eOk != ( eErrorCode = FillDragInfo(_pView,pParamNode,aDragLeft))
    1551           0 :                         && SQL_ISRULE(pParamNode,num_value_exp) )
    1552             :                 {
    1553           0 :                     OUString sParameterValue;
    1554             :                     pParamNode->parseNodeToStr( sParameterValue,
    1555             :                                                 xConnection,
    1556           0 :                                                 &rController.getParser().getContext());
    1557           0 :                     nFunctionType |= FKT_NUMERIC;
    1558           0 :                     aDragLeft->SetField(sParameterValue);
    1559           0 :                     eErrorCode = eOk;
    1560             :                 }
    1561           0 :                 aDragLeft->SetFunctionType(nFunctionType);
    1562           0 :                 if ( bHaving )
    1563           0 :                     aDragLeft->SetGroupBy(true);
    1564           0 :                 sal_Int32 nIndex = 0;
    1565           0 :                 aDragLeft->SetFunction(aColumnName.getToken(0,'(',nIndex));
    1566             :             }
    1567             :             else
    1568             :             {
    1569             :                 // for an unknown function we write the whole text in the field
    1570           0 :                 aDragLeft->SetField(aColumnName);
    1571           0 :                 if(bHaving)
    1572           0 :                     aDragLeft->SetGroupBy(true);
    1573           0 :                 aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
    1574             :             }
    1575           0 :             _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
    1576             :         }
    1577             : 
    1578           0 :         return eErrorCode;
    1579             :     }
    1580           0 :     SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
    1581             :                             OSelectionBrowseBox* _pSelectionBrw,
    1582             :                             const ::connectivity::OSQLParseNode * pCondition,
    1583             :                             const sal_uInt16 nLevel,
    1584             :                             bool bHaving
    1585             :                             ,bool bAddOrOnOneLine)
    1586             :     {
    1587           0 :         SqlParseError eErrorCode = eOk;
    1588           0 :         OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    1589             : 
    1590             :         OSL_ENSURE(SQL_ISRULE( pCondition, comparison_predicate),"ComparisonPredicate: pCondition is not a Comparison Predicate");
    1591           0 :         if ( SQL_ISRULE(pCondition->getChild(0), column_ref )
    1592           0 :             || SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref) )
    1593             :         {
    1594           0 :             OUString aCondition;
    1595           0 :             OTableFieldDescRef aDragLeft = new OTableFieldDesc();
    1596             : 
    1597           0 :             if ( SQL_ISRULE(pCondition->getChild(0), column_ref ) && SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
    1598             :             {
    1599           0 :                 OTableFieldDescRef aDragRight = new OTableFieldDesc();
    1600           0 :                 if (eOk != ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) ||
    1601           0 :                     eOk != ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(2),aDragRight)))
    1602           0 :                     return eErrorCode;
    1603             : 
    1604             :                 OQueryTableConnection* pConn = static_cast<OQueryTableConnection*>(
    1605           0 :                                                     _pView->getTableView()->GetTabConn(static_cast<OQueryTableWindow*>(aDragLeft->GetTabWindow()),
    1606           0 :                                                                                        static_cast<OQueryTableWindow*>(aDragRight->GetTabWindow()),
    1607           0 :                                                                                        true));
    1608           0 :                 if ( pConn )
    1609             :                 {
    1610           0 :                     OConnectionLineDataVec& rLineDataList = pConn->GetData()->GetConnLineDataList();
    1611           0 :                     OConnectionLineDataVec::iterator aIter = rLineDataList.begin();
    1612           0 :                     OConnectionLineDataVec::iterator aEnd = rLineDataList.end();
    1613           0 :                     for(;aIter != aEnd;++aIter)
    1614             :                     {
    1615           0 :                         if((*aIter)->GetSourceFieldName() == aDragLeft->GetField() ||
    1616           0 :                            (*aIter)->GetDestFieldName() == aDragLeft->GetField() )
    1617           0 :                             break;
    1618             :                     }
    1619           0 :                     if(aIter != aEnd)
    1620           0 :                         return eOk;
    1621           0 :                 }
    1622             :             }
    1623             : 
    1624           0 :             sal_uInt32 nPos = 0;
    1625           0 :             if(SQL_ISRULE(pCondition->getChild(0), column_ref ))
    1626             :             {
    1627           0 :                 nPos = 0;
    1628           0 :                 sal_uInt32 i=1;
    1629             : 
    1630             :                 // don't display the equal
    1631           0 :                 if (pCondition->getChild(i)->getNodeType() == SQL_NODE_EQUAL)
    1632           0 :                     i++;
    1633             : 
    1634             :                 // Bedingung parsen
    1635           0 :                 aCondition = ParseCondition(rController
    1636             :                                             ,pCondition
    1637             :                                             ,_pView->getDecimalSeparator()
    1638             :                                             ,_pView->getLocale()
    1639           0 :                                             ,i);
    1640             :             }
    1641           0 :             else if( SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
    1642             :             {
    1643           0 :                 nPos = pCondition->count()-1;
    1644             : 
    1645           0 :                 sal_Int32 i = static_cast<sal_Int32>(pCondition->count() - 2);
    1646           0 :                 switch (pCondition->getChild(i)->getNodeType())
    1647             :                 {
    1648             :                     case SQL_NODE_EQUAL:
    1649             :                         // don't display the equal
    1650           0 :                         i--;
    1651           0 :                         break;
    1652             :                     case SQL_NODE_LESS:
    1653             :                         // take the opposite as we change the order
    1654           0 :                         i--;
    1655           0 :                         aCondition += ">";
    1656           0 :                         break;
    1657             :                     case SQL_NODE_LESSEQ:
    1658             :                         // take the opposite as we change the order
    1659           0 :                         i--;
    1660           0 :                         aCondition += ">=";
    1661           0 :                         break;
    1662             :                     case SQL_NODE_GREAT:
    1663             :                         // take the opposite as we change the order
    1664           0 :                         i--;
    1665           0 :                         aCondition += "<";
    1666           0 :                         break;
    1667             :                     case SQL_NODE_GREATEQ:
    1668             :                         // take the opposite as we change the order
    1669           0 :                         i--;
    1670           0 :                         aCondition += "<=";
    1671           0 :                         break;
    1672             :                     default:
    1673           0 :                         break;
    1674             :                 }
    1675             : 
    1676             :                 // go backward
    1677           0 :                 Reference< XConnection> xConnection = rController.getConnection();
    1678           0 :                 if(xConnection.is())
    1679             :                 {
    1680           0 :                     Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1681           0 :                     for (; i >= 0; i--)
    1682             :                         pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
    1683             :                                                 xConnection,
    1684             :                                                 rController.getNumberFormatter(),
    1685             :                                                 _pView->getLocale(),
    1686           0 :                                                 static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
    1687           0 :                                                 &rController.getParser().getContext());
    1688           0 :                 }
    1689             :             }
    1690             :             // else ???
    1691             : 
    1692           0 :             if( eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(nPos),aDragLeft)))
    1693             :             {
    1694           0 :                 if(bHaving)
    1695           0 :                     aDragLeft->SetGroupBy(true);
    1696           0 :                 _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
    1697           0 :             }
    1698             :         }
    1699           0 :         else if( SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
    1700             :         {
    1701             :             AddFunctionCondition(   _pView,
    1702             :                                     _pSelectionBrw,
    1703             :                                     pCondition,
    1704             :                                     nLevel,
    1705             :                                     bHaving,
    1706           0 :                                     bAddOrOnOneLine);
    1707             :         }
    1708             :         else // it can only be an Expr
    1709             :         {
    1710           0 :             OUString aName,aCondition;
    1711             : 
    1712           0 :             ::connectivity::OSQLParseNode *pLhs = pCondition->getChild(0);
    1713           0 :             ::connectivity::OSQLParseNode *pRhs = pCondition->getChild(2);
    1714             :             // Field name
    1715           0 :             Reference< XConnection> xConnection = rController.getConnection();
    1716           0 :             if(xConnection.is())
    1717             :             {
    1718             :                 pLhs->parseNodeToStr(aName,
    1719             :                                      xConnection,
    1720           0 :                                      &rController.getParser().getContext(),
    1721           0 :                                      true);
    1722             :                 // Criteria
    1723           0 :                 aCondition = pCondition->getChild(1)->getTokenValue();
    1724             :                 pRhs->parseNodeToPredicateStr(aCondition,
    1725             :                                                             xConnection,
    1726             :                                                             rController.getNumberFormatter(),
    1727             :                                                             _pView->getLocale(),
    1728           0 :                                                             static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
    1729           0 :                                                             &rController.getParser().getContext());
    1730             :             }
    1731             : 
    1732           0 :             OTableFieldDescRef aDragLeft = new OTableFieldDesc();
    1733           0 :             aDragLeft->SetField(aName);
    1734           0 :             aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
    1735             :             // and add it on
    1736           0 :             _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
    1737             :         }
    1738           0 :         return eErrorCode;
    1739             :     }
    1740             : 
    1741             :     namespace
    1742             :     {
    1743           0 :         OQueryTableWindow* lcl_findColumnInTables( const OUString& _rColumName, const OJoinTableView::OTableWindowMap& _rTabList, OTableFieldDescRef& _rInfo )
    1744             :         {
    1745           0 :             OJoinTableView::OTableWindowMap::const_iterator aIter = _rTabList.begin();
    1746           0 :             OJoinTableView::OTableWindowMap::const_iterator aEnd = _rTabList.end();
    1747           0 :             for ( ; aIter != aEnd; ++aIter )
    1748             :             {
    1749           0 :                 OQueryTableWindow* pTabWin = static_cast< OQueryTableWindow* >( aIter->second );
    1750           0 :                 if ( pTabWin && pTabWin->ExistsField( _rColumName, _rInfo ) )
    1751           0 :                     return pTabWin;
    1752             :             }
    1753           0 :             return NULL;
    1754             :         }
    1755             :     }
    1756             : 
    1757           0 :     void InsertColumnRef(const OQueryDesignView* _pView,
    1758             :                         const ::connectivity::OSQLParseNode * pColumnRef,
    1759             :                         OUString& aColumnName,
    1760             :                         const OUString& aColumnAlias,
    1761             :                         OUString& aTableRange,
    1762             :                         OTableFieldDescRef& _raInfo,
    1763             :                         OJoinTableView::OTableWindowMap* pTabList)
    1764             :     {
    1765             : 
    1766             :         // Put the table names together
    1767           0 :         ::connectivity::OSQLParseTreeIterator& rParseIter = static_cast<OQueryController&>(_pView->getController()).getParseIterator();
    1768           0 :         rParseIter.getColumnRange( pColumnRef, aColumnName, aTableRange );
    1769             : 
    1770           0 :         bool bFound(false);
    1771             :         OSL_ENSURE(!aColumnName.isEmpty(),"Column name must not be empty");
    1772           0 :         if (aTableRange.isEmpty())
    1773             :         {
    1774             :             // SELECT column, ...
    1775           0 :             bFound = NULL != lcl_findColumnInTables( aColumnName, *pTabList, _raInfo );
    1776           0 :             if ( bFound && ( aColumnName.toChar() != '*' ) )
    1777           0 :                 _raInfo->SetFieldAlias(aColumnAlias);
    1778             :         }
    1779             :         else
    1780             :         {
    1781             :             // SELECT range.column, ...
    1782           0 :             OQueryTableWindow* pTabWin = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable(aTableRange);
    1783             : 
    1784           0 :             if (pTabWin && pTabWin->ExistsField(aColumnName, _raInfo))
    1785             :             {
    1786           0 :                 if(aColumnName.toChar() != '*')
    1787           0 :                     _raInfo->SetFieldAlias(aColumnAlias);
    1788           0 :                 bFound = true;
    1789             :             }
    1790             :         }
    1791           0 :         if (!bFound)
    1792             :         {
    1793           0 :             _raInfo->SetTable(OUString());
    1794           0 :             _raInfo->SetAlias(OUString());
    1795           0 :             _raInfo->SetField(aColumnName);
    1796           0 :             _raInfo->SetFieldAlias(aColumnAlias);   // nyi : here it continues Expr_1, Expr_2 ...
    1797           0 :             _raInfo->SetFunctionType(FKT_OTHER);
    1798             :         }
    1799           0 :     }
    1800           0 :     bool checkJoinConditions(   const OQueryDesignView* _pView,
    1801             :                                     const ::connectivity::OSQLParseNode* _pNode )
    1802             :     {
    1803           0 :         const ::connectivity::OSQLParseNode* pJoinNode = NULL;
    1804           0 :         bool bRet = true;
    1805           0 :         if (SQL_ISRULE(_pNode,qualified_join))
    1806           0 :             pJoinNode = _pNode;
    1807           0 :         else if (SQL_ISRULE(_pNode,table_ref)
    1808           0 :                 &&  _pNode->count() == 3
    1809           0 :                 &&  SQL_ISPUNCTUATION(_pNode->getChild(0),"(")
    1810           0 :                 &&  SQL_ISPUNCTUATION(_pNode->getChild(2),")") ) // '(' joined_table ')'
    1811           0 :             pJoinNode = _pNode->getChild(1);
    1812           0 :         else if (! ( SQL_ISRULE(_pNode, table_ref) && _pNode->count() == 2) ) // table_node table_primary_as_range_column
    1813           0 :             bRet = false;
    1814             : 
    1815           0 :         if (pJoinNode && !InsertJoin(_pView,pJoinNode))
    1816           0 :             bRet = false;
    1817           0 :         return bRet;
    1818             :     }
    1819           0 :     bool InsertJoin(const OQueryDesignView* _pView,
    1820             :                         const ::connectivity::OSQLParseNode *pNode)
    1821             :     {
    1822             :         OSL_ENSURE( SQL_ISRULE( pNode, qualified_join ) || SQL_ISRULE( pNode, joined_table ) || SQL_ISRULE( pNode, cross_union ),
    1823             :             "OQueryDesignView::InsertJoin: Error in the Parse Tree");
    1824             : 
    1825           0 :         if (SQL_ISRULE(pNode,joined_table))
    1826           0 :             return InsertJoin(_pView,pNode->getChild(1));
    1827             : 
    1828             :         // first check the left and right side
    1829           0 :         const ::connectivity::OSQLParseNode* pRightTableRef = pNode->getChild(3); // table_ref
    1830           0 :         if ( SQL_ISRULE(pNode, qualified_join) && SQL_ISTOKEN(pNode->getChild(1),NATURAL) )
    1831           0 :             pRightTableRef = pNode->getChild(4); // table_ref
    1832             : 
    1833           0 :         if ( !checkJoinConditions(_pView,pNode->getChild(0)) || !checkJoinConditions(_pView,pRightTableRef))
    1834           0 :             return false;
    1835             : 
    1836             :         // named column join may be implemented later
    1837             :         // SQL_ISRULE(pNode->getChild(4),named_columns_join)
    1838           0 :         EJoinType eJoinType = INNER_JOIN;
    1839           0 :         bool bNatural = false;
    1840           0 :         if ( SQL_ISRULE(pNode, qualified_join) )
    1841             :         {
    1842           0 :             ::connectivity::OSQLParseNode* pJoinType = pNode->getChild(1); // join_type
    1843           0 :             if ( SQL_ISTOKEN(pJoinType,NATURAL) )
    1844             :             {
    1845           0 :                 bNatural = true;
    1846           0 :                 pJoinType = pNode->getChild(2);
    1847             :             }
    1848             : 
    1849           0 :             if (SQL_ISRULE(pJoinType,join_type) && (!pJoinType->count() || SQL_ISTOKEN(pJoinType->getChild(0),INNER)))
    1850             :             {
    1851           0 :                 eJoinType = INNER_JOIN;
    1852             :             }
    1853             :             else
    1854             :             {
    1855           0 :                 if (SQL_ISRULE(pJoinType,join_type))       // one level deeper
    1856           0 :                     pJoinType = pJoinType->getChild(0);
    1857             : 
    1858           0 :                 if (SQL_ISTOKEN(pJoinType->getChild(0),LEFT))
    1859           0 :                     eJoinType = LEFT_JOIN;
    1860           0 :                 else if(SQL_ISTOKEN(pJoinType->getChild(0),RIGHT))
    1861           0 :                     eJoinType = RIGHT_JOIN;
    1862             :                 else
    1863           0 :                     eJoinType = FULL_JOIN;
    1864             :             }
    1865           0 :             if ( SQL_ISRULE(pNode->getChild(4),join_condition) )
    1866             :             {
    1867           0 :                 if ( InsertJoinConnection(_pView,pNode->getChild(4)->getChild(1), eJoinType,pNode->getChild(0),pRightTableRef) != eOk )
    1868           0 :                     return false;
    1869             :             }
    1870             :         }
    1871           0 :         else if ( SQL_ISRULE(pNode, cross_union) )
    1872             :         {
    1873           0 :             eJoinType = CROSS_JOIN;
    1874           0 :             pRightTableRef = pNode->getChild(pNode->count() - 1);
    1875             :         }
    1876             :         else
    1877           0 :             return false;
    1878             : 
    1879           0 :         if ( eJoinType == CROSS_JOIN || bNatural )
    1880             :         {
    1881             : 
    1882           0 :             OQueryTableWindow*  pLeftWindow = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( getTableRange(_pView,pNode->getChild(0)) );
    1883           0 :             OQueryTableWindow*  pRightWindow = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( getTableRange(_pView,pRightTableRef) );
    1884             :             OSL_ENSURE(pLeftWindow && pRightWindow,"Table Windows could not be found!");
    1885           0 :             if ( !pLeftWindow || !pRightWindow )
    1886           0 :                 return false;
    1887             : 
    1888           0 :             OTableFieldDescRef aDragLeft  = new OTableFieldDesc();
    1889           0 :             aDragLeft->SetTabWindow(pLeftWindow);
    1890           0 :             aDragLeft->SetTable(pLeftWindow->GetTableName());
    1891           0 :             aDragLeft->SetAlias(pLeftWindow->GetAliasName());
    1892             : 
    1893           0 :             OTableFieldDescRef aDragRight = new OTableFieldDesc();
    1894           0 :             aDragRight->SetTabWindow(pRightWindow);
    1895           0 :             aDragRight->SetTable(pRightWindow->GetTableName());
    1896           0 :             aDragRight->SetAlias(pRightWindow->GetAliasName());
    1897             : 
    1898           0 :             insertConnection(_pView,eJoinType,aDragLeft,aDragRight,bNatural);
    1899             :         }
    1900             : 
    1901           0 :         return true;
    1902             :     }
    1903           0 :     void insertUnUsedFields(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw)
    1904             :     {
    1905             :         // now we have to insert the fields which aren't in the statement
    1906           0 :         OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    1907           0 :         OTableFields& rUnUsedFields = rController.getUnUsedFields();
    1908           0 :         OTableFields::iterator aEnd = rUnUsedFields.end();
    1909           0 :         for(OTableFields::iterator aIter = rUnUsedFields.begin();aIter != aEnd;++aIter)
    1910           0 :             if(_pSelectionBrw->InsertField(*aIter,BROWSER_INVALIDID,false,false).is())
    1911           0 :                 (*aIter) = NULL;
    1912           0 :         OTableFields().swap( rUnUsedFields );
    1913           0 :     }
    1914             : 
    1915           0 :     SqlParseError InitFromParseNodeImpl(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw)
    1916             :     {
    1917           0 :         SqlParseError eErrorCode = eOk;
    1918             : 
    1919           0 :         OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    1920             : 
    1921           0 :         _pSelectionBrw->PreFill();
    1922           0 :         _pSelectionBrw->SetReadOnly(rController.isReadOnly());
    1923           0 :         _pSelectionBrw->Fill();
    1924             : 
    1925           0 :         ::connectivity::OSQLParseTreeIterator& aIterator = rController.getParseIterator();
    1926           0 :         const ::connectivity::OSQLParseNode* pParseTree = aIterator.getParseTree();
    1927             : 
    1928             :         do
    1929             :         {
    1930           0 :             if ( !pParseTree )
    1931             :             {
    1932             :                 // now we have to insert the fields which aren't in the statement
    1933           0 :                 insertUnUsedFields(_pView,_pSelectionBrw);
    1934           0 :                 break;
    1935             :             }
    1936             : 
    1937           0 :             if ( !rController.isEsacpeProcessing() ) // not allowed in this mode
    1938             :             {
    1939           0 :                 eErrorCode = eNativeMode;
    1940           0 :                 break;
    1941             :             }
    1942             : 
    1943           0 :             if ( !( SQL_ISRULE( pParseTree, select_statement ) ) )
    1944             :             {
    1945           0 :                 eErrorCode = eNoSelectStatement;
    1946           0 :                 break;
    1947             :             }
    1948             : 
    1949           0 :             const OSQLParseNode* pTableExp = pParseTree->getChild(3);
    1950           0 :             if ( pTableExp->getChild(7)->count() > 0 || pTableExp->getChild(8)->count() > 0)
    1951             :             {
    1952           0 :                 eErrorCode = eStatementTooComplex;
    1953           0 :                 break;
    1954             :             }
    1955             : 
    1956           0 :             Reference< XConnection> xConnection = rController.getConnection();
    1957           0 :             if ( !xConnection.is() )
    1958             :             {
    1959             :                 OSL_FAIL( "InitFromParseNodeImpl: no connection? no connection!" );
    1960           0 :                 break;
    1961             :             }
    1962             : 
    1963           0 :             const OSQLTables& aMap = aIterator.getTables();
    1964           0 :             ::comphelper::UStringMixLess aTmp(aMap.key_comp());
    1965           0 :             ::comphelper::UStringMixEqual aKeyComp( aTmp.isCaseSensitive() );
    1966             : 
    1967           0 :             Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
    1968             :             try
    1969             :             {
    1970           0 :                 sal_Int32 nMax = xMetaData->getMaxTablesInSelect();
    1971           0 :                 if ( nMax && nMax < (sal_Int32)aMap.size() )
    1972             :                 {
    1973           0 :                     eErrorCode = eTooManyTables;
    1974           0 :                     break;
    1975             :                 }
    1976             : 
    1977           0 :                 OUString sComposedName;
    1978           0 :                 OUString sAlias;
    1979             : 
    1980           0 :                 OQueryTableView* pTableView = static_cast<OQueryTableView*>(_pView->getTableView());
    1981           0 :                 pTableView->clearLayoutInformation();
    1982           0 :                 OSQLTables::const_iterator aIter = aMap.begin();
    1983           0 :                 OSQLTables::const_iterator aEnd = aMap.end();
    1984           0 :                 for(;aIter != aEnd;++aIter)
    1985             :                 {
    1986           0 :                     OSQLTable xTable = aIter->second;
    1987           0 :                     Reference< XPropertySet > xTableProps( xTable, UNO_QUERY_THROW );
    1988             : 
    1989           0 :                     sAlias = aIter->first;
    1990             : 
    1991             :                     // check whether this is a query
    1992           0 :                     Reference< XPropertySetInfo > xPSI = xTableProps->getPropertySetInfo();
    1993           0 :                     bool bIsQuery = xPSI.is() && xPSI->hasPropertyByName( PROPERTY_COMMAND );
    1994             : 
    1995           0 :                     if ( bIsQuery )
    1996           0 :                         OSL_VERIFY( xTableProps->getPropertyValue( PROPERTY_NAME ) >>= sComposedName );
    1997             :                     else
    1998             :                     {
    1999           0 :                         sComposedName = ::dbtools::composeTableName( xMetaData, xTableProps, ::dbtools::eInDataManipulation, false, false, false );
    2000             : 
    2001             :                         // if the alias is the complete (composed) table, then shorten it
    2002           0 :                         if ( aKeyComp( sComposedName, aIter->first ) )
    2003             :                         {
    2004           0 :                             OUString sCatalog, sSchema, sTable;
    2005           0 :                             ::dbtools::qualifiedNameComponents( xMetaData, sComposedName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
    2006           0 :                             sAlias = sTable;
    2007             :                         }
    2008             :                     }
    2009             : 
    2010             :                     // find the existent window for this alias
    2011           0 :                     OQueryTableWindow* pExistentWin = pTableView->FindTable( sAlias );
    2012           0 :                     if ( !pExistentWin )
    2013             :                     {
    2014           0 :                         pTableView->AddTabWin( sComposedName, sAlias, false );  // don't create data here
    2015             :                     }
    2016             :                     else
    2017             :                     {
    2018             :                         // there already exists a window for this alias ....
    2019           0 :                         if ( !aKeyComp( pExistentWin->GetData()->GetComposedName(), sComposedName ) )
    2020             :                             // ... but for another complete table name -> new window
    2021           0 :                             pTableView->AddTabWin(sComposedName, sAlias);
    2022             :                     }
    2023           0 :                 }
    2024             : 
    2025             :                 // now delete the data for which we haven't any tablewindow
    2026           0 :                 OJoinTableView::OTableWindowMap aTableMap(pTableView->GetTabWinMap());
    2027           0 :                 OJoinTableView::OTableWindowMap::iterator aIterTableMap = aTableMap.begin();
    2028           0 :                 OJoinTableView::OTableWindowMap::iterator aIterTableEnd = aTableMap.end();
    2029           0 :                 for(;aIterTableMap != aIterTableEnd;++aIterTableMap)
    2030             :                 {
    2031           0 :                     if(aMap.find(aIterTableMap->second->GetComposedName())  == aMap.end() &&
    2032           0 :                         aMap.find(aIterTableMap->first)                     == aMap.end())
    2033           0 :                         pTableView->RemoveTabWin(aIterTableMap->second);
    2034             :                 }
    2035             : 
    2036           0 :                 if ( eOk == (eErrorCode = FillOuterJoins(_pView,pTableExp->getChild(0)->getChild(1))) )
    2037             :                 {
    2038             :                     // check if we have a distinct statement
    2039           0 :                     if(SQL_ISTOKEN(pParseTree->getChild(1),DISTINCT))
    2040             :                     {
    2041           0 :                         rController.setDistinct(true);
    2042           0 :                         rController.InvalidateFeature(SID_QUERY_DISTINCT_VALUES);
    2043             :                     }
    2044             :                     else
    2045             :                     {
    2046           0 :                         rController.setDistinct(false);
    2047             :                     }
    2048             : 
    2049             :                     ///check if query has a limit
    2050           0 :                     if( pTableExp->getChild(6)->count() >= 2 && pTableExp->getChild(6)->getChild(1) )
    2051             :                     {
    2052             :                         rController.setLimit(
    2053           0 :                             pTableExp->getChild(6)->getChild(1)->getTokenValue().toInt64() );
    2054             :                     }
    2055             :                     else
    2056             :                     {
    2057           0 :                         rController.setLimit(-1);
    2058             :                     }
    2059             : 
    2060           0 :                     if ( (eErrorCode = InstallFields(_pView, pParseTree, &pTableView->GetTabWinMap())) == eOk )
    2061             :                     {
    2062             :                         // GetSelectionCriteria must be called before GetHavingCriteria
    2063           0 :                         sal_uInt16 nLevel=0;
    2064             : 
    2065           0 :                         if ( eOk == (eErrorCode = GetSelectionCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
    2066             :                         {
    2067           0 :                             if ( eOk == (eErrorCode = GetGroupCriteria(_pView,_pSelectionBrw,pParseTree)) )
    2068             :                             {
    2069           0 :                                 if ( eOk == (eErrorCode = GetHavingCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
    2070             :                                 {
    2071           0 :                                     if ( eOk == (eErrorCode = GetOrderCriteria(_pView,_pSelectionBrw,pParseTree)) )
    2072           0 :                                         insertUnUsedFields(_pView,_pSelectionBrw);
    2073             :                                 }
    2074             :                             }
    2075             :                         }
    2076             :                     }
    2077           0 :                 }
    2078             :             }
    2079           0 :             catch(SQLException&)
    2080             :             {
    2081             :                 OSL_FAIL("getMaxTablesInSelect!");
    2082           0 :             }
    2083             :         }
    2084             :         while ( false );
    2085             : 
    2086             :         // New Undo-Actions were created in the Manager by the regeneration
    2087           0 :         rController.ClearUndoManager();
    2088           0 :         _pSelectionBrw->Invalidate();
    2089           0 :         return eErrorCode;
    2090             :     }
    2091             :     /** fillSelectSubList
    2092             :         @return
    2093             :             <TRUE/> when columns could be inserted otherwise <FALSE/>
    2094             :     */
    2095           0 :     SqlParseError fillSelectSubList(    OQueryDesignView* _pView,
    2096             :                                 OJoinTableView::OTableWindowMap* _pTabList)
    2097             :     {
    2098           0 :         SqlParseError eErrorCode = eOk;
    2099           0 :         bool bFirstField = true;
    2100           0 :         OUString sAsterisk("*");
    2101           0 :         OJoinTableView::OTableWindowMap::iterator aIter = _pTabList->begin();
    2102           0 :         OJoinTableView::OTableWindowMap::iterator aEnd = _pTabList->end();
    2103           0 :         for(;aIter != aEnd && eOk == eErrorCode ;++aIter)
    2104             :         {
    2105           0 :             OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
    2106           0 :             OTableFieldDescRef  aInfo = new OTableFieldDesc();
    2107           0 :             if (pTabWin->ExistsField( sAsterisk, aInfo ))
    2108             :             {
    2109           0 :                 eErrorCode = _pView->InsertField(aInfo, true, bFirstField);
    2110           0 :                 bFirstField = false;
    2111             :             }
    2112           0 :         }
    2113           0 :         return eErrorCode;
    2114             :     }
    2115           0 :     SqlParseError InstallFields(OQueryDesignView* _pView,
    2116             :                                 const ::connectivity::OSQLParseNode* pNode,
    2117             :                                 OJoinTableView::OTableWindowMap* pTabList )
    2118             :     {
    2119           0 :         if( pNode==0 || !SQL_ISRULE(pNode,select_statement))
    2120           0 :             return eNoSelectStatement;
    2121             : 
    2122           0 :         ::connectivity::OSQLParseNode* pParseTree = pNode->getChild(2); // selection
    2123           0 :         bool bFirstField = true;    // When initializing, the first field must be reactivated
    2124             : 
    2125           0 :         SqlParseError eErrorCode = eOk;
    2126             : 
    2127           0 :         if ( pParseTree->isRule() && SQL_ISPUNCTUATION(pParseTree->getChild(0),"*") )
    2128             :         {
    2129             :             // SELECT * ...
    2130           0 :             eErrorCode = fillSelectSubList(_pView,pTabList);
    2131             :         }
    2132           0 :         else if (SQL_ISRULE(pParseTree,scalar_exp_commalist) )
    2133             :         {
    2134             :             // SELECT column, ...
    2135           0 :             OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    2136           0 :             Reference< XConnection> xConnection = rController.getConnection();
    2137             : 
    2138           0 :             OUString aColumnName,aTableRange;
    2139           0 :             for (sal_uInt32 i = 0; i < pParseTree->count() && eOk == eErrorCode ; ++i)
    2140             :             {
    2141           0 :                 ::connectivity::OSQLParseNode * pColumnRef = pParseTree->getChild(i);
    2142             : 
    2143             :                 do {
    2144             : 
    2145           0 :                 if ( SQL_ISRULE(pColumnRef,select_sublist) )
    2146             :                 {
    2147           0 :                      eErrorCode = fillSelectSubList(_pView,pTabList);
    2148           0 :                      break;
    2149             :                 }
    2150             : 
    2151           0 :                 if ( SQL_ISRULE(pColumnRef,derived_column) )
    2152             :                 {
    2153           0 :                     OUString aColumnAlias(connectivity::OSQLParseTreeIterator::getColumnAlias(pColumnRef)); // might be empty
    2154           0 :                     pColumnRef = pColumnRef->getChild(0);
    2155           0 :                     OTableFieldDescRef aInfo = new OTableFieldDesc();
    2156             : 
    2157           0 :                     if (    pColumnRef->getKnownRuleID() != OSQLParseNode::subquery &&
    2158           0 :                             pColumnRef->count() == 3 &&
    2159           0 :                             SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") &&
    2160           0 :                             SQL_ISPUNCTUATION(pColumnRef->getChild(2),")")
    2161             :                         )
    2162           0 :                         pColumnRef = pColumnRef->getChild(1);
    2163             : 
    2164           0 :                     if (SQL_ISRULE(pColumnRef,column_ref))
    2165             :                     {
    2166           0 :                         InsertColumnRef(_pView,pColumnRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
    2167           0 :                         eErrorCode = _pView->InsertField(aInfo, true, bFirstField);
    2168           0 :                         bFirstField = false;
    2169             :                     }
    2170           0 :                     else if(SQL_ISRULEOR3(pColumnRef, general_set_fct, set_fct_spec, position_exp)  ||
    2171           0 :                               SQL_ISRULEOR3(pColumnRef, extract_exp, fold, char_substring_fct)      ||
    2172           0 :                               SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct))
    2173             :                     {
    2174           0 :                         OUString aColumns;
    2175             :                         pColumnRef->parseNodeToPredicateStr(aColumns,
    2176             :                                                             xConnection,
    2177             :                                                             rController.getNumberFormatter(),
    2178             :                                                             _pView->getLocale(),
    2179           0 :                                                             static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
    2180           0 :                                                             &rController.getParser().getContext());
    2181             : 
    2182           0 :                         sal_Int32 nFunctionType = FKT_NONE;
    2183           0 :                         ::connectivity::OSQLParseNode* pParamRef = NULL;
    2184           0 :                         sal_Int32 nColumnRefPos = pColumnRef->count() - 2;
    2185           0 :                         if ( nColumnRefPos >= 0 && static_cast<sal_uInt32>(nColumnRefPos) < pColumnRef->count() )
    2186           0 :                             pParamRef = pColumnRef->getChild(nColumnRefPos);
    2187             : 
    2188           0 :                         if ( SQL_ISRULE(pColumnRef,general_set_fct)
    2189           0 :                             && pParamRef &&  SQL_ISRULE(pParamRef,column_ref) )
    2190             :                         {
    2191             :                             // Check the parameters for Column references
    2192           0 :                             InsertColumnRef(_pView,pParamRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
    2193             :                         }
    2194           0 :                         else if ( SQL_ISRULE(pColumnRef,general_set_fct) )
    2195             :                         {
    2196           0 :                             if ( pParamRef && pParamRef->getTokenValue().toChar() == '*' )
    2197             :                             {
    2198           0 :                                 OJoinTableView::OTableWindowMap::iterator             aIter = pTabList->begin();
    2199           0 :                                 const OJoinTableView::OTableWindowMap::const_iterator aEnd  = pTabList->end();
    2200           0 :                                 for(;aIter != aEnd;++aIter)
    2201             :                                 {
    2202           0 :                                     OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
    2203           0 :                                     if (pTabWin->ExistsField( OUString("*"), aInfo ))
    2204             :                                     {
    2205           0 :                                         aInfo->SetAlias(OUString());
    2206           0 :                                         aInfo->SetTable(OUString());
    2207           0 :                                         break;
    2208             :                                     }
    2209             :                                 }
    2210             :                             }
    2211             :                             else
    2212             :                             {
    2213           0 :                                 OUString sFieldName = aColumns;
    2214           0 :                                 if ( pParamRef )
    2215             :                                 {   // we got an aggregate function but without column name inside
    2216             :                                     // so we set the whole argument of the function as field name
    2217           0 :                                     nFunctionType |= FKT_NUMERIC;
    2218           0 :                                     sFieldName = "";
    2219             :                                     pParamRef->parseNodeToStr(  sFieldName,
    2220             :                                                         xConnection,
    2221           0 :                                                         &rController.getParser().getContext(),
    2222             :                                                         true,
    2223           0 :                                                         true); // quote is to true because we need quoted elements inside the function
    2224             :                                 }
    2225           0 :                                 aInfo->SetDataType(DataType::DOUBLE);
    2226           0 :                                 aInfo->SetFieldType(TAB_NORMAL_FIELD);
    2227           0 :                                 aInfo->SetField(sFieldName);
    2228             :                             }
    2229           0 :                             aInfo->SetTabWindow(NULL);
    2230           0 :                             aInfo->SetFieldAlias(aColumnAlias);
    2231             :                         }
    2232             :                         else
    2233             :                         {
    2234           0 :                             _pView->fillFunctionInfo(pColumnRef,aColumns,aInfo);
    2235           0 :                             aInfo->SetFieldAlias(aColumnAlias);
    2236             :                         }
    2237             : 
    2238           0 :                         if ( SQL_ISRULE(pColumnRef,general_set_fct) )
    2239             :                         {
    2240           0 :                             aInfo->SetFunctionType(nFunctionType|FKT_AGGREGATE);
    2241           0 :                             OUString aCol(aColumns);
    2242           0 :                             aInfo->SetFunction(comphelper::string::stripEnd(aCol.getToken(0,'('), ' '));
    2243             :                         }
    2244             :                         else
    2245           0 :                             aInfo->SetFunctionType(nFunctionType|FKT_OTHER);
    2246             : 
    2247           0 :                         eErrorCode = _pView->InsertField(aInfo, true, bFirstField);
    2248           0 :                         bFirstField = false;
    2249             :                     }
    2250             :                     else
    2251             :                     {
    2252           0 :                         OUString aColumns;
    2253             :                         pColumnRef->parseNodeToStr( aColumns,
    2254             :                                                     xConnection,
    2255           0 :                                                     &rController.getParser().getContext(),
    2256             :                                                     true,
    2257           0 :                                                     true); // quote is to true because we need quoted elements inside the function
    2258             : 
    2259           0 :                         aInfo->SetTabWindow( NULL );
    2260             : 
    2261             :                         // since we support queries in queries, the thingie might belong to an existing "table"
    2262           0 :                         OQueryTableWindow* pExistingTable = lcl_findColumnInTables( aColumns, *pTabList, aInfo );
    2263           0 :                         if ( pExistingTable )
    2264             :                         {
    2265           0 :                             aInfo->SetTabWindow( pExistingTable );
    2266           0 :                             aInfo->SetTable( pExistingTable->GetTableName() );
    2267           0 :                             aInfo->SetAlias( pExistingTable->GetAliasName() );
    2268             :                         }
    2269             : 
    2270           0 :                         aInfo->SetDataType(DataType::DOUBLE);
    2271           0 :                         aInfo->SetFieldType(TAB_NORMAL_FIELD);
    2272           0 :                         aInfo->SetField(aColumns);
    2273           0 :                         aInfo->SetFieldAlias(aColumnAlias);
    2274           0 :                         aInfo->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
    2275             : 
    2276           0 :                         eErrorCode = _pView->InsertField(aInfo, true, bFirstField);
    2277           0 :                         bFirstField = false;
    2278             :                     }
    2279             : 
    2280           0 :                     break;
    2281             :                 }
    2282             : 
    2283             :                 OSL_FAIL( "InstallFields: don't know how to interpret this parse node!" );
    2284             : 
    2285             :                 } while ( false );
    2286           0 :             }
    2287             :         }
    2288             :         else
    2289           0 :             eErrorCode = eStatementTooComplex;
    2290             : 
    2291           0 :         return eErrorCode;
    2292             :     }
    2293           0 :     SqlParseError GetOrderCriteria( OQueryDesignView* _pView,
    2294             :                             OSelectionBrowseBox* _pSelectionBrw,
    2295             :                             const ::connectivity::OSQLParseNode* pParseRoot )
    2296             :     {
    2297           0 :         SqlParseError eErrorCode = eOk;
    2298           0 :         if (!pParseRoot->getChild(3)->getChild(ORDER_BY_CHILD_POS)->isLeaf())
    2299             :         {
    2300           0 :             ::connectivity::OSQLParseNode* pNode = pParseRoot->getChild(3)->getChild(ORDER_BY_CHILD_POS)->getChild(2);
    2301           0 :             ::connectivity::OSQLParseNode* pParamRef = NULL;
    2302             : 
    2303           0 :             OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    2304             :             EOrderDir eOrderDir;
    2305           0 :             for( sal_uInt32 i=0 ; i<pNode->count() ; i++ )
    2306             :             {
    2307           0 :                 OTableFieldDescRef aDragLeft = new OTableFieldDesc();
    2308           0 :                 eOrderDir = ORDER_ASC;
    2309           0 :                 ::connectivity::OSQLParseNode*  pChild = pNode->getChild( i );
    2310             : 
    2311           0 :                 if (SQL_ISTOKEN( pChild->getChild(1), DESC ) )
    2312           0 :                     eOrderDir = ORDER_DESC;
    2313             : 
    2314           0 :                 ::connectivity::OSQLParseNode* pArgument = pChild->getChild(0);
    2315             : 
    2316           0 :                 if(SQL_ISRULE(pArgument,column_ref))
    2317             :                 {
    2318           0 :                     if( eOk == FillDragInfo(_pView,pArgument,aDragLeft))
    2319           0 :                         _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i);
    2320             :                     else // it could be a alias name for a field
    2321             :                     {
    2322           0 :                         OUString aTableRange,aColumnName;
    2323           0 :                         ::connectivity::OSQLParseTreeIterator& rParseIter = rController.getParseIterator();
    2324           0 :                         rParseIter.getColumnRange( pArgument, aColumnName, aTableRange );
    2325             : 
    2326           0 :                         OTableFields& aList = rController.getTableFieldDesc();
    2327           0 :                         OTableFields::iterator aIter = aList.begin();
    2328           0 :                         OTableFields::iterator aEnd = aList.end();
    2329           0 :                         for(;aIter != aEnd;++aIter)
    2330             :                         {
    2331           0 :                             OTableFieldDescRef pEntry = *aIter;
    2332           0 :                             if(pEntry.is() && pEntry->GetFieldAlias() == aColumnName)
    2333           0 :                                 pEntry->SetOrderDir( eOrderDir );
    2334           0 :                         }
    2335             :                     }
    2336             :                 }
    2337           0 :                 else if(SQL_ISRULE(pArgument, general_set_fct ) &&
    2338           0 :                         SQL_ISRULE(pParamRef = pArgument->getChild(pArgument->count()-2),column_ref) &&
    2339           0 :                         eOk == FillDragInfo(_pView,pParamRef,aDragLeft))
    2340           0 :                     _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i );
    2341           0 :                 else if( SQL_ISRULE(pArgument, set_fct_spec ) )
    2342             :                 {
    2343             : 
    2344           0 :                     Reference< XConnection> xConnection = rController.getConnection();
    2345           0 :                     if(xConnection.is())
    2346             :                     {
    2347           0 :                         OUString sCondition;
    2348             :                         pArgument->parseNodeToPredicateStr(sCondition,
    2349             :                                                             xConnection,
    2350             :                                                             rController.getNumberFormatter(),
    2351             :                                                             _pView->getLocale(),
    2352           0 :                                                             static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
    2353           0 :                                                             &rController.getParser().getContext());
    2354           0 :                         _pView->fillFunctionInfo(pArgument,sCondition,aDragLeft);
    2355           0 :                         aDragLeft->SetFunctionType(FKT_OTHER);
    2356           0 :                         aDragLeft->SetOrderDir(eOrderDir);
    2357           0 :                         aDragLeft->SetVisible(false);
    2358           0 :                         _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i );
    2359             :                     }
    2360             :                     else
    2361           0 :                         eErrorCode = eColumnNotFound;
    2362             :                 }
    2363             :                 else
    2364           0 :                     eErrorCode = eColumnNotFound;
    2365           0 :             }
    2366             :         }
    2367           0 :         return eErrorCode;
    2368             :     }
    2369           0 :     SqlParseError GetHavingCriteria(    OQueryDesignView* _pView,
    2370             :                             OSelectionBrowseBox* _pSelectionBrw,
    2371             :                             const ::connectivity::OSQLParseNode* pSelectRoot,
    2372             :                             sal_uInt16& rLevel )
    2373             :     {
    2374           0 :         SqlParseError eErrorCode = eOk;
    2375           0 :         if (!pSelectRoot->getChild(3)->getChild(3)->isLeaf())
    2376           0 :             eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSelectRoot->getChild(3)->getChild(3)->getChild(1),rLevel, true);
    2377           0 :         return eErrorCode;
    2378             :     }
    2379           0 :     SqlParseError GetGroupCriteria( OQueryDesignView* _pView,
    2380             :                             OSelectionBrowseBox* _pSelectionBrw,
    2381             :                             const ::connectivity::OSQLParseNode* pSelectRoot )
    2382             :     {
    2383           0 :         SqlParseError eErrorCode = eOk;
    2384           0 :         if (!pSelectRoot->getChild(3)->getChild(2)->isLeaf()) // opt_group_by_clause
    2385             :         {
    2386           0 :             OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
    2387           0 :             ::connectivity::OSQLParseNode* pGroupBy = pSelectRoot->getChild(3)->getChild(2)->getChild(2);
    2388             : 
    2389           0 :             for( sal_uInt32 i=0 ; i < pGroupBy->count() && eOk == eErrorCode; ++i )
    2390             :             {
    2391           0 :                 OTableFieldDescRef aDragInfo = new OTableFieldDesc();
    2392           0 :                 ::connectivity::OSQLParseNode* pParamRef = NULL;
    2393           0 :                 ::connectivity::OSQLParseNode* pArgument = pGroupBy->getChild( i );
    2394           0 :                 if(SQL_ISRULE(pArgument,column_ref))
    2395             :                 {
    2396           0 :                     if ( eOk == (eErrorCode = FillDragInfo(_pView,pArgument,aDragInfo)) )
    2397             :                     {
    2398           0 :                         aDragInfo->SetGroupBy(true);
    2399           0 :                         _pSelectionBrw->AddGroupBy(aDragInfo,i);
    2400             :                     }
    2401             :                 }
    2402           0 :                 else if(SQL_ISRULE(pArgument, general_set_fct ) &&
    2403           0 :                         SQL_ISRULE(pParamRef = pArgument->getChild(pArgument->count()-2),column_ref) &&
    2404           0 :                         eOk == FillDragInfo(_pView,pParamRef,aDragInfo))
    2405             :                 {
    2406           0 :                     aDragInfo->SetGroupBy(true);
    2407           0 :                     _pSelectionBrw->AddGroupBy( aDragInfo, i );
    2408             :                 }
    2409           0 :                 else if( SQL_ISRULE(pArgument, set_fct_spec ) )
    2410             :                 {
    2411           0 :                     Reference< XConnection> xConnection = rController.getConnection();
    2412           0 :                     if(xConnection.is())
    2413             :                     {
    2414           0 :                         OUString sGroupByExpression;
    2415             :                         pArgument->parseNodeToStr(  sGroupByExpression,
    2416             :                                                     xConnection,
    2417           0 :                                                     &rController.getParser().getContext(),
    2418             :                                                     true,
    2419           0 :                                                     true); // quote is to true because we need quoted elements inside the function
    2420           0 :                         _pView->fillFunctionInfo(pArgument,sGroupByExpression,aDragInfo);
    2421           0 :                         aDragInfo->SetFunctionType(FKT_OTHER);
    2422           0 :                         aDragInfo->SetGroupBy(true);
    2423           0 :                         aDragInfo->SetVisible(false);
    2424           0 :                         _pSelectionBrw->AddGroupBy( aDragInfo, i );
    2425             :                     }
    2426             :                     else
    2427           0 :                         eErrorCode = eColumnNotFound;
    2428             :                 }
    2429           0 :             }
    2430             :         }
    2431           0 :         return eErrorCode;
    2432             :     }
    2433             : 
    2434           0 :     OUString getParseErrorMessage( SqlParseError _eErrorCode )
    2435             :     {
    2436             :         sal_uInt16 nResId;
    2437           0 :         switch(_eErrorCode)
    2438             :         {
    2439             :             case eIllegalJoin:
    2440           0 :                 nResId = STR_QRY_ILLEGAL_JOIN;
    2441           0 :                 break;
    2442             :             case eStatementTooLong:
    2443           0 :                 nResId = STR_QRY_TOO_LONG_STATEMENT;
    2444           0 :                 break;
    2445             :             case eNoConnection:
    2446           0 :                 nResId = STR_QRY_SYNTAX;
    2447           0 :                 break;
    2448             :             case eNoSelectStatement:
    2449           0 :                 nResId = STR_QRY_NOSELECT;
    2450           0 :                 break;
    2451             :             case eColumnInLikeNotFound:
    2452           0 :                 nResId = STR_QRY_SYNTAX;
    2453           0 :                 break;
    2454             :             case eNoColumnInLike:
    2455           0 :                 nResId = STR_QRY_SYNTAX;
    2456           0 :                 break;
    2457             :             case eColumnNotFound:
    2458           0 :                 nResId = STR_QRY_SYNTAX;
    2459           0 :                 break;
    2460             :             case eNativeMode:
    2461           0 :                 nResId = STR_QRY_NATIVE;
    2462           0 :                 break;
    2463             :             case eTooManyTables:
    2464           0 :                 nResId = STR_QRY_TOO_MANY_TABLES;
    2465           0 :                 break;
    2466             :             case eTooManyConditions:
    2467           0 :                 nResId = STR_QRY_TOOMANYCOND;
    2468           0 :                 break;
    2469             :             case eTooManyColumns:
    2470           0 :                 nResId = STR_QRY_TOO_MANY_COLUMNS;
    2471           0 :                 break;
    2472             :             case eStatementTooComplex:
    2473           0 :                 nResId = STR_QRY_TOOCOMPLEX;
    2474           0 :                 break;
    2475             :             default:
    2476           0 :                 nResId = STR_QRY_SYNTAX;
    2477           0 :                 break;
    2478             :         }
    2479             :         ;
    2480           0 :         return OUString( ModuleRes( nResId ) );
    2481             :     }
    2482             : 
    2483             : }
    2484             : 
    2485             : // end of anonymouse namespace
    2486             : 
    2487           0 : OQueryDesignView::OQueryDesignView( OQueryContainerWindow* _pParent,
    2488             :                                     OQueryController& _rController,
    2489             :                                     const Reference< XComponentContext >& _rxContext)
    2490             :     :OQueryView( _pParent, _rController, _rxContext )
    2491             :     ,m_aSplitter( this )
    2492             :     ,m_eChildFocus(NONE)
    2493           0 :     ,m_bInSplitHandler( false )
    2494             : {
    2495             : 
    2496             :     try
    2497             :     {
    2498           0 :         SvtSysLocale aSysLocale;
    2499           0 :         m_aLocale = aSysLocale.GetLanguageTag().getLocale();
    2500           0 :         m_sDecimalSep = aSysLocale.GetLocaleData().getNumDecimalSep();
    2501             :     }
    2502           0 :     catch(Exception&)
    2503             :     {
    2504             :     }
    2505             : 
    2506           0 :     m_pSelectionBox = new OSelectionBrowseBox(this);
    2507             : 
    2508           0 :     setNoneVisbleRow(static_cast<OQueryController&>(getController()).getVisibleRows());
    2509           0 :     m_pSelectionBox->Show();
    2510             :     // setup Splitter
    2511           0 :     m_aSplitter.SetSplitHdl(LINK(this, OQueryDesignView,SplitHdl));
    2512           0 :     m_aSplitter.Show();
    2513             : 
    2514           0 : }
    2515             : 
    2516           0 : OQueryDesignView::~OQueryDesignView()
    2517             : {
    2518           0 :     if ( m_pTableView )
    2519           0 :         ::dbaui::notifySystemWindow(this,m_pTableView,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
    2520           0 :     boost::scoped_ptr<vcl::Window> aTemp(m_pSelectionBox);
    2521           0 :     m_pSelectionBox = NULL;
    2522             : 
    2523           0 : }
    2524             : 
    2525           0 : IMPL_LINK( OQueryDesignView, SplitHdl, void*, /*p*/ )
    2526             : {
    2527           0 :     if (!getController().isReadOnly())
    2528             :     {
    2529           0 :         m_bInSplitHandler = true;
    2530           0 :         m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),m_aSplitter.GetSplitPosPixel() ) );
    2531           0 :         static_cast<OQueryController&>(getController()).setSplitPos(m_aSplitter.GetSplitPosPixel());
    2532           0 :         static_cast<OQueryController&>(getController()).setModified( sal_True );
    2533           0 :         Resize();
    2534           0 :         m_bInSplitHandler = true;
    2535             :     }
    2536           0 :     return 0L;
    2537             : }
    2538             : 
    2539           0 : void OQueryDesignView::Construct()
    2540             : {
    2541           0 :     m_pTableView = new OQueryTableView(m_pScrollWindow,this);
    2542           0 :     ::dbaui::notifySystemWindow(this,m_pTableView,::comphelper::mem_fun(&TaskPaneList::AddWindow));
    2543           0 :     OQueryView::Construct();
    2544           0 : }
    2545             : 
    2546           0 : void OQueryDesignView::initialize()
    2547             : {
    2548           0 :     if(static_cast<OQueryController&>(getController()).getSplitPos() != -1)
    2549             :     {
    2550           0 :         m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),static_cast<OQueryController&>(getController()).getSplitPos() ) );
    2551           0 :         m_aSplitter.SetSplitPosPixel(static_cast<OQueryController&>(getController()).getSplitPos());
    2552             :     }
    2553           0 :     m_pSelectionBox->initialize();
    2554           0 :     reset();
    2555           0 : }
    2556             : 
    2557           0 : void OQueryDesignView::resizeDocumentView(Rectangle& _rPlayground)
    2558             : {
    2559           0 :     Point aPlaygroundPos( _rPlayground.TopLeft() );
    2560           0 :     Size aPlaygroundSize( _rPlayground.GetSize() );
    2561             : 
    2562             :     // calc the split pos, and forward it to the controller
    2563           0 :     sal_Int32 nSplitPos = static_cast<OQueryController&>(getController()).getSplitPos();
    2564           0 :     if ( 0 != aPlaygroundSize.Height() )
    2565             :     {
    2566           0 :         if  (   ( -1 == nSplitPos )
    2567           0 :             ||  ( nSplitPos >= aPlaygroundSize.Height() )
    2568             :             )
    2569             :         {
    2570             :             // let the selection browse box determine an optimal size
    2571           0 :             Size aSelectionBoxSize = m_pSelectionBox->CalcOptimalSize( aPlaygroundSize );
    2572           0 :             nSplitPos = aPlaygroundSize.Height() - aSelectionBoxSize.Height() - m_aSplitter.GetSizePixel().Height();
    2573             :             // still an invalid size?
    2574           0 :             if ( nSplitPos == -1 || nSplitPos >= aPlaygroundSize.Height() )
    2575           0 :                 nSplitPos = sal_Int32(aPlaygroundSize.Height()*0.6);
    2576             : 
    2577           0 :             static_cast<OQueryController&>(getController()).setSplitPos(nSplitPos);
    2578             :         }
    2579             : 
    2580           0 :         if ( !m_bInSplitHandler )
    2581             :         {   // the resize is triggered by something else than the split handler
    2582             :             // our main focus is to try to preserve the size of the selectionbrowse box
    2583           0 :             Size aSelBoxSize = m_pSelectionBox->GetSizePixel();
    2584           0 :             if ( aSelBoxSize.Height() )
    2585             :             {
    2586             :                 // keep the size of the sel box constant
    2587           0 :                 nSplitPos = aPlaygroundSize.Height() - m_aSplitter.GetSizePixel().Height() - aSelBoxSize.Height();
    2588             : 
    2589             :                 // and if the box is smaller than the optimal size, try to do something about it
    2590           0 :                 Size aSelBoxOptSize = m_pSelectionBox->CalcOptimalSize( aPlaygroundSize );
    2591           0 :                 if ( aSelBoxOptSize.Height() > aSelBoxSize.Height() )
    2592             :                 {
    2593           0 :                     nSplitPos = aPlaygroundSize.Height() - m_aSplitter.GetSizePixel().Height() - aSelBoxOptSize.Height();
    2594             :                 }
    2595             : 
    2596           0 :                 static_cast< OQueryController& >(getController()).setSplitPos( nSplitPos );
    2597             :             }
    2598             :         }
    2599             :     }
    2600             : 
    2601             :     // normalize the split pos
    2602           0 :     Point   aSplitPos       = Point( _rPlayground.Left(), nSplitPos );
    2603           0 :     Size    aSplitSize      = Size( _rPlayground.GetSize().Width(), m_aSplitter.GetSizePixel().Height() );
    2604             : 
    2605           0 :     if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
    2606           0 :         aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
    2607             : 
    2608           0 :     if( aSplitPos.Y() <= aPlaygroundPos.Y() )
    2609           0 :         aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.2);
    2610             : 
    2611             :     // position the table
    2612           0 :     Size aTableViewSize(aPlaygroundSize.Width(), aSplitPos.Y() - aPlaygroundPos.Y());
    2613           0 :     m_pScrollWindow->SetPosSizePixel(aPlaygroundPos, aTableViewSize);
    2614             : 
    2615             :     // position the selection browse box
    2616           0 :     Point aPos( aPlaygroundPos.X(), aSplitPos.Y() + aSplitSize.Height() );
    2617           0 :     m_pSelectionBox->SetPosSizePixel( aPos, Size( aPlaygroundSize.Width(), aPlaygroundSize.Height() - aSplitSize.Height() - aTableViewSize.Height() ));
    2618             : 
    2619             :     // set the size of the splitter
    2620           0 :     m_aSplitter.SetPosSizePixel( aSplitPos, aSplitSize );
    2621           0 :     m_aSplitter.SetDragRectPixel( _rPlayground );
    2622             : 
    2623             :     // just for completeness: there is no space left, we occupied it all ...
    2624           0 :     _rPlayground.SetPos( _rPlayground.BottomRight() );
    2625           0 :     _rPlayground.SetSize( Size( 0, 0 ) );
    2626           0 : }
    2627             : 
    2628           0 : void OQueryDesignView::setReadOnly(bool _bReadOnly)
    2629             : {
    2630           0 :     m_pSelectionBox->SetReadOnly(_bReadOnly);
    2631           0 : }
    2632             : 
    2633           0 : void OQueryDesignView::clear()
    2634             : {
    2635           0 :     m_pSelectionBox->ClearAll(); // clear the whole selection
    2636           0 :     m_pTableView->ClearAll();
    2637           0 : }
    2638             : 
    2639           0 : void OQueryDesignView::setStatement(const OUString& /*_rsStatement*/)
    2640             : {
    2641           0 : }
    2642             : 
    2643           0 : void OQueryDesignView::copy()
    2644             : {
    2645           0 :     if( m_eChildFocus == SELECTION)
    2646           0 :         m_pSelectionBox->copy();
    2647           0 : }
    2648             : 
    2649           0 : bool OQueryDesignView::isCutAllowed()
    2650             : {
    2651           0 :     bool bAllowed = false;
    2652           0 :     if ( SELECTION == m_eChildFocus )
    2653           0 :         bAllowed = m_pSelectionBox->isCutAllowed();
    2654           0 :     return bAllowed;
    2655             : }
    2656             : 
    2657           0 : bool OQueryDesignView::isPasteAllowed()
    2658             : {
    2659           0 :     bool bAllowed = false;
    2660           0 :     if ( SELECTION == m_eChildFocus )
    2661           0 :         bAllowed = m_pSelectionBox->isPasteAllowed();
    2662           0 :     return bAllowed;
    2663             : }
    2664             : 
    2665           0 : bool OQueryDesignView::isCopyAllowed()
    2666             : {
    2667           0 :     bool bAllowed = false;
    2668           0 :     if ( SELECTION == m_eChildFocus )
    2669           0 :         bAllowed = m_pSelectionBox->isCopyAllowed();
    2670           0 :     return bAllowed;
    2671             : }
    2672             : 
    2673           0 : void OQueryDesignView::stopTimer()
    2674             : {
    2675           0 :     m_pSelectionBox->stopTimer();
    2676           0 : }
    2677             : 
    2678           0 : void OQueryDesignView::startTimer()
    2679             : {
    2680           0 :     m_pSelectionBox->startTimer();
    2681           0 : }
    2682             : 
    2683           0 : void OQueryDesignView::cut()
    2684             : {
    2685           0 :     if( m_eChildFocus == SELECTION)
    2686             :     {
    2687           0 :         m_pSelectionBox->cut();
    2688           0 :         static_cast<OQueryController&>(getController()).setModified(sal_True);
    2689             :     }
    2690           0 : }
    2691             : 
    2692           0 : void OQueryDesignView::paste()
    2693             : {
    2694           0 :     if( m_eChildFocus == SELECTION)
    2695             :     {
    2696           0 :         m_pSelectionBox->paste();
    2697           0 :         static_cast<OQueryController&>(getController()).setModified(sal_True);
    2698             :     }
    2699           0 : }
    2700             : 
    2701           0 : void OQueryDesignView::TableDeleted(const OUString& rAliasName)
    2702             : {
    2703             :     // message that the table was removed from the window
    2704           0 :     DeleteFields(rAliasName);
    2705           0 :     static_cast<OQueryController&>(getController()).InvalidateFeature(ID_BROWSER_ADDTABLE); // inform the view again
    2706           0 : }
    2707             : 
    2708           0 : void OQueryDesignView::DeleteFields( const OUString& rAliasName )
    2709             : {
    2710           0 :     m_pSelectionBox->DeleteFields( rAliasName );
    2711           0 : }
    2712             : 
    2713           0 : bool OQueryDesignView::HasFieldByAliasName(const OUString& rFieldName, OTableFieldDescRef& rInfo)  const
    2714             : {
    2715           0 :     return m_pSelectionBox->HasFieldByAliasName( rFieldName, rInfo);
    2716             : }
    2717             : 
    2718           0 : SqlParseError OQueryDesignView::InsertField( const OTableFieldDescRef& rInfo, bool bVis, bool bActivate)
    2719             : {
    2720           0 :     return m_pSelectionBox->InsertField( rInfo, BROWSER_INVALIDID,bVis, bActivate ).is() ? eOk : eTooManyColumns;
    2721             : }
    2722             : 
    2723           0 : sal_Int32 OQueryDesignView::getColWidth(sal_uInt16 _nColPos) const
    2724             : {
    2725           0 :     static sal_Int32 s_nDefaultWidth = GetTextWidth(OUString("0")) * 15;
    2726           0 :     sal_Int32 nWidth = static_cast<OQueryController&>(getController()).getColWidth(_nColPos);
    2727           0 :     if ( !nWidth )
    2728           0 :         nWidth = s_nDefaultWidth;
    2729           0 :     return nWidth;
    2730             : }
    2731             : 
    2732           0 : void OQueryDesignView::fillValidFields(const OUString& sAliasName, ComboBox* pFieldList)
    2733             : {
    2734             :     OSL_ENSURE(pFieldList != NULL, "OQueryDesignView::FillValidFields : What the hell do you think I can do with a NULL-ptr ? This will crash !");
    2735           0 :     pFieldList->Clear();
    2736             : 
    2737           0 :     bool bAllTables = sAliasName.isEmpty();
    2738             : 
    2739           0 :     OJoinTableView::OTableWindowMap& rTabWins = m_pTableView->GetTabWinMap();
    2740           0 :     OUString strCurrentPrefix;
    2741           0 :     ::std::vector< OUString> aFields;
    2742           0 :     OJoinTableView::OTableWindowMap::iterator aIter = rTabWins.begin();
    2743           0 :     OJoinTableView::OTableWindowMap::iterator aEnd  = rTabWins.end();
    2744           0 :     for(;aIter != aEnd;++aIter)
    2745             :     {
    2746           0 :         OQueryTableWindow* pCurrentWin = static_cast<OQueryTableWindow*>(aIter->second);
    2747           0 :         if (bAllTables || (pCurrentWin->GetAliasName() == sAliasName))
    2748             :         {
    2749           0 :             strCurrentPrefix = pCurrentWin->GetAliasName();
    2750           0 :             strCurrentPrefix += ".";
    2751             : 
    2752           0 :             pCurrentWin->EnumValidFields(aFields);
    2753             : 
    2754           0 :             ::std::vector< OUString>::iterator aStrIter = aFields.begin();
    2755           0 :             ::std::vector< OUString>::iterator aStrEnd = aFields.end();
    2756           0 :             for(;aStrIter != aStrEnd;++aStrIter)
    2757             :             {
    2758           0 :                 if (bAllTables || aStrIter->toChar() == '*')
    2759           0 :                     pFieldList->InsertEntry(OUString(strCurrentPrefix) += *aStrIter);
    2760             :                 else
    2761           0 :                     pFieldList->InsertEntry(*aStrIter);
    2762             :             }
    2763             : 
    2764           0 :             if (!bAllTables)
    2765             :                 // this means that I came into this block because the table name was exactly what I was looking for so I can end here
    2766             :                 // (and I prevent that fields get added more than once, if a table is repeated in TabWin)
    2767           0 :                 break;
    2768             :         }
    2769           0 :     }
    2770           0 : }
    2771             : 
    2772           0 : bool OQueryDesignView::PreNotify(NotifyEvent& rNEvt)
    2773             : {
    2774           0 :     switch (rNEvt.GetType())
    2775             :     {
    2776             :         case EVENT_GETFOCUS:
    2777             : #if OSL_DEBUG_LEVEL > 0
    2778             :             {
    2779             :                 vcl::Window* pFocus = Application::GetFocusWindow();
    2780             :                 (void)pFocus;
    2781             :             }
    2782             : #endif
    2783             : 
    2784           0 :             if ( m_pSelectionBox && m_pSelectionBox->HasChildPathFocus() )
    2785           0 :                 m_eChildFocus = SELECTION;
    2786             :             else
    2787           0 :                 m_eChildFocus = TABLEVIEW;
    2788           0 :             break;
    2789             :     }
    2790             : 
    2791           0 :     return OQueryView::PreNotify(rNEvt);
    2792             : }
    2793             : 
    2794             : // check if the statement is correct when not returning false
    2795           0 : bool OQueryDesignView::checkStatement()
    2796             : {
    2797           0 :     bool bRet = true;
    2798           0 :     if ( m_pSelectionBox )
    2799           0 :         bRet = m_pSelectionBox->Save(); // an error occurred so we return no
    2800           0 :     return bRet;
    2801             : }
    2802             : 
    2803           0 : OUString OQueryDesignView::getStatement()
    2804             : {
    2805           0 :     OQueryController& rController = static_cast<OQueryController&>(getController());
    2806           0 :     m_rController.clearError();
    2807             :     // used for fields which aren't any longer in the statement
    2808           0 :     OTableFields& rUnUsedFields = rController.getUnUsedFields();
    2809           0 :     OTableFields().swap( rUnUsedFields );
    2810             : 
    2811             :     // create the select columns
    2812           0 :     sal_uInt32 nFieldcount = 0;
    2813           0 :     OTableFields& rFieldList = rController.getTableFieldDesc();
    2814           0 :     OTableFields::iterator aIter = rFieldList.begin();
    2815           0 :     OTableFields::iterator aEnd = rFieldList.end();
    2816           0 :     for(;aIter != aEnd;++aIter)
    2817             :     {
    2818           0 :         OTableFieldDescRef pEntryField = *aIter;
    2819           0 :         if (!pEntryField->GetField().isEmpty() && pEntryField->IsVisible() )
    2820           0 :             ++nFieldcount;
    2821           0 :         else if (!pEntryField->GetField().isEmpty()            &&
    2822           0 :                 !pEntryField->HasCriteria()                 &&
    2823           0 :                 pEntryField->isNoneFunction()               &&
    2824           0 :                 pEntryField->GetOrderDir() == ORDER_NONE    &&
    2825           0 :                 !pEntryField->IsGroupBy()                   &&
    2826           0 :                 pEntryField->GetFunction().isEmpty() )
    2827           0 :             rUnUsedFields.push_back(pEntryField);
    2828           0 :     }
    2829           0 :     if ( !nFieldcount ) // no visible fields so return
    2830             :     {
    2831           0 :         rUnUsedFields = rFieldList;
    2832           0 :         return OUString();
    2833             :     }
    2834             : 
    2835           0 :     OQueryTableView::OTableWindowMap& rTabList   = m_pTableView->GetTabWinMap();
    2836           0 :     sal_uInt32 nTabcount        = rTabList.size();
    2837             : 
    2838           0 :     OUString aFieldListStr(GenerateSelectList(this,rFieldList,nTabcount>1));
    2839           0 :     if( aFieldListStr.isEmpty() )
    2840           0 :         return OUString();
    2841             : 
    2842             :     // Exceptionhandling, if no fields have been passed we should not
    2843             :     // change the tab page
    2844             :     // TabBarSelectHdl will query the SQL-OUString for STATEMENT_NOFIELDS
    2845             :     // and trigger a error message
    2846             :     // ----------------- Build table list ----------------------
    2847             : 
    2848           0 :     const ::std::vector<OTableConnection*>& rConnList = m_pTableView->getTableConnections();
    2849           0 :     Reference< XConnection> xConnection = rController.getConnection();
    2850           0 :     OUString aTableListStr(GenerateFromClause(xConnection,&rTabList,&rConnList));
    2851             :     OSL_ENSURE(!aTableListStr.isEmpty(), "OQueryDesignView::getStatement() : unexpected : have Fields, but no Tables !");
    2852             :     // if fields exist now, these only can be created by inserting from an already existing table; if on the other hand
    2853             :     // a table is deleted, also the belonging fields will be deleted -> therefore it CANNOT occur that fields
    2854             :     // exist but no tables exist (and aFieldListStr has its length, I secure this above)
    2855           0 :     OUStringBuffer aHavingStr,aCriteriaListStr;
    2856             : 
    2857             :     // ----------------- Kriterien aufbauen ----------------------
    2858           0 :     if (!GenerateCriterias(this,aCriteriaListStr,aHavingStr,rFieldList, nTabcount > 1))
    2859           0 :         return OUString();
    2860             : 
    2861           0 :     OUString aJoinCrit;
    2862           0 :     GenerateInnerJoinCriterias(xConnection,aJoinCrit,&rConnList);
    2863           0 :     if(!aJoinCrit.isEmpty())
    2864             :     {
    2865           0 :         OUString aTmp = "( " + aJoinCrit + " )";
    2866           0 :         if(!aCriteriaListStr.isEmpty())
    2867             :         {
    2868           0 :             aTmp += C_AND;
    2869           0 :             aTmp += aCriteriaListStr.makeStringAndClear();
    2870             :         }
    2871           0 :         aCriteriaListStr = aTmp;
    2872             :     }
    2873             :     // ----------------- construct statement  ----------------------
    2874           0 :     OUStringBuffer aSqlCmd("SELECT ");
    2875           0 :     if(rController.isDistinct())
    2876           0 :         aSqlCmd.append(" DISTINCT ");
    2877           0 :     aSqlCmd.append(aFieldListStr);
    2878           0 :     aSqlCmd.append(" FROM ");
    2879           0 :     aSqlCmd.append(aTableListStr);
    2880             : 
    2881           0 :     if (!aCriteriaListStr.isEmpty())
    2882             :     {
    2883           0 :         aSqlCmd.append(" WHERE ");
    2884           0 :         aSqlCmd.append(aCriteriaListStr.makeStringAndClear());
    2885             :     }
    2886           0 :     Reference<XDatabaseMetaData> xMeta;
    2887           0 :     if ( xConnection.is() )
    2888           0 :         xMeta = xConnection->getMetaData();
    2889           0 :     bool bUseAlias = nTabcount > 1;
    2890           0 :     if ( xMeta.is() )
    2891           0 :         bUseAlias = bUseAlias || !xMeta->supportsGroupByUnrelated();
    2892             : 
    2893           0 :     aSqlCmd.append(GenerateGroupBy(this,rFieldList,bUseAlias));
    2894             :     // ----------------- construct GroupBy and attachen ------------
    2895           0 :     if(!aHavingStr.isEmpty())
    2896             :     {
    2897           0 :         aSqlCmd.append(" HAVING ");
    2898           0 :         aSqlCmd.append(aHavingStr.makeStringAndClear());
    2899             :     }
    2900             :     // ----------------- construct sorting and attach ------------
    2901           0 :     OUString sOrder;
    2902           0 :     SqlParseError eErrorCode = eOk;
    2903           0 :     if ( (eErrorCode = GenerateOrder(this,rFieldList,nTabcount > 1,sOrder)) == eOk)
    2904           0 :         aSqlCmd.append(sOrder);
    2905             :     else
    2906             :     {
    2907           0 :         if ( !m_rController.hasError() )
    2908           0 :             m_rController.appendError( getParseErrorMessage( eErrorCode ) );
    2909             : 
    2910           0 :         m_rController.displayError();
    2911             :     }
    2912             :     // --------------------- Limit Clause -------------------
    2913             :     {
    2914           0 :         const sal_Int64 nLimit = rController.getLimit();
    2915           0 :         if( nLimit != -1 )
    2916             :         {
    2917           0 :             aSqlCmd.append( " LIMIT " + OUString::number(nLimit) );
    2918             :         }
    2919             :     }
    2920             : 
    2921           0 :     OUString sSQL = aSqlCmd.makeStringAndClear();
    2922           0 :     if ( xConnection.is() )
    2923             :     {
    2924           0 :         ::connectivity::OSQLParser& rParser( rController.getParser() );
    2925           0 :         OUString sErrorMessage;
    2926           0 :         boost::scoped_ptr<OSQLParseNode> pParseNode( rParser.parseTree( sErrorMessage, sSQL, true ) );
    2927           0 :         if ( pParseNode.get() )
    2928             :         {
    2929           0 :             OSQLParseNode* pNode = pParseNode->getChild(3)->getChild(1);
    2930           0 :             if ( pNode->count() > 1 )
    2931             :             {
    2932           0 :                 ::connectivity::OSQLParseNode * pCondition = pNode->getChild(1);
    2933           0 :                 if ( pCondition ) // no where clause
    2934             :                 {
    2935           0 :                     OSQLParseNode::compress(pCondition);
    2936           0 :                     OUString sTemp;
    2937           0 :                     pParseNode->parseNodeToStr(sTemp,xConnection);
    2938           0 :                     sSQL = sTemp;
    2939             :                 }
    2940             :             }
    2941           0 :         }
    2942             :     }
    2943           0 :     return sSQL;
    2944             : }
    2945             : 
    2946           0 : void OQueryDesignView::setSlotEnabled(sal_Int32 _nSlotId, bool _bEnable)
    2947             : {
    2948             :     sal_uInt16 nRow;
    2949           0 :     switch (_nSlotId)
    2950             :     {
    2951             :         case SID_QUERY_VIEW_FUNCTIONS:
    2952           0 :             nRow = BROW_FUNCTION_ROW;
    2953           0 :             break;
    2954             :         case SID_QUERY_VIEW_TABLES:
    2955           0 :             nRow = BROW_TABLE_ROW;
    2956           0 :             break;
    2957             :         case SID_QUERY_VIEW_ALIASES:
    2958           0 :             nRow = BROW_COLUMNALIAS_ROW;
    2959           0 :             break;
    2960             :         default:
    2961             :             // ????????????
    2962           0 :             nRow = 0;
    2963           0 :             break;
    2964             :     }
    2965           0 :     m_pSelectionBox->SetRowVisible(nRow,_bEnable);
    2966           0 :     m_pSelectionBox->Invalidate();
    2967           0 : }
    2968             : 
    2969           0 : bool OQueryDesignView::isSlotEnabled(sal_Int32 _nSlotId)
    2970             : {
    2971             :     sal_uInt16 nRow;
    2972           0 :     switch (_nSlotId)
    2973             :     {
    2974             :         case SID_QUERY_VIEW_FUNCTIONS:
    2975           0 :             nRow = BROW_FUNCTION_ROW;
    2976           0 :             break;
    2977             :         case SID_QUERY_VIEW_TABLES:
    2978           0 :             nRow = BROW_TABLE_ROW;
    2979           0 :             break;
    2980             :         case SID_QUERY_VIEW_ALIASES:
    2981           0 :             nRow = BROW_COLUMNALIAS_ROW;
    2982           0 :             break;
    2983             :         default:
    2984             :             // ?????????
    2985           0 :             nRow = 0;
    2986           0 :             break;
    2987             :     }
    2988           0 :     return m_pSelectionBox->IsRowVisible(nRow);
    2989             : }
    2990             : 
    2991           0 : void OQueryDesignView::SaveUIConfig()
    2992             : {
    2993           0 :     OQueryController& rCtrl = static_cast<OQueryController&>(getController());
    2994           0 :     rCtrl.SaveTabWinsPosSize( &m_pTableView->GetTabWinMap(), m_pScrollWindow->GetHScrollBar().GetThumbPos(), m_pScrollWindow->GetVScrollBar().GetThumbPos() );
    2995           0 :     rCtrl.setVisibleRows( m_pSelectionBox->GetNoneVisibleRows() );
    2996           0 :     if ( m_aSplitter.GetSplitPosPixel() != 0 )
    2997           0 :         rCtrl.setSplitPos( m_aSplitter.GetSplitPosPixel() );
    2998           0 : }
    2999             : 
    3000           0 : OSQLParseNode* OQueryDesignView::getPredicateTreeFromEntry(OTableFieldDescRef pEntry,
    3001             :                                                            const OUString& _sCriteria,
    3002             :                                                            OUString& _rsErrorMessage,
    3003             :                                                            Reference<XPropertySet>& _rxColumn) const
    3004             : {
    3005             :     OSL_ENSURE(pEntry.is(),"Entry is null!");
    3006           0 :     if(!pEntry.is())
    3007           0 :         return NULL;
    3008           0 :     Reference< XConnection> xConnection = static_cast<OQueryController&>(getController()).getConnection();
    3009           0 :     if(!xConnection.is())
    3010           0 :         return NULL;
    3011             : 
    3012           0 :     ::connectivity::OSQLParser& rParser( static_cast<OQueryController&>(getController()).getParser() );
    3013           0 :     OQueryTableWindow* pWin = static_cast<OQueryTableWindow*>(pEntry->GetTabWindow());
    3014             : 
    3015             :     // special handling for functions
    3016           0 :     if ( pEntry->GetFunctionType() & (FKT_OTHER | FKT_AGGREGATE | FKT_NUMERIC) )
    3017             :     {
    3018             :         // we have a function here so we have to distinguish the type of return vOUalue
    3019           0 :         OUString sFunction;
    3020           0 :         if ( pEntry->isNumericOrAggreateFunction() )
    3021           0 :             sFunction = pEntry->GetFunction();
    3022             : 
    3023           0 :         if ( sFunction.isEmpty() )
    3024           0 :             sFunction = pEntry->GetField();
    3025             : 
    3026           0 :         if (comphelper::string::getTokenCount(sFunction, '(') > 1)
    3027           0 :             sFunction = sFunction.getToken(0,'('); // this should be the name of the function
    3028             : 
    3029           0 :         sal_Int32 nType = ::connectivity::OSQLParser::getFunctionReturnType(sFunction,&rParser.getContext());
    3030           0 :         if ( nType == DataType::OTHER || (sFunction.isEmpty() && pEntry->isNumericOrAggreateFunction()) )
    3031             :         {
    3032             :             // first try the international version
    3033           0 :             OUString sSql;
    3034           0 :             sSql += "SELECT * ";
    3035           0 :             sSql += " FROM x WHERE ";
    3036           0 :             sSql += pEntry->GetField();
    3037           0 :             sSql += _sCriteria;
    3038           0 :             boost::scoped_ptr<OSQLParseNode> pParseNode( rParser.parseTree( _rsErrorMessage, sSql, true ) );
    3039           0 :             nType = DataType::DOUBLE;
    3040           0 :             if ( pParseNode.get() )
    3041             :             {
    3042           0 :                 OSQLParseNode* pColumnRef = pParseNode->getByRule(OSQLParseNode::column_ref);
    3043           0 :                 if ( pColumnRef )
    3044             :                 {
    3045           0 :                     OTableFieldDescRef aField = new OTableFieldDesc();
    3046           0 :                     if ( eOk == FillDragInfo(this,pColumnRef,aField) )
    3047             :                     {
    3048           0 :                         nType = aField->GetDataType();
    3049           0 :                     }
    3050             :                 }
    3051           0 :             }
    3052             :         }
    3053             : 
    3054           0 :         Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
    3055             :         parse::OParseColumn* pColumn = new parse::OParseColumn( pEntry->GetField(),
    3056             :                                                                 OUString(),
    3057             :                                                                 OUString(),
    3058             :                                                                 OUString(),
    3059             :                                                                 ColumnValue::NULLABLE_UNKNOWN,
    3060             :                                                                 0,
    3061             :                                                                 0,
    3062             :                                                                 nType,
    3063             :                                                                 false,
    3064             :                                                                 false,
    3065           0 :                                                                 xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
    3066             :                                                                 OUString(),
    3067             :                                                                 OUString(),
    3068           0 :                                                                 OUString());
    3069           0 :         _rxColumn = pColumn;
    3070           0 :         pColumn->setFunction(true);
    3071           0 :         pColumn->setRealName(pEntry->GetField());
    3072             :     }
    3073             :     else
    3074             :     {
    3075           0 :         if (pWin)
    3076             :         {
    3077           0 :             Reference<XNameAccess> xColumns = pWin->GetOriginalColumns();
    3078           0 :             if (xColumns.is() && xColumns->hasByName(pEntry->GetField()))
    3079           0 :                 xColumns->getByName(pEntry->GetField()) >>= _rxColumn;
    3080             :         }
    3081             :     }
    3082             : 
    3083           0 :     OUString sTest(_sCriteria);
    3084             :     OSQLParseNode* pParseNode = rParser.predicateTree(  _rsErrorMessage,
    3085             :                                                         sTest,
    3086           0 :                                                         static_cast<OQueryController&>(getController()).getNumberFormatter(),
    3087           0 :                                                         _rxColumn);
    3088           0 :     return pParseNode;
    3089             : }
    3090             : 
    3091           0 : void OQueryDesignView::GetFocus()
    3092             : {
    3093           0 :     OQueryView::GetFocus();
    3094           0 :     if ( m_pSelectionBox && !m_pSelectionBox->HasChildPathFocus() )
    3095             :     {
    3096             :         // first we have to deactivate the current cell to refill when necessary
    3097           0 :         m_pSelectionBox->DeactivateCell();
    3098           0 :         m_pSelectionBox->ActivateCell(m_pSelectionBox->GetCurRow(), m_pSelectionBox->GetCurColumnId());
    3099           0 :         m_pSelectionBox->GrabFocus();
    3100             :     }
    3101           0 : }
    3102             : 
    3103           0 : void OQueryDesignView::reset()
    3104             : {
    3105           0 :     m_pTableView->ClearAll();
    3106           0 :     m_pTableView->ReSync();
    3107           0 : }
    3108             : 
    3109           0 : void OQueryDesignView::setNoneVisbleRow(sal_Int32 _nRows)
    3110             : {
    3111           0 :     m_pSelectionBox->SetNoneVisbleRow(_nRows);
    3112           0 : }
    3113             : 
    3114           0 : void OQueryDesignView::initByFieldDescriptions( const Sequence< PropertyValue >& i_rFieldDescriptions )
    3115             : {
    3116           0 :     OQueryController& rController = static_cast< OQueryController& >( getController() );
    3117             : 
    3118           0 :     m_pSelectionBox->PreFill();
    3119           0 :     m_pSelectionBox->SetReadOnly( rController.isReadOnly() );
    3120           0 :     m_pSelectionBox->Fill();
    3121             : 
    3122           0 :     for (   const PropertyValue* field = i_rFieldDescriptions.getConstArray();
    3123           0 :             field != i_rFieldDescriptions.getConstArray() + i_rFieldDescriptions.getLength();
    3124             :             ++field
    3125             :         )
    3126             :     {
    3127           0 :         ::rtl::Reference< OTableFieldDesc > pField( new OTableFieldDesc() );
    3128           0 :         pField->Load( *field, true );
    3129           0 :         InsertField( pField, true, false );
    3130           0 :     }
    3131             : 
    3132           0 :     rController.ClearUndoManager();
    3133           0 :     m_pSelectionBox->Invalidate();
    3134           0 : }
    3135             : 
    3136           0 : bool OQueryDesignView::initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo )
    3137             : {
    3138           0 :     SqlParseError eErrorCode = eNativeMode;
    3139           0 :     m_rController.clearError();
    3140             : 
    3141             :     try
    3142             :     {
    3143           0 :         eErrorCode = InitFromParseNodeImpl( this, m_pSelectionBox );
    3144             : 
    3145           0 :         if ( eErrorCode != eOk )
    3146             :         {
    3147           0 :             if ( !m_rController.hasError() )
    3148           0 :                 m_rController.appendError( getParseErrorMessage( eErrorCode ) );
    3149             : 
    3150           0 :             if ( _pErrorInfo )
    3151             :             {
    3152           0 :                 *_pErrorInfo = m_rController.getError();
    3153             :             }
    3154             :             else
    3155             :             {
    3156           0 :                 m_rController.displayError();
    3157             :             }
    3158             :         }
    3159             :     }
    3160           0 :     catch ( const Exception& )
    3161             :     {
    3162             :         DBG_UNHANDLED_EXCEPTION();
    3163             :     }
    3164           0 :     return eErrorCode == eOk;
    3165             : }
    3166             : 
    3167             : // Utility function for fillFunctionInfo
    3168             : namespace {
    3169           0 :     sal_Int32 char_datatype(const::connectivity::OSQLParseNode* pDataType, const unsigned int offset) {
    3170           0 :         int cnt = pDataType->count() - offset;
    3171           0 :         if ( cnt < 0 )
    3172             :         {
    3173             :             OSL_FAIL("internal error in decoding character datatype specification");
    3174           0 :             return DataType::VARCHAR;
    3175             :         }
    3176           0 :         else if ( cnt == 0 )
    3177             :         {
    3178           0 :             if ( offset == 0 )
    3179             :             {
    3180             :                 // The datatype is the node itself
    3181           0 :                 if ( SQL_ISTOKENOR2 (pDataType, CHARACTER, CHAR) )
    3182           0 :                     return DataType::CHAR;
    3183           0 :                 else if ( SQL_ISTOKEN (pDataType, VARCHAR) )
    3184           0 :                     return DataType::VARCHAR;
    3185           0 :                 else if ( SQL_ISTOKEN (pDataType, CLOB) )
    3186           0 :                     return DataType::CLOB;
    3187             :                 else
    3188             :                 {
    3189             :                     OSL_FAIL("unknown/unexpected token in decoding character datatype specification");
    3190           0 :                     return DataType::VARCHAR;
    3191             :                 }
    3192             :             }
    3193             :             else
    3194             :             {
    3195             :                 // No child left to read!
    3196             :                 OSL_FAIL("incomplete datatype in decoding character datatype specification");
    3197           0 :                 return DataType::VARCHAR;
    3198             :             }
    3199             :         }
    3200             : 
    3201           0 :         if ( SQL_ISTOKEN(pDataType->getChild(offset), NATIONAL) )
    3202           0 :             return char_datatype(pDataType, offset+1);
    3203           0 :         else if ( SQL_ISTOKENOR3(pDataType->getChild(offset), CHARACTER, CHAR, NCHAR) )
    3204             :         {
    3205           0 :             if ( cnt > 2 && SQL_ISTOKEN(pDataType->getChild(offset+1), LARGE) && SQL_ISTOKEN(pDataType->getChild(offset+2), OBJECT) )
    3206           0 :                 return DataType::CLOB;
    3207           0 :             else if ( cnt > 1 && SQL_ISTOKEN(pDataType->getChild(offset+1), VARYING) )
    3208           0 :                 return DataType::VARCHAR;
    3209             :             else
    3210           0 :                 return DataType::CHAR;
    3211             :         }
    3212           0 :         else if ( SQL_ISTOKEN (pDataType->getChild(offset), VARCHAR) )
    3213           0 :             return DataType::VARCHAR;
    3214           0 :         else if ( SQL_ISTOKENOR2 (pDataType->getChild(offset), CLOB, NCLOB) )
    3215           0 :             return DataType::CLOB;
    3216             : 
    3217             :         OSL_FAIL("unrecognised character datatype");
    3218           0 :         return DataType::VARCHAR;
    3219             :     }
    3220             : }
    3221             : 
    3222             : // Try to guess the type of an expression in simple cases.
    3223             : // Originally meant to be called only on a function call (hence the misnomer),
    3224             : // but now tries to do the best it can also in other cases.
    3225             : // Don't completely rely on fillFunctionInfo,
    3226             : // it won't look at the function's arguments to find the return type
    3227             : // (in particular, in the case of general_set_fct,
    3228             : //  the return type is the type of the argument;
    3229             : //  if that is (as is typical) a column reference,
    3230             : //  it is the type of the column).
    3231             : // TODO: There is similar "guess the expression's type" code in several places:
    3232             : //       SelectionBrowseBox.cxx: OSelectionBrowseBox::saveField
    3233             : //       QueryDesignView.cxx: InstallFields, GetOrderCriteria, GetGroupCriteria
    3234             : //       If possible, they should be factorised into this function
    3235             : //       (which should then be renamed...)
    3236             : 
    3237           0 : void OQueryDesignView::fillFunctionInfo(  const ::connectivity::OSQLParseNode* pNode
    3238             :                                         ,const OUString& sFunctionTerm
    3239             :                                         ,OTableFieldDescRef& aInfo)
    3240             : {
    3241             :     // get the type of the expression, as far as easily possible
    3242           0 :     OQueryController& rController = static_cast<OQueryController&>(getController());
    3243           0 :     sal_Int32 nDataType = DataType::DOUBLE;
    3244           0 :     switch(pNode->getNodeType())
    3245             :     {
    3246             :     case SQL_NODE_CONCAT:
    3247             :     case SQL_NODE_STRING:
    3248           0 :         nDataType = DataType::VARCHAR;
    3249           0 :         break;
    3250             :     case SQL_NODE_INTNUM:
    3251           0 :         nDataType = DataType::INTEGER;
    3252           0 :         break;
    3253             :     case SQL_NODE_APPROXNUM:
    3254           0 :         nDataType = DataType::DOUBLE;
    3255           0 :         break;
    3256             :     case SQL_NODE_DATE:
    3257             :     case SQL_NODE_ACCESS_DATE:
    3258           0 :         nDataType = DataType::TIMESTAMP;
    3259           0 :         break;
    3260             :     case SQL_NODE_COMPARISON:
    3261             :     case SQL_NODE_EQUAL:
    3262             :     case SQL_NODE_LESS:
    3263             :     case SQL_NODE_GREAT:
    3264             :     case SQL_NODE_LESSEQ:
    3265             :     case SQL_NODE_GREATEQ:
    3266             :     case SQL_NODE_NOTEQUAL:
    3267           0 :         nDataType = DataType::BOOLEAN;
    3268           0 :         break;
    3269             :     case SQL_NODE_NAME:
    3270             :     case SQL_NODE_LISTRULE:
    3271             :     case SQL_NODE_COMMALISTRULE:
    3272             :     case SQL_NODE_KEYWORD:
    3273             :     case SQL_NODE_AMMSC: //??
    3274             :     case SQL_NODE_PUNCTUATION:
    3275             :         OSL_FAIL("Unexpected SQL Node Type");
    3276           0 :         break;
    3277             :     case SQL_NODE_RULE:
    3278           0 :         switch(pNode->getKnownRuleID())
    3279             :         {
    3280             :         case OSQLParseNode::select_statement:
    3281             :         case OSQLParseNode::table_exp:
    3282             :         case OSQLParseNode::table_ref_commalist:
    3283             :         case OSQLParseNode::table_ref:
    3284             :         case OSQLParseNode::catalog_name:
    3285             :         case OSQLParseNode::schema_name:
    3286             :         case OSQLParseNode::table_name:
    3287             :         case OSQLParseNode::opt_column_commalist:
    3288             :         case OSQLParseNode::column_commalist:
    3289             :         case OSQLParseNode::column_ref_commalist:
    3290             :         case OSQLParseNode::column_ref:
    3291             :         case OSQLParseNode::opt_order_by_clause:
    3292             :         case OSQLParseNode::ordering_spec_commalist:
    3293             :         case OSQLParseNode::ordering_spec:
    3294             :         case OSQLParseNode::opt_asc_desc:
    3295             :         case OSQLParseNode::where_clause:
    3296             :         case OSQLParseNode::opt_where_clause:
    3297             :         case OSQLParseNode::opt_escape:
    3298             :         case OSQLParseNode::scalar_exp_commalist:
    3299             :         case OSQLParseNode::scalar_exp: // Seems to never be generated?
    3300             :         case OSQLParseNode::parameter_ref:
    3301             :         case OSQLParseNode::parameter:
    3302             :         case OSQLParseNode::range_variable:
    3303             :         case OSQLParseNode::delete_statement_positioned:
    3304             :         case OSQLParseNode::delete_statement_searched:
    3305             :         case OSQLParseNode::update_statement_positioned:
    3306             :         case OSQLParseNode::update_statement_searched:
    3307             :         case OSQLParseNode::assignment_commalist:
    3308             :         case OSQLParseNode::assignment:
    3309             :         case OSQLParseNode::insert_statement:
    3310             :         case OSQLParseNode::insert_atom_commalist:
    3311             :         case OSQLParseNode::insert_atom:
    3312             :         case OSQLParseNode::from_clause:
    3313             :         case OSQLParseNode::qualified_join:
    3314             :         case OSQLParseNode::cross_union:
    3315             :         case OSQLParseNode::select_sublist:
    3316             :         case OSQLParseNode::join_type:
    3317             :         case OSQLParseNode::named_columns_join:
    3318             :         case OSQLParseNode::joined_table:
    3319             :         case OSQLParseNode::sql_not:
    3320             :         case OSQLParseNode::manipulative_statement:
    3321             :         case OSQLParseNode::value_exp_commalist:
    3322             :         case OSQLParseNode::union_statement:
    3323             :         case OSQLParseNode::outer_join_type:
    3324             :         case OSQLParseNode::selection:
    3325             :         case OSQLParseNode::base_table_def:
    3326             :         case OSQLParseNode::base_table_element_commalist:
    3327             :         case OSQLParseNode::data_type:
    3328             :         case OSQLParseNode::column_def:
    3329             :         case OSQLParseNode::table_node:
    3330             :         case OSQLParseNode::as_clause:
    3331             :         case OSQLParseNode::opt_as:
    3332             :         case OSQLParseNode::op_column_commalist:
    3333             :         case OSQLParseNode::table_primary_as_range_column:
    3334             :         case OSQLParseNode::character_string_type:
    3335             :         case OSQLParseNode::comparison:
    3336             :             OSL_FAIL("Unexpected SQL RuleID");
    3337           0 :             break;
    3338             :         case OSQLParseNode::column:
    3339             :         case OSQLParseNode::column_val:
    3340             :             OSL_FAIL("Cannot guess column type");
    3341           0 :             break;
    3342             :         case OSQLParseNode::values_or_query_spec:
    3343             :             OSL_FAIL("Cannot guess VALUES type");
    3344           0 :             break;
    3345             :         case OSQLParseNode::derived_column:
    3346             :             OSL_FAIL("Cannot guess computed column type");
    3347           0 :             break;
    3348             :         case OSQLParseNode::subquery:
    3349             :             OSL_FAIL("Cannot guess subquery return type");
    3350           0 :             break;
    3351             :         case OSQLParseNode::search_condition:
    3352             :         case OSQLParseNode::comparison_predicate:
    3353             :         case OSQLParseNode::between_predicate:
    3354             :         case OSQLParseNode::like_predicate:
    3355             :         case OSQLParseNode::test_for_null:
    3356             :         case OSQLParseNode::boolean_term:
    3357             :         case OSQLParseNode::boolean_primary:
    3358             :         case OSQLParseNode::in_predicate:
    3359             :         case OSQLParseNode::existence_test:
    3360             :         case OSQLParseNode::unique_test:
    3361             :         case OSQLParseNode::all_or_any_predicate:
    3362             :         case OSQLParseNode::join_condition:
    3363             :         case OSQLParseNode::boolean_factor:
    3364             :         case OSQLParseNode::comparison_predicate_part_2:
    3365             :         case OSQLParseNode::parenthesized_boolean_value_expression:
    3366             :         case OSQLParseNode::other_like_predicate_part_2:
    3367             :         case OSQLParseNode::between_predicate_part_2:
    3368           0 :             nDataType = DataType::BOOLEAN;
    3369           0 :             break;
    3370             :         case OSQLParseNode::num_value_exp:
    3371             :         case OSQLParseNode::extract_exp:
    3372             :         case OSQLParseNode::term:
    3373             :         case OSQLParseNode::factor:
    3374             :             // Might by an integer or a float; take the most generic
    3375           0 :             nDataType = DataType::DOUBLE;
    3376           0 :             break;
    3377             :         case OSQLParseNode::value_exp_primary:
    3378             :         case OSQLParseNode::value_exp:
    3379             :         case OSQLParseNode::odbc_call_spec:
    3380             :             // Really, we don't know. Let the default.
    3381           0 :             break;
    3382             :         case OSQLParseNode::position_exp:
    3383             :         case OSQLParseNode::length_exp:
    3384           0 :             nDataType = DataType::INTEGER;
    3385           0 :             break;
    3386             :         case OSQLParseNode::char_value_exp:
    3387             :         case OSQLParseNode::char_value_fct:
    3388             :         case OSQLParseNode::fold:
    3389             :         case OSQLParseNode::char_substring_fct:
    3390             :         case OSQLParseNode::char_factor:
    3391             :         case OSQLParseNode::concatenation:
    3392           0 :             nDataType = DataType::VARCHAR;
    3393           0 :             break;
    3394             :         case OSQLParseNode::datetime_primary:
    3395           0 :             nDataType = DataType::TIMESTAMP;
    3396           0 :             break;
    3397             :         case OSQLParseNode::bit_value_fct:
    3398           0 :             nDataType = DataType::BINARY;
    3399           0 :             break;
    3400             :         case OSQLParseNode::general_set_fct: // May depend on argument; ignore that for now
    3401             :         case OSQLParseNode::set_fct_spec:
    3402             :         {
    3403           0 :             if (pNode->count() == 0)
    3404             :             {
    3405             :                 // This is not a function call, no sense to continue with a function return type lookup
    3406             :                 OSL_FAIL("Got leaf SQL node where non-leaf expected");
    3407           0 :                 break;
    3408             :             }
    3409           0 :             const OSQLParseNode* pFunctionName = pNode->getChild(0);
    3410           0 :             if ( SQL_ISPUNCTUATION(pFunctionName,"{") )
    3411             :             {
    3412           0 :                 if ( pNode->count() == 3 )
    3413           0 :                     return fillFunctionInfo( pNode->getChild(1), sFunctionTerm, aInfo );
    3414             :                 else
    3415             :                     OSL_FAIL("ODBC escape not in recognised form");
    3416           0 :                 break;
    3417             :             }
    3418             :             else
    3419             :             {
    3420           0 :                 if ( SQL_ISRULEOR2(pNode,length_exp,char_value_fct) )
    3421           0 :                     pFunctionName = pFunctionName->getChild(0);
    3422             : 
    3423           0 :                 OUString sFunctionName = pFunctionName->getTokenValue();
    3424           0 :                 if ( sFunctionName.isEmpty() )
    3425           0 :                     sFunctionName = OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_UTF8);
    3426             : 
    3427             :                 nDataType = OSQLParser::getFunctionReturnType(
    3428             :                     sFunctionName
    3429           0 :                     ,&rController.getParser().getContext());
    3430             :             }
    3431           0 :             break;
    3432             :         }
    3433             :         case OSQLParseNode::odbc_fct_spec:
    3434             :         {
    3435           0 :             if (pNode->count() != 2)
    3436             :             {
    3437             :                 OSL_FAIL("interior of ODBC escape not in recognised shape");
    3438           0 :                 break;
    3439             :             }
    3440             : 
    3441           0 :             const OSQLParseNode* const pEscapeType = pNode->getChild(0);
    3442           0 :             if (SQL_ISTOKEN(pEscapeType, TS))
    3443           0 :                 nDataType = DataType::TIMESTAMP;
    3444           0 :             else if (SQL_ISTOKEN(pEscapeType, D))
    3445           0 :                 nDataType = DataType::DATE;
    3446           0 :             else if (SQL_ISTOKEN(pEscapeType, T))
    3447           0 :                 nDataType = DataType::TIME;
    3448           0 :             else if (SQL_ISTOKEN(pEscapeType, FN))
    3449           0 :                 return fillFunctionInfo( pNode->getChild(1), sFunctionTerm, aInfo );
    3450             :             else
    3451             :                 OSL_FAIL("Unknown ODBC escape");
    3452           0 :             break;
    3453             :         }
    3454             :         case OSQLParseNode::cast_spec:
    3455             :         {
    3456           0 :             if ( pNode->count() != 6 || !SQL_ISTOKEN(pNode->getChild(3), AS) )
    3457             :             {
    3458             :                 OSL_FAIL("CAST not in recognised shape");
    3459           0 :                 break;
    3460             :             }
    3461           0 :             const OSQLParseNode *pCastTarget = pNode->getChild(4);
    3462           0 :             if ( SQL_ISTOKENOR2(pCastTarget, INTEGER, INT) )
    3463           0 :                 nDataType = DataType::INTEGER;
    3464           0 :             else if ( SQL_ISTOKEN(pCastTarget, SMALLINT) )
    3465           0 :                 nDataType = DataType::SMALLINT;
    3466           0 :             else if ( SQL_ISTOKEN(pCastTarget, BIGINT) )
    3467           0 :                 nDataType = DataType::BIGINT;
    3468           0 :             else if ( SQL_ISTOKEN(pCastTarget, FLOAT) )
    3469           0 :                 nDataType = DataType::FLOAT;
    3470           0 :             else if ( SQL_ISTOKEN(pCastTarget, REAL) )
    3471           0 :                 nDataType = DataType::REAL;
    3472           0 :            else if ( SQL_ISTOKEN(pCastTarget, DOUBLE) )
    3473           0 :                 nDataType = DataType::DOUBLE;
    3474           0 :             else if ( SQL_ISTOKEN(pCastTarget, BOOLEAN) )
    3475           0 :                 nDataType = DataType::BOOLEAN;
    3476           0 :             else if ( SQL_ISTOKEN(pCastTarget, DATE) )
    3477           0 :                 nDataType = DataType::DATE;
    3478           0 :             else if ( pCastTarget->count() > 0 )
    3479             :             {
    3480           0 :                 const OSQLParseNode *pDataType = pCastTarget->getChild(0);
    3481           0 :                 while (pDataType->count() > 0)
    3482             :                 {
    3483           0 :                     pCastTarget = pDataType;
    3484           0 :                     pDataType = pDataType->getChild(0);
    3485             :                 }
    3486           0 :                 if ( SQL_ISTOKEN (pDataType, TIME) )
    3487           0 :                     nDataType = DataType::TIME;
    3488           0 :                 else if ( SQL_ISTOKEN (pDataType, TIMESTAMP) )
    3489           0 :                     nDataType = DataType::TIMESTAMP;
    3490           0 :                 else if ( SQL_ISTOKENOR3 (pDataType, CHARACTER, CHAR, NCHAR) )
    3491           0 :                     nDataType = char_datatype(pCastTarget, 0);
    3492           0 :                 else if ( SQL_ISTOKEN (pDataType, VARCHAR) )
    3493           0 :                     nDataType = DataType::VARCHAR;
    3494           0 :                 else if ( SQL_ISTOKEN (pDataType, CLOB) )
    3495           0 :                     nDataType = DataType::CLOB;
    3496           0 :                 else if ( SQL_ISTOKEN (pDataType, NATIONAL) )
    3497           0 :                     nDataType = char_datatype(pCastTarget, 1);
    3498           0 :                 else if ( SQL_ISTOKEN (pDataType, BINARY) )
    3499             :                 {
    3500           0 :                     if ( pCastTarget->count() > 2 && SQL_ISTOKEN(pCastTarget->getChild(1), LARGE) && SQL_ISTOKEN(pCastTarget->getChild(2), OBJECT) )
    3501           0 :                         nDataType = DataType::BLOB;
    3502           0 :                     else if ( pCastTarget->count() > 1 && SQL_ISTOKEN(pCastTarget->getChild(1), VARYING) )
    3503           0 :                         nDataType = DataType::VARBINARY;
    3504             :                     else
    3505           0 :                         nDataType = DataType::BINARY;
    3506             :                 }
    3507           0 :                 else if ( SQL_ISTOKEN (pDataType, VARBINARY) )
    3508           0 :                     nDataType = DataType::VARBINARY;
    3509           0 :                 else if ( SQL_ISTOKEN (pDataType, BLOB) )
    3510           0 :                     nDataType = DataType::BLOB;
    3511           0 :                 else if ( SQL_ISTOKEN (pDataType, NUMERIC) )
    3512           0 :                     nDataType = DataType::NUMERIC;
    3513           0 :                 else if ( SQL_ISTOKENOR2 (pDataType, DECIMAL, DEC) )
    3514           0 :                     nDataType = DataType::DECIMAL;
    3515           0 :                 else if ( SQL_ISTOKEN (pDataType, FLOAT) )
    3516           0 :                     nDataType = DataType::FLOAT;
    3517           0 :                 else if ( SQL_ISTOKEN (pDataType, DOUBLE) )
    3518           0 :                     nDataType = DataType::DOUBLE;
    3519           0 :                 else if ( SQL_ISTOKEN (pDataType, TIME) )
    3520           0 :                     nDataType = DataType::TIME;
    3521           0 :                 else if ( SQL_ISTOKEN (pDataType, TIMESTAMP) )
    3522           0 :                     nDataType = DataType::TIMESTAMP;
    3523           0 :                 else if ( SQL_ISTOKEN (pDataType, INTERVAL) )
    3524             :                     // Not in DataType published constant (because not in JDBC...)
    3525           0 :                     nDataType = DataType::VARCHAR;
    3526             :                 else
    3527             :                     OSL_FAIL("Failed to decode CAST target");
    3528             :             }
    3529             :             else
    3530             :                 OSL_FAIL("Could not decipher CAST target");
    3531           0 :             break;
    3532             :         }
    3533             :         default:
    3534             :             OSL_FAIL("Unknown SQL RuleID");
    3535           0 :             break;
    3536             :         }
    3537           0 :         break;
    3538             :     default:
    3539             :         OSL_FAIL("Unknown SQL Node Type");
    3540           0 :         break;
    3541             :     }
    3542             : 
    3543           0 :     aInfo->SetDataType(nDataType);
    3544           0 :     aInfo->SetFieldType(TAB_NORMAL_FIELD);
    3545           0 :     aInfo->SetField(sFunctionTerm);
    3546           0 :     aInfo->SetTabWindow(NULL);
    3547          72 : }
    3548             : 
    3549             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10