User: hr      
Date: 2007-11-01 15:31:24+0000
Modified:
   dba/dbaccess/source/ui/querydesign/QueryDesignView.cxx

Log:
 INTEGRATION: CWS dba24b (1.86.46); FILE MERGED
 2007/10/04 09:01:52 oj 1.86.46.6: #i61061# handle or in and condition
 2007/08/24 10:16:54 oj 1.86.46.5: #i75557# allow functions before like
 2007/08/24 08:21:37 oj 1.86.46.4: #i69678# allow functions in group by
 2007/08/22 14:28:20 oj 1.86.46.3: #i78577# add table alias if they differ
 2007/08/22 11:41:58 oj 1.86.46.2: #i76374# handle cross join as natural join 
now in query design
 2007/08/16 06:14:44 oj 1.86.46.1: #i56898# clean up of the class structure

File Changes:

Directory: /dba/dbaccess/source/ui/querydesign/
===============================================

File [changed]: QueryDesignView.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/querydesign/QueryDesignView.cxx?r1=1.87&r2=1.88
Delta lines:  +353 -133
-----------------------
--- QueryDesignView.cxx 2007-09-26 14:52:43+0000        1.87
+++ QueryDesignView.cxx 2007-11-01 15:31:21+0000        1.88
@@ -185,7 +185,8 @@
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
                                                                        const 
::connectivity::OSQLParseNode * pCondition,
                                                                        const 
sal_uInt16 nLevel,
-                                                                       
sal_Bool bHaving);
+                                                                       
sal_Bool bHaving,
+                                    bool _bAddOrOnOneLine);
 
     void fillFunctionInfo(          OQueryDesignView* _pView
                                                        ,const 
::connectivity::OSQLParseNode* pNode
@@ -205,6 +206,105 @@
                return sRet;
        }
        
//------------------------------------------------------------------------------
+    ::rtl::OUString getTableRange(const OQueryDesignView* _pView,const 
::connectivity::OSQLParseNode* _pTableRef)
+    {
+        Reference< XConnection> xConnection = 
static_cast<OQueryController*>(_pView->getController())->getConnection();
+        ::rtl::OUString sTableRange;
+        if ( _pTableRef )
+        {
+            if ( SQL_ISRULE( _pTableRef, joined_table ) )
+            {
+                OSL_ENSURE(0,"joined_table NYI");
+            }
+            else 
+            {
+                switch( _pTableRef->count() )
+                {
+                    case 1:
+                        
_pTableRef->parseNodeToStr(sTableRange,xConnection,NULL,sal_False,sal_False);
+                        break;
+                    case 3:
+                        sTableRange = _pTableRef->getChild(2)->getTokenValue();
+                        break;
+                    case 4:
+                        if ( !SQL_ISRULE( _pTableRef->getChild(2), 
joined_table ))
+                            sTableRange = 
_pTableRef->getChild(2)->getTokenValue();
+                        else
+                            OSL_ENSURE(0,"Outer join is not implemented 
here!");
+                        break;
+                    case 6:
+                        sTableRange = _pTableRef->getChild(4)->getTokenValue();
+                        break;
+                    default:
+                        OSL_ENSURE(0,"Unhandled child count");
+                }
+            }
+        }
+        return sTableRange;
+    }
+    
//------------------------------------------------------------------------------
+    void insertConnection(const OQueryDesignView* _pView,const EJoinType& 
_eJoinType,OTableFieldDescRef _aDragLeft,OTableFieldDescRef _aDragRight,bool 
_bNatural = false)
+    {
+        OQueryTableView* pTableView = 
static_cast<OQueryTableView*>(_pView->getTableView());
+               OQueryTableConnection* pConn = 
static_cast<OQueryTableConnection*>( 
pTableView->GetTabConn(static_cast<OTableWindow*>(_aDragLeft->GetTabWindow()),static_cast<OTableWindow*>(_aDragRight->GetTabWindow()),true));
+
+               if ( !pConn )
+               {
+                       OQueryTableConnectionData* pInfoData = new 
OQueryTableConnectionData();
+            TTableConnectionData::value_type aInfoData(pInfoData);
+                       pInfoData->InitFromDrag(_aDragLeft, _aDragRight);
+                       pInfoData->SetJoinType(_eJoinType);
+
+            if ( _bNatural )
+            {
+                aInfoData->ResetConnLines();
+                pInfoData->setNatural(_bNatural);
+                try
+                {
+                    Reference<XNameAccess> 
xReferencedTableColumns(aInfoData->getReferencedTable()->getColumns());
+                    Sequence< ::rtl::OUString> aSeq = 
aInfoData->getReferencingTable()->getColumns()->getElementNames();
+                    const ::rtl::OUString* pIter = aSeq.getConstArray();
+                    const ::rtl::OUString* pEnd          = pIter + 
aSeq.getLength();
+                    for(;pIter != pEnd;++pIter)
+                    {
+                        if ( xReferencedTableColumns->hasByName(*pIter) )
+                            aInfoData->AppendConnLine(*pIter,*pIter);
+                    }            
+                }
+                catch(const Exception&)
+                {
+                    OSL_ENSURE(0,"Exception caught while asking for column 
names in case of a natural join.");
+                }
+            }
+
+                       OQueryTableConnection aInfo(pTableView, aInfoData);
+                       // da ein OQueryTableConnection-Objekt nie den Besitz 
der uebergebenen Daten uebernimmt, sondern sich nur den Zeiger merkt,
+                       // ist dieser Zeiger auf eine lokale Variable hier 
unkritisch, denn aInfoData und aInfo haben die selbe Lebensdauer
+                       pTableView->NotifyTabConnection( aInfo );
+               }
+               else
+               {
+                       ::rtl::OUString 
aSourceFieldName(_aDragLeft->GetField());
+                       ::rtl::OUString aDestFieldName(_aDragRight->GetField());
+                       // the connection could point on the other side
+                       if(pConn->GetSourceWin() == _aDragRight->GetTabWindow())
+                       {
+                               ::rtl::OUString aTmp(aSourceFieldName);
+                               aSourceFieldName = aDestFieldName;
+                               aDestFieldName = aTmp;
+                       }
+                       pConn->GetData()->AppendConnLine( 
aSourceFieldName,aDestFieldName);
+                       pConn->UpdateLineList();
+                       // Modified-Flag
+                       //      SetModified();
+                       // und neu zeichnen
+                       pConn->RecalcLines();
+                               // fuer das unten folgende Invalidate muss ich 
dieser neuen Connection erst mal die Moeglichkeit geben,
+                               // ihr BoundingRect zu ermitteln
+                       pConn->InvalidateConnection();
+               }
+    }
+       
//------------------------------------------------------------------------------
        ::rtl::OUString ParseCondition( OQueryController* pController
                                                                        ,const 
::connectivity::OSQLParseNode* pCondition
                                                                        ,const 
::rtl::OUString _sDecimal
@@ -400,8 +500,6 @@
                        for(;aIter != pLineDataList->end();++aIter)
                        {
                                OConnectionLineDataRef pLineData = *aIter;
-                               if(pLineData->IsValid())
-                               {
                                        if(aCondition.getLength())
                                                aCondition += C_AND;
                                        aCondition += 
quoteTableAlias(sal_True,pData->GetAliasName(JTCS_FROM),aQuote);
@@ -411,7 +509,6 @@
                                        aCondition += 
::dbtools::quoteName(aQuote, pLineData->GetFieldName(JTCS_TO) );
                                }
                        }
-               }
                catch(SQLException&)
                {
                        OSL_ASSERT(!"Failure while building Join criteria!");
@@ -433,7 +530,7 @@
        {
                OSL_ENSURE(_pEntryConn,"TableConnection can not be null!");
 
-               OQueryTableConnectionData* pData = static_cast< 
OQueryTableConnectionData*>(_pEntryConn->GetData());
+               OQueryTableConnectionData* pData = static_cast< 
OQueryTableConnectionData*>(_pEntryConn->GetData().get());
                if ( pData->GetJoinType() != INNER_JOIN && 
_pEntryTabTo->ExistsAVisitedConn() )
                {
                        sal_Bool bBrace = sal_False;
@@ -450,7 +547,8 @@
        }
        
//------------------------------------------------------------------------------
        ::rtl::OUString BuildTable(     const Reference< XConnection>& 
_xConnection,
-                                                               const 
OQueryTableWindow* pEntryTab
+                                                               const 
OQueryTableWindow* pEntryTab,
+                                bool _bForce = false
                                                                )
        {
                ::rtl::OUString aDBName(pEntryTab->GetComposedName());
@@ -467,7 +565,7 @@
                                ::rtl::OUString aTableListStr = 
::dbtools::composeTableNameForSelect( _xConnection, sCatalog, sSchema, sTable );
 
                                ::rtl::OUString aQuote = 
xMetaData->getIdentifierQuoteString();
-                               if ( isAppendTableAliasEnabled( _xConnection ) )
+                               if ( _bForce || isAppendTableAliasEnabled( 
_xConnection ) || pEntryTab->GetAliasName() != aDBName )
                                {
                     aTableListStr += ::rtl::OUString::createFromAscii(" ");
                     if ( generateAsBeforeTableAlias( _xConnection ) )
@@ -491,6 +589,8 @@
        {
 
                String aErg(rLh);
+        if ( pData->isNatural() && pData->GetJoinType() != CROSS_JOIN )
+            aErg.AppendAscii(" NATURAL ");
                switch(pData->GetJoinType())
                {
                        case LEFT_JOIN:
@@ -499,9 +599,13 @@
                        case RIGHT_JOIN:
                                aErg.AppendAscii(" RIGHT OUTER ");
                                break;
+            case CROSS_JOIN:
+                OSL_ENSURE(!pData->isNatural(),"OQueryDesignView::BuildJoin: 
This should not happen!");
+                               aErg.AppendAscii(" CROSS ");
+                               break;
                        case INNER_JOIN:
-                               DBG_ERROR("OQueryDesignView::BuildJoin: This 
should not happen!");
-                               //aErg.AppendAscii(" INNER ");
+                OSL_ENSURE(pData->isNatural(),"OQueryDesignView::BuildJoin: 
This should not happen!");
+                               aErg.AppendAscii(" INNER ");
                                break;
                        default:
                                aErg.AppendAscii(" FULL OUTER ");
@@ -509,8 +613,11 @@
                }
                aErg.AppendAscii("JOIN ");
                aErg += String(rRh);
+        if ( CROSS_JOIN != pData->GetJoinType() && !pData->isNatural() )
+        {
                aErg.AppendAscii(" ON ");
                aErg += 
String(BuildJoinCriteria(_xConnection,pData->GetConnLineDataList(),pData));
+        }
 
                return aErg;
        }
@@ -521,7 +628,8 @@
                                                                
OQueryTableConnectionData* pData
                                                                )
        {
-               return 
BuildJoin(_xConnection,BuildTable(_xConnection,pLh),BuildTable(_xConnection,pRh),pData);
+        bool bForce = pData->GetJoinType() == CROSS_JOIN || pData->isNatural();
+               return 
BuildJoin(_xConnection,BuildTable(_xConnection,pLh,bForce),BuildTable(_xConnection,pRh,bForce),pData);
        }
        
//------------------------------------------------------------------------------
        ::rtl::OUString BuildJoin(      const Reference< XConnection>& 
_xConnection,
@@ -547,8 +655,8 @@
                                                OQueryTableWindow* pEntryTabTo,
                                                ::rtl::OUString &aJoin)
        {
-               OQueryTableConnectionData* pEntryConnData = 
static_cast<OQueryTableConnectionData*>(pEntryConn->GetData());
-               if(pEntryConnData->GetJoinType() == INNER_JOIN)
+               OQueryTableConnectionData* pEntryConnData = 
static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get());
+        if ( pEntryConnData->GetJoinType() == INNER_JOIN && 
!pEntryConnData->isNatural() )
                        return;
 
                //      Reference< XConnection> xConnection = 
static_cast<OQueryController*>(_pView->getController())->getConnection();
@@ -648,41 +756,7 @@
                                eOk != ( eErrorCode = 
FillDragInfo(_pView,pNode->getChild(2),aDragRight)))
                                return eErrorCode;
 
-                       OQueryTableView* pTableView = 
static_cast<OQueryTableView*>(_pView->getTableView());
-                       OQueryTableConnection* pConn = 
static_cast<OQueryTableConnection*>( 
pTableView->GetTabConn(static_cast<OQueryTableWindow*>(aDragLeft->GetTabWindow()),static_cast<OQueryTableWindow*>(aDragRight->GetTabWindow())));
-                       if(!pConn)
-                       {
-                               OQueryTableConnectionData aInfoData;
-                               aInfoData.InitFromDrag(aDragLeft, aDragRight);
-                               aInfoData.SetJoinType(_eJoinType);
-
-                               OQueryTableConnection aInfo(pTableView, 
&aInfoData);
-                               // da ein OQueryTableConnection-Objekt nie den 
Besitz der uebergebenen Daten uebernimmt, sondern sich nur den Zeiger merkt,
-                               // ist dieser Zeiger auf eine lokale Variable 
hier unkritisch, denn aInfoData und aInfo haben die selbe Lebensdauer
-                               pTableView->NotifyTabConnection( aInfo );
-                       }
-                       else
-                       {
-                               ::rtl::OUString 
aSourceFieldName(aDragLeft->GetField());
-                               ::rtl::OUString 
aDestFieldName(aDragRight->GetField());
-                               // the connection could point on the other side
-                               if(pConn->GetSourceWin() == 
aDragRight->GetTabWindow())
-                               {
-                                       ::rtl::OUString aTmp(aSourceFieldName);
-                                       aSourceFieldName = aDestFieldName;
-                                       aDestFieldName = aTmp;
-                               }
-                               pConn->GetData()->AppendConnLine( 
aSourceFieldName,aDestFieldName);
-                               pConn->UpdateLineList();
-                               // Modified-Flag
-                               //      SetModified();
-                               // und neu zeichnen
-                               pConn->RecalcLines();
-                                       // fuer das unten folgende Invalidate 
muss ich dieser neuen Connection erst mal die Moeglichkeit geben,
-                                       // ihr BoundingRect zu ermitteln
-                               pConn->InvalidateConnection();
-                       }
-
+            insertConnection(_pView,_eJoinType,aDragLeft,aDragRight);
                }
                else
                        eErrorCode = eIllegalJoin;
@@ -1088,8 +1162,8 @@
                for(;aIter != _pConnList->end();++aIter)
                {
                        const OQueryTableConnection* pEntryConn = 
static_cast<const OQueryTableConnection*>(*aIter);
-                       OQueryTableConnectionData* pEntryConnData = 
static_cast<OQueryTableConnectionData*>(pEntryConn->GetData());
-                       if(pEntryConnData->GetJoinType() == INNER_JOIN)
+                       OQueryTableConnectionData* pEntryConnData = 
static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get());
+            if ( pEntryConnData->GetJoinType() == INNER_JOIN && 
!pEntryConnData->isNatural() )
                        {
                                if(_rJoinCrit.getLength())
                                        _rJoinCrit += C_AND;
@@ -1132,6 +1206,7 @@
                                
static_cast<OQueryTableConnection*>(*aIter)->SetVisited(sal_False);
 
                        aIter = pConnList->begin();
+            sal_Bool bUseEscape = ::dbtools::getBooleanDataSourceSetting( 
_xConnection, PROPERTY_OUTERJOINESCAPE );
                        for(;aIter != pConnList->end();++aIter)
                        {
                                OQueryTableConnection* pEntryConn = 
static_cast<OQueryTableConnection*>(*aIter);
@@ -1153,14 +1228,25 @@
                                                if(aTableNames.find(sTabName) 
== aTableNames.end())
                                                        aTableNames[sTabName] = 
sal_True;
 
-                                               // create join                  
                
-                        sal_Bool bUseEscape = 
::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_OUTERJOINESCAPE 
);
                                                ::rtl::OUString aStr;
+                        
switch(static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get())->GetJoinType())
+                               {
+                                       case LEFT_JOIN:
+                                       case RIGHT_JOIN:
+                            case FULL_JOIN:
+                                {
+                                                           // create outer join
                                                if ( bUseEscape )
                                                        aStr += 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("{ OJ "));
                                                aStr += aJoin;
                                                if ( bUseEscape )
                                                        aStr += 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" }"));
+                                }
+                                break;
+                            default:
+                                aStr += aJoin;
+                                break;
+                        }
                                                aStr += 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
                                                aTableListStr += aStr;
                                        }
@@ -1206,7 +1292,8 @@
        ::rtl::OUString GenerateGroupBy(const OQueryDesignView* 
_pView,OTableFields& _rFieldList, sal_Bool bMulti )
        {
 
-               Reference< XConnection> xConnection = 
static_cast<OQueryController*>(_pView->getController())->getConnection();
+        OQueryController* pController = 
static_cast<OQueryController*>(_pView->getController());
+               Reference< XConnection> xConnection = 
pController->getConnection();
                if(!xConnection.is())
                        return ::rtl::OUString();
 
@@ -1229,7 +1316,25 @@
                                        if ( pEntryField->isNoneFunction() )
                                                aGroupByStr += 
::dbtools::quoteName(aQuote, pEntryField->GetField());
                                        else
+                    {
+                        ::rtl::OUString aTmp = pEntryField->GetField();
+                                               ::rtl::OUString aErrorMsg;
+                                               Reference<XPropertySet> xColumn;
+                                               ::connectivity::OSQLParseNode* 
pParseNode = 
_pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn);
+                                               if (pParseNode)
+                                               {
+                                                       ::rtl::OUString 
sGroupBy;
+                                                       
pParseNode->parseNodeToStr(     sGroupBy,
+                                                                               
                                xConnection,
+                                                                               
                                &pController->getParser().getContext(),
+                                                                               
                                sal_False,
+                                                                               
                                !pEntryField->isOtherFunction());
+                                                       aGroupByStr += sGroupBy;
+                                                       delete pParseNode;
+                                               }
+                                               else
                                                aGroupByStr += 
pEntryField->GetField();
+                    }
                                        aGroupByStr += ::rtl::OUString(',');
                                }
                        }
@@ -1252,7 +1357,8 @@
                                                                
OSelectionBrowseBox* _pSelectionBrw,
                                                                const 
::connectivity::OSQLParseNode * pCondition,
                                                                sal_uInt16& 
nLevel ,
-                                                               sal_Bool 
bHaving = sal_False);
+                                                               sal_Bool 
bHaving = sal_False,
+                                bool bAddOrOnOneLine = false);
        // 
-----------------------------------------------------------------------------
        SqlParseError GetSelectionCriteria(     OQueryDesignView* _pView,
                                                                                
OSelectionBrowseBox* _pSelectionBrw,
@@ -1296,19 +1402,22 @@
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
                                                                        const  
::connectivity::OSQLParseNode * pCondition,
                                                                        const 
sal_uInt16 nLevel,
-                                                                       
sal_Bool bHaving );
+                                                                       
sal_Bool bHaving,
+                                    bool bAddOrOnOneLine);
        
//------------------------------------------------------------------------------
        SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
                                                        OSelectionBrowseBox* 
_pSelectionBrw,
                                                        const 
::connectivity::OSQLParseNode * pCondition,
                                                        const sal_uInt16 nLevel,
-                                                       sal_Bool bHaving );
+                                                       sal_Bool bHaving,
+                            bool bAddOrOnOneLine);
        
//------------------------------------------------------------------------------
        SqlParseError GetORCriteria(OQueryDesignView* _pView,
                                                                
OSelectionBrowseBox* _pSelectionBrw,
                                                                const 
::connectivity::OSQLParseNode * pCondition,
                                                                sal_uInt16& 
nLevel ,
-                                                               sal_Bool 
bHaving)
+                                                               sal_Bool 
bHaving,
+                                bool bAddOrOnOneLine)
        {
                SqlParseError eErrorCode = eOk;
 
@@ -1317,7 +1426,7 @@
                        SQL_ISPUNCTUATION(pCondition->getChild(0),"(") &&
                        SQL_ISPUNCTUATION(pCondition->getChild(2),")"))
                {
-                       eErrorCode = 
GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1),nLevel,bHaving);
+                       eErrorCode = 
GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1),nLevel,bHaving,bAddOrOnOneLine);
                }
                // oder Verknuepfung
                // a searchcondition can only look like this: search_condition 
SQL_TOKEN_OR boolean_term
@@ -1326,13 +1435,13 @@
                        for (int i = 0; i < 3 && eErrorCode == eOk ; i+=2)
                        {
                                if ( 
SQL_ISRULE(pCondition->getChild(i),search_condition) )
-                                       eErrorCode = 
GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(i),nLevel,bHaving);
+                                       eErrorCode = 
GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(i),nLevel,bHaving,bAddOrOnOneLine);
                                else
-                                       eErrorCode = 
GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(i), nLevel++,bHaving);
+                    eErrorCode = 
GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(i), bAddOrOnOneLine ? 
nLevel : nLevel++,bHaving,bAddOrOnOneLine);
                        }
                }
                else
-                       eErrorCode = GetANDCriteria( 
_pView,_pSelectionBrw,pCondition, nLevel, bHaving );
+                       eErrorCode = GetANDCriteria( 
_pView,_pSelectionBrw,pCondition, nLevel, bHaving,bAddOrOnOneLine );
 
                return eErrorCode;
        }
@@ -1341,7 +1450,8 @@
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
                                                                        const  
::connectivity::OSQLParseNode * pCondition,
                                                                        const 
sal_uInt16 nLevel,
-                                                                       
sal_Bool bHaving )
+                                                                       
sal_Bool bHaving,
+                                    bool bAddOrOnOneLine)
        {
                ::com::sun::star::lang::Locale  aLocale = _pView->getLocale();
                ::rtl::OUString sDecimal = _pView->getDecimalSeparator();
@@ -1354,22 +1464,23 @@
                if (SQL_ISRULE(pCondition,boolean_primary))
                {
                        sal_uInt16 nLevel2 = nLevel;
-                       eErrorCode = 
GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1), nLevel2,bHaving );
+                       eErrorCode = 
GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1), 
nLevel2,bHaving,true );
                }
                // Das erste Element ist (wieder) eine AND-Verknuepfung
                else if ( SQL_ISRULE(pCondition,boolean_term) && 
pCondition->count() == 3 )
                {
-                       eErrorCode = 
GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(0), nLevel,bHaving );
+                       eErrorCode = 
GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(0), 
nLevel,bHaving,bAddOrOnOneLine );
                        if ( eErrorCode == eOk )
-                               eErrorCode = 
GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(2), nLevel,bHaving );
+                               eErrorCode = 
GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(2), 
nLevel,bHaving,bAddOrOnOneLine );
                }
                else if (SQL_ISRULE( pCondition, comparison_predicate))
                {
-                       eErrorCode = 
ComparisonPredicate(_pView,_pSelectionBrw,pCondition,nLevel,bHaving);
+                       eErrorCode = 
ComparisonPredicate(_pView,_pSelectionBrw,pCondition,nLevel,bHaving,bAddOrOnOneLine);
                }
                else if( SQL_ISRULE(pCondition,like_predicate) )
                {
-                       if (SQL_ISRULE(pCondition->getChild(0), column_ref ) )
+            const  ::connectivity::OSQLParseNode* pValueExp = 
pCondition->getChild(0);
+                       if (SQL_ISRULE(pValueExp, column_ref ) )
                        {
                                ::rtl::OUString aColumnName;
                                ::rtl::OUString aCondition;
@@ -1385,7 +1496,7 @@
                                                                                
                                static_cast<sal_Char>(sDecimal.toChar()),
                                                                                
                                &pController->getParser().getContext());
 
-                                       
pCondition->getChild(0)->parseNodeToPredicateStr(       aColumnName,
+                                       pValueExp->parseNodeToPredicateStr(     
aColumnName,
                                                                                
                                                                xConnection,
                                                                                
                                                                
pController->getNumberFormatter(),
                                                                                
                                                                aLocale,
@@ -1398,8 +1509,20 @@
                                }
 
                                OTableFieldDescRef aDragLeft = new 
OTableFieldDesc();
-                               if ( eOk == ( eErrorCode = 
FillDragInfo(_pView,pCondition->getChild(0),aDragLeft) ))
-                                       _pSelectionBrw->AddCondition(aDragLeft, 
aCondition, nLevel);
+                               if ( eOk == ( eErrorCode = 
FillDragInfo(_pView,pValueExp,aDragLeft) ))
+                                       _pSelectionBrw->AddCondition(aDragLeft, 
aCondition, nLevel,bAddOrOnOneLine);
+                       }
+            else if(SQL_ISRULEOR2(pValueExp,general_set_fct ,set_fct_spec)     
        ||
+                                                       
SQL_ISRULEOR2(pValueExp,position_exp,extract_exp)       ||
+                                                       
SQL_ISRULEOR2(pValueExp,fold,char_substring_fct)        ||
+                                                       
SQL_ISRULEOR2(pValueExp,length_exp,char_value_fct))
+                   {
+                           AddFunctionCondition(       _pView,
+                                                                           
_pSelectionBrw,
+                                                                           
pCondition,
+                                                                           
nLevel,
+                                                                           
bHaving,
+                                        bAddOrOnOneLine);
                        }
                        else
                        {
@@ -1417,7 +1540,8 @@
                                                                                
_pSelectionBrw,
                                                                                
pCondition,
                                                                                
nLevel,
-                                                                               
bHaving);
+                                                                               
bHaving,
+                                        bAddOrOnOneLine);
                        }
                        else if ( SQL_ISRULE(pCondition->getChild(0), 
column_ref ) )
                        {
@@ -1425,7 +1549,7 @@
                                ::rtl::OUString sCondition = 
ParseCondition(pController,pCondition,sDecimal,aLocale,1);
                                OTableFieldDescRef      aDragLeft = new 
OTableFieldDesc();
                                if ( eOk == ( eErrorCode = 
FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) )
-                                       _pSelectionBrw->AddCondition(aDragLeft, 
sCondition, nLevel);
+                                       _pSelectionBrw->AddCondition(aDragLeft, 
sCondition, nLevel,bAddOrOnOneLine);
                        }
                }
                else if( SQL_ISRULEOR2(pCondition,existence_test,unique_test) )
@@ -1450,16 +1574,21 @@
                                                        OSelectionBrowseBox* 
_pSelectionBrw,
                                                        const 
::connectivity::OSQLParseNode * pCondition,
                                                        const sal_uInt16 nLevel,
-                                                       sal_Bool bHaving)
+                                                       sal_Bool bHaving,
+                            bool bAddOrOnOneLine)
        {
                SqlParseError eErrorCode = eOk;
                OQueryController* pController = 
static_cast<OQueryController*>(_pView->getController());
-               OSL_ENSURE(SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec 
, general_set_fct ),"Illegal call!");
-               ::rtl::OUString aCondition;
-               OTableFieldDescRef aDragLeft = new OTableFieldDesc();
 
                OSQLParseNode* pFunction = pCondition->getChild(0);
 
+        OSL_ENSURE(SQL_ISRULEOR2(pFunction,general_set_fct ,set_fct_spec)      
        ||
+                                                       
SQL_ISRULEOR2(pFunction,position_exp,extract_exp)       ||
+                                                       
SQL_ISRULEOR2(pFunction,fold,char_substring_fct)        ||
+                                                       
SQL_ISRULEOR2(pFunction,length_exp,char_value_fct),"Illegal call!");
+               ::rtl::OUString aCondition;
+               OTableFieldDescRef aDragLeft = new OTableFieldDesc();
+
                ::rtl::OUString aColumnName;
                Reference< XConnection> xConnection = 
pController->getConnection();
                if(xConnection.is())
@@ -1472,12 +1601,18 @@
                                                                                
                static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
                                                                                
                &pController->getParser().getContext());
 
-                       pFunction->parseNodeToPredicateStr(aColumnName,
+            pFunction->parseNodeToStr( aColumnName,
                                                                                
                xConnection,
-                                                                               
                pController->getNumberFormatter(),
-                                                                               
                _pView->getLocale(),
-                                                                               
                static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
-                                                                               
                &pController->getParser().getContext());
+                                                                               
&pController->getParser().getContext(),
+                                                                               
sal_True,
+                                                                               
sal_True); // quote is to true because we need quoted elements inside the 
function
+            // i75557
+                       //pFunction->parseNodeToPredicateStr(aColumnName,
+                       //                                                      
                xConnection,
+                       //                                                      
                pController->getNumberFormatter(),
+                       //                                                      
                _pView->getLocale(),
+                       //                                                      
                static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
+                       //                                                      
                &pController->getParser().getContext());
                        // don't display the column name
                        aCondition = aCondition.copy(aColumnName.getLength());
                        aCondition = aCondition.trim();
@@ -1529,7 +1664,7 @@
                                        aDragLeft->SetGroupBy(sal_True);
                                
aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
                        }
-                       _pSelectionBrw->AddCondition(aDragLeft, aCondition, 
nLevel);
+                       _pSelectionBrw->AddCondition(aDragLeft, aCondition, 
nLevel,bAddOrOnOneLine);
                }
 
                return eErrorCode;
@@ -1539,7 +1674,8 @@
                                                        OSelectionBrowseBox* 
_pSelectionBrw,
                                                        const 
::connectivity::OSQLParseNode * pCondition,
                                                        const sal_uInt16 nLevel,
-                                                       sal_Bool bHaving )
+                                                       sal_Bool bHaving 
+                            ,bool bAddOrOnOneLine)
        {
                SqlParseError eErrorCode = eOk;
                OQueryController* pController = 
static_cast<OQueryController*>(_pView->getController());
@@ -1558,9 +1694,11 @@
                                        eOk != ( eErrorCode = 
FillDragInfo(_pView,pCondition->getChild(2),aDragRight)))
                                        return eErrorCode;
 
-                               OQueryTableConnection* pConn = 
static_cast<OQueryTableConnection*>(_pView->getTableView()->GetTabConn(static_cast<OQueryTableWindow*>(aDragLeft->GetTabWindow()),
-                                                                               
                                                                                
                                                        
static_cast<OQueryTableWindow*>(aDragRight->GetTabWindow())));
-                               if(pConn)
+                OQueryTableConnection* pConn = 
static_cast<OQueryTableConnection*>(
+                                                    
_pView->getTableView()->GetTabConn(static_cast<OQueryTableWindow*>(aDragLeft->GetTabWindow()),
+                                                                               
                                                                                
           static_cast<OQueryTableWindow*>(aDragRight->GetTabWindow()),
+                                                                               
        true));
+                               if ( pConn )
                                {
                                        OConnectionLineDataVec* pLineDataList = 
pConn->GetData()->GetConnLineDataList();
                                        OConnectionLineDataVec::iterator aIter 
= pLineDataList->begin();
@@ -1648,7 +1786,7 @@
                        {
                                if(bHaving)
                                        aDragLeft->SetGroupBy(sal_True);
-                               _pSelectionBrw->AddCondition(aDragLeft, 
aCondition, nLevel);
+                               _pSelectionBrw->AddCondition(aDragLeft, 
aCondition, nLevel,bAddOrOnOneLine);
                        }
                }
                else if( SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , 
general_set_fct ) )
@@ -1657,7 +1795,8 @@
                                                                        
_pSelectionBrw,
                                                                        
pCondition,
                                                                        nLevel,
-                                                                       
bHaving);
+                                                                       bHaving,
+                                    bAddOrOnOneLine);
                }
                else // kann sich nur um einen Expr. Ausdruck handeln
                {
@@ -1687,7 +1826,7 @@
                        aDragLeft->SetField(aName);
                        aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
                        // und anh"angen
-                       _pSelectionBrw->AddCondition(aDragLeft, aCondition, 
nLevel);
+                       _pSelectionBrw->AddCondition(aDragLeft, aCondition, 
nLevel,bAddOrOnOneLine);
                }
                return eErrorCode;
        }
@@ -1775,22 +1914,33 @@
        sal_Bool InsertJoin(const OQueryDesignView* _pView,
                                                const 
::connectivity::OSQLParseNode *pNode)
        {
-               DBG_ASSERT(SQL_ISRULE(pNode, qualified_join) || 
SQL_ISRULE(pNode, joined_table),
+               DBG_ASSERT(SQL_ISRULE(pNode, qualified_join) || 
SQL_ISRULE(pNode, joined_table) || SQL_ISRULE(pNode, cross_union),
                        "OQueryDesignView::InsertJoin: Fehler im Parse Tree");
 
                if (SQL_ISRULE(pNode,joined_table))
                        return InsertJoin(_pView,pNode->getChild(1));
 
                // first check the left and right side
-               if ( !checkJoinConditions(_pView,pNode->getChild(0)) || 
!checkJoinConditions(_pView,pNode->getChild(3)))
+        ::connectivity::OSQLParseNode* pRightTableRef = pNode->getChild(3); // 
table_ref
+        if ( SQL_ISRULE(pNode, qualified_join) && 
SQL_ISTOKEN(pNode->getChild(1),NATURAL) )
+            pRightTableRef = pNode->getChild(4); // table_ref
+
+               if ( !checkJoinConditions(_pView,pNode->getChild(0)) || 
!checkJoinConditions(_pView,pRightTableRef))
                        return sal_False;
 
                // named column join wird später vieleicht noch implementiert
                // SQL_ISRULE(pNode->getChild(4),named_columns_join)
-               if (SQL_ISRULE(pNode->getChild(4),join_condition))
+        EJoinType eJoinType = INNER_JOIN;
+        bool bNatural = false;
+               if ( SQL_ISRULE(pNode, qualified_join) )
                {
-                       EJoinType eJoinType;
                        ::connectivity::OSQLParseNode* pJoinType = 
pNode->getChild(1); // join_type
+            if ( SQL_ISTOKEN(pJoinType,NATURAL) )
+            {
+                bNatural = true;
+                pJoinType = pNode->getChild(2);
+            }
+
                        if (SQL_ISRULE(pJoinType,join_type) && 
SQL_ISTOKEN(pJoinType->getChild(0),INNER))
                        {
                                eJoinType = INNER_JOIN;
@@ -1807,12 +1957,43 @@
                                else
                                        eJoinType = FULL_JOIN;
                        }
+            if ( SQL_ISRULE(pNode->getChild(4),join_condition) )
+            {
                        if ( 
InsertJoinConnection(_pView,pNode->getChild(4)->getChild(1), eJoinType) != eOk )
                                return sal_False;
                }
+               }
+        else if ( SQL_ISRULE(pNode, cross_union) )
+        {
+            eJoinType = CROSS_JOIN;
+            pRightTableRef = pNode->getChild(pNode->count() - 1);
+        }
                else
                        return sal_False;
 
+        if ( eJoinType == CROSS_JOIN || bNatural )
+        {
+
+            OQueryTableWindow* pLeftWindow = 
static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( 
getTableRange(_pView,pNode->getChild(0)) );
+            OQueryTableWindow* pRightWindow = 
static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( 
getTableRange(_pView,pRightTableRef) );
+            OSL_ENSURE(pLeftWindow && pRightWindow,"Table Windows could not be 
found!");
+            if ( !pLeftWindow || !pRightWindow )
+                return sal_False;
+
+            OTableFieldDescRef aDragLeft  = new OTableFieldDesc();
+            aDragLeft->SetTabWindow(pLeftWindow);
+            aDragLeft->SetTable(pLeftWindow->GetTableName());
+            aDragLeft->SetAlias(pLeftWindow->GetAliasName());
+
+                       OTableFieldDescRef aDragRight = new OTableFieldDesc();
+            aDragRight->SetTabWindow(pRightWindow);
+            aDragRight->SetTable(pRightWindow->GetTableName());
+            aDragRight->SetAlias(pRightWindow->GetAliasName());
+
+            insertConnection(_pView,eJoinType,aDragLeft,aDragRight,bNatural);
+        }
+               
+
                return sal_True;
        }
        
//------------------------------------------------------------------------------
@@ -1888,6 +2069,7 @@
                                ::rtl::OUString sAlias;
 
                                OQueryTableView* pTableView = 
static_cast<OQueryTableView*>(_pView->getTableView());
+                pTableView->clearLayoutInformation();
                                OSQLTables::const_iterator aIter = aMap.begin();
                                for(;aIter != aMap.end();++aIter)
                                {
@@ -2309,19 +2491,48 @@
                SqlParseError eErrorCode = eOk;
                if (!pSelectRoot->getChild(3)->getChild(2)->isLeaf())
                {
+            OQueryController* pController = 
static_cast<OQueryController*>(_pView->getController());
                        ::connectivity::OSQLParseNode* pGroupBy = 
pSelectRoot->getChild(3)->getChild(2)->getChild(2);
                        OTableFieldDescRef aDragInfo = new OTableFieldDesc();
                        for( sal_uInt32 i=0 ; i < pGroupBy->count() && eOk == 
eErrorCode; ++i )
                        {
-                               ::connectivity::OSQLParseNode* pColumnRef = 
pGroupBy->getChild( i );
-                               if(SQL_ISRULE(pColumnRef,column_ref))
+                ::connectivity::OSQLParseNode* pParamRef = NULL;
+                               ::connectivity::OSQLParseNode* pArgument = 
pGroupBy->getChild( i );
+                               if(SQL_ISRULE(pArgument,column_ref))
                                {
-                                       if ( eOk == (eErrorCode = 
FillDragInfo(_pView,pColumnRef,aDragInfo)) )
+                                       if ( eOk == (eErrorCode = 
FillDragInfo(_pView,pArgument,aDragInfo)) )
                                        {
                                                aDragInfo->SetGroupBy(sal_True);
                                                
_pSelectionBrw->AddGroupBy(aDragInfo,i);
                                        }
                                }
+                else if(SQL_ISRULE(pArgument, general_set_fct ) &&
+                                               SQL_ISRULE(pParamRef = 
pArgument->getChild(pArgument->count()-2),column_ref) &&
+                                               eOk == 
FillDragInfo(_pView,pParamRef,aDragInfo))
+                {
+                    aDragInfo->SetGroupBy(sal_True);
+                                       _pSelectionBrw->AddGroupBy( aDragInfo, 
i );
+                }
+                else if( SQL_ISRULE(pArgument, set_fct_spec ) )
+                {                    
+                           Reference< XConnection> xConnection = 
pController->getConnection();
+                           if(xConnection.is())
+                           {
+                        ::rtl::OUString sGroupByExpression;
+                                   pArgument->parseNodeToStr(  
sGroupByExpression,
+                                                                               
                        xConnection,
+                                                                               
                        &pController->getParser().getContext(),
+                                                                               
                        sal_True,
+                                                                               
                        sal_True); // quote is to true because we need quoted 
elements inside the function
+                        
fillFunctionInfo(_pView,pArgument,sGroupByExpression,aDragInfo);
+                        aDragInfo->SetFunctionType(FKT_OTHER);
+                        aDragInfo->SetGroupBy(sal_True);
+                        aDragInfo->SetVisible(sal_False);
+                        _pSelectionBrw->AddGroupBy( aDragInfo, i );
+                    }
+                    else
+                        eErrorCode = eColumnNotFound;
+                }
                        }
                }
                return eErrorCode;
@@ -2381,7 +2592,8 @@
 
        
//------------------------------------------------------------------------------
        
//------------------------------------------------------------------------------
-} // end of anonymouse namespace
+}
+// end of anonymouse namespace
 DBG_NAME(OQueryDesignView)
 
 OQueryDesignView::OQueryDesignView(    OQueryContainerWindow* _pParent,
@@ -2882,7 +3094,7 @@
 OSQLParseNode* OQueryDesignView::getPredicateTreeFromEntry(OTableFieldDescRef 
pEntry,
                                                                                
                                   const String& _sCriteria,
                                                                                
                                   ::rtl::OUString& _rsErrorMessage,
-                                                                               
                                   Reference<XPropertySet>& _rxColumn)
+                                                                               
                                   Reference<XPropertySet>& _rxColumn) const
 {
        OSL_ENSURE(pEntry.isValid(),"Entry is null!");
        if(!pEntry.isValid())
@@ -2902,6 +3114,7 @@
                String sFunction;
                if ( pEntry->isNumericOrAggreateFunction() )
                        sFunction = pEntry->GetFunction();
+
                if ( !sFunction.Len() ) 
                        sFunction = pEntry->GetField();
 
@@ -2991,8 +3204,10 @@
 // 
-----------------------------------------------------------------------------
 sal_Bool OQueryDesignView::InitFromParseNode()
 {
-       SqlParseError eErrorCode;
+       SqlParseError eErrorCode = eNativeMode;
        m_pController->clearError();
+    try
+    {
        if ( (eErrorCode = InitFromParseNodeImpl(this,m_pSelectionBox)) != eOk )
        {
                if ( !m_pController->hasError() ) // fill generell error string
@@ -3002,6 +3217,11 @@
                m_pController->getError(aError);
                m_pController->showError(aError);
        }
+    }
+    catch(Exception&)
+    {
+        OSL_ENSURE(0,"Can not fill query view!");
+    }
        return eErrorCode == eOk;
 }
 // 
-----------------------------------------------------------------------------




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to