User: obo     
Date: 2006/07/10 08:41:15

Modified:
   dba/dbaccess/source/ui/querydesign/QueryDesignView.cxx

Log:
 INTEGRATION: CWS qiq (1.78.16); FILE MERGED
 2006/07/03 19:48:00 fs 1.78.16.7: #i51143# don't allow to add queries to the 
designer which do not produce a result set
 2006/06/30 13:31:23 fs 1.78.16.6: during #i51143#: PROPERTY_ID_HY0000 
superseded by StandardSQLState.SQL_GENERAL_ERROR
 2006/06/27 12:52:46 fs 1.78.16.5: RESYNC: (1.78-1.79); FILE MERGED
 2006/05/24 06:49:29 fs 1.78.16.4: some refactoring of compose/quoteTableName 
and friends, in preparation of #i51143#
 2006/05/17 04:31:50 fs 1.78.16.3: #i61143# controller's getParser noew 
returning a reference instead of a pointer
 2006/05/15 14:41:03 fs 1.78.16.2: during #i51143#: when adding a table alias 
name, use AS - this is much better understandable to the user
 2006/05/10 11:05:35 fs 1.78.16.1: #i51143# also allow for queries in queries
 (while I was here: SELECT "a" * "b" FROM <table> previously showed wrong
 table information in the graphical view - fixed this)

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.79&r2=1.80
Delta lines:  +323 -262
-----------------------
--- QueryDesignView.cxx 20 Jun 2006 03:26:39 -0000      1.79
+++ QueryDesignView.cxx 10 Jul 2006 15:41:12 -0000      1.80
@@ -86,6 +86,9 @@
 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
 #include <connectivity/dbtools.hxx>
 #endif
+#ifndef _DBHELPER_DBEXCEPTION_HXX_
+#include <connectivity/dbexception.hxx>
+#endif
 #ifndef _COM_SUN_STAR_I18N_XLOCALEDATA_HPP_
 #include <com/sun/star/i18n/XLocaleData.hpp>
 #endif
@@ -138,6 +141,7 @@
 using namespace ::dbaui;
 using namespace ::utl;
 using namespace ::connectivity;
+using namespace ::dbtools;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::i18n;
@@ -171,7 +175,7 @@
        SqlParseError GetHavingCriteria(OQueryDesignView* _pView,
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
                                                                        const 
::connectivity::OSQLParseNode* pSelectRoot,
-                                                                       int 
&rLevel );
+                                                                       
sal_uInt16& rLevel );
 
        SqlParseError GetOrderCriteria( OQueryDesignView* _pView,
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
@@ -180,7 +184,7 @@
        SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
                                                                        const 
::connectivity::OSQLParseNode * pCondition,
-                                                                       const 
int nLevel,
+                                                                       const 
sal_uInt16 nLevel,
                                                                        
sal_Bool bHaving);
 
        
//------------------------------------------------------------------------------
@@ -214,7 +218,7 @@
                                                                
pController->getNumberFormatter(),
                                                                _rLocale,
                                                                
static_cast<sal_Char>(_sDecimal.toChar()),
-                                                               
&pController->getParser()->getContext());
+                                                               
&pController->getParser().getContext());
                }
                return aCondition;
        }
@@ -359,13 +363,13 @@
                        eErrorCode = eColumnNotFound;
                        String sError(ModuleRes(STR_QRY_COLUMN_NOT_FOUND));
                        sError.SearchAndReplaceAscii("$name$",aColumnName);
-                       
_pView->getController()->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000")
 ),1000,Any()));
+                       
_pView->getController()->appendError(SQLException(sError,NULL,getStandardSQLState(
 SQL_GENERAL_ERROR ),1000,Any()));
 
                        try
                        {
                                Reference<XDatabaseMetaData> xMeta = 
_pView->getController()->getConnection()->getMetaData();
                                if ( xMeta.is() && 
xMeta->storesMixedCaseQuotedIdentifiers() )
-                                       
_pView->getController()->appendError(SQLException(String(ModuleRes(STR_QRY_CHECK_CASESENSITIVE)),NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000")
 ),1000,Any()));
+                                       
_pView->getController()->appendError(SQLException(String(ModuleRes(STR_QRY_CHECK_CASESENSITIVE)),NULL,getStandardSQLState(
 SQL_GENERAL_ERROR ),1000,Any()));
                        }
                        catch(Exception&)
                        {
@@ -454,14 +458,14 @@
                        {
                                Reference< XDatabaseMetaData >  xMetaData = 
_xConnection->getMetaData();
 
-                               sal_Bool bUseCatalogInSelect = 
::dbtools::isDataSourcePropertyEnabled(_xConnection,PROPERTY_USECATALOGINSELECT,sal_True);
-                               sal_Bool bUseSchemaInSelect = 
::dbtools::isDataSourcePropertyEnabled(_xConnection,PROPERTY_USESCHEMAINSELECT,sal_True);
-                               ::rtl::OUString aTableListStr = 
::dbtools::quoteTableName(xMetaData,aDBName,::dbtools::eInDataManipulation,bUseCatalogInSelect,bUseSchemaInSelect);
+                ::rtl::OUString sCatalog, sSchema, sTable;
+                ::dbtools::qualifiedNameComponents( xMetaData, aDBName, 
sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
+                               ::rtl::OUString aTableListStr = 
::dbtools::composeTableNameForSelect( _xConnection, sCatalog, sSchema, sTable );
 
                                ::rtl::OUString aQuote = 
xMetaData->getIdentifierQuoteString();
                                if ( isAppendTableAliasEnabled(_xConnection) )
                                {
-                                       aTableListStr += ::rtl::OUString(' ');
+                    aTableListStr += ::rtl::OUString::createFromAscii(" AS ");
                                        aTableListStr += 
::dbtools::quoteName(aQuote, pEntryTab->GetAliasName());
                                }
                                aDBName = aTableListStr;
@@ -628,7 +632,7 @@
                                   pNode->getChild(1)->getNodeType() == 
SQL_NODE_EQUAL))
                        {
                                String 
sError(ModuleRes(STR_QRY_JOIN_COLUMN_COMPARE));
-                               
_pView->getController()->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000")
 ),1000,Any()));
+                               
_pView->getController()->appendError(SQLException(sError,NULL,getStandardSQLState(
 SQL_GENERAL_ERROR ),1000,Any()));
                                return eIllegalJoin;
                        }
 
@@ -746,12 +750,11 @@
                                                {
                                                        OQueryTableWindow* 
pTabWin = static_cast<OQueryTableWindow*>(tableIter->second);
 
-                                                       if ( bFound = 
pTabWin->ExistsField( rFieldName, aInfo ) )
-                                                       {
+                            bFound = pTabWin->ExistsField( rFieldName, aInfo );
+                                                       if ( bFound )
                                                                rFieldName = 
aInfo->GetField();
                                                        }
-                                               }
-                                               if ( rFieldName.toChar() != '*' 
)
+                                               if ( ( rFieldName.toChar() != 
'*' ) && ( rFieldName.indexOf( aQuote ) == -1 ) )
                                                {
                                                        
OSL_ENSURE(pEntryField->GetTable().getLength(),"No table field name!");
                                                        aTmpStr += 
::dbtools::quoteName(aQuote, rFieldName);
@@ -809,7 +812,7 @@
                OTableFields::iterator aIter = _rFieldList.begin();
                for(;aIter != _rFieldList.end();++aIter)
                {
-                       nMaxCriteria = 
::std::max<sal_uInt16>(nMaxCriteria,(*aIter)->GetCriteria().size());
+                       nMaxCriteria = 
::std::max<sal_uInt16>(nMaxCriteria,(sal_uInt16)(*aIter)->GetCriteria().size());
                }
                Reference< XConnection> xConnection = 
static_cast<OQueryController*>(_pView->getController())->getConnection();
                if(!xConnection.is())
@@ -818,7 +821,7 @@
                {
                        Reference< XDatabaseMetaData >  xMetaData = 
xConnection->getMetaData();
                        ::rtl::OUString aQuote = 
xMetaData->getIdentifierQuoteString();
-                       const IParseContext& rContext = 
static_cast<OQueryController*>(_pView->getController())->getParser()->getContext();
+                       const IParseContext& rContext = 
static_cast<OQueryController*>(_pView->getController())->getParser().getContext();
 
                        for (sal_uInt16 i=0 ; i < nMaxCriteria ; i++)
                        {
@@ -1034,7 +1037,7 @@
                                                aWorkStr += 
::dbtools::quoteName(aQuote, aColumnName);
                                        }
                                        aWorkStr += ::rtl::OUString(' ');
-                                       aWorkStr += String::CreateFromAscii( 
";ASC;DESC" ).GetToken( eOrder );
+                                       aWorkStr += String::CreateFromAscii( 
";ASC;DESC" ).GetToken( (USHORT)eOrder );
                                        aWorkStr += ::rtl::OUString(',');
                                }
                        }
@@ -1238,13 +1241,13 @@
        SqlParseError GetORCriteria(OQueryDesignView* _pView,
                                                                
OSelectionBrowseBox* _pSelectionBrw,
                                                                const 
::connectivity::OSQLParseNode * pCondition,
-                                                               int& nLevel ,
+                                                               sal_uInt16& 
nLevel ,
                                                                sal_Bool 
bHaving = sal_False);
        // 
-----------------------------------------------------------------------------
        SqlParseError GetSelectionCriteria(     OQueryDesignView* _pView,
                                                                                
OSelectionBrowseBox* _pSelectionBrw,
                                                                                
const ::connectivity::OSQLParseNode* pNode,
-                                                                               
int& rLevel )
+                                                                               
sal_uInt16& rLevel )
        {
                if (!SQL_ISRULE(pNode, select_statement))
                        return eNoSelectStatement;
@@ -1282,19 +1285,19 @@
        SqlParseError GetANDCriteria(   OQueryDesignView* _pView,
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
                                                                        const  
::connectivity::OSQLParseNode * pCondition,
-                                                                       const 
int nLevel,
+                                                                       const 
sal_uInt16 nLevel,
                                                                        
sal_Bool bHaving );
        
//------------------------------------------------------------------------------
        SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
                                                        OSelectionBrowseBox* 
_pSelectionBrw,
                                                        const 
::connectivity::OSQLParseNode * pCondition,
-                                                       const int nLevel,
+                                                       const sal_uInt16 nLevel,
                                                        sal_Bool bHaving );
        
//------------------------------------------------------------------------------
        SqlParseError GetORCriteria(OQueryDesignView* _pView,
                                                                
OSelectionBrowseBox* _pSelectionBrw,
                                                                const 
::connectivity::OSQLParseNode * pCondition,
-                                                               int& nLevel ,
+                                                               sal_uInt16& 
nLevel ,
                                                                sal_Bool 
bHaving)
        {
                SqlParseError eErrorCode = eOk;
@@ -1327,7 +1330,7 @@
        SqlParseError GetANDCriteria(   OQueryDesignView* _pView,
                                                                        
OSelectionBrowseBox* _pSelectionBrw,
                                                                        const  
::connectivity::OSQLParseNode * pCondition,
-                                                                       const 
int nLevel,
+                                                                       const 
sal_uInt16 nLevel,
                                                                        
sal_Bool bHaving )
        {
                ::com::sun::star::lang::Locale  aLocale = _pView->getLocale();
@@ -1340,7 +1343,7 @@
                // Runde Klammern
                if (SQL_ISRULE(pCondition,boolean_primary))
                {
-                       int nLevel2 = nLevel;
+                       sal_uInt16 nLevel2 = nLevel;
                        eErrorCode = 
GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1), nLevel2,bHaving );
                }
                // Das erste Element ist (wieder) eine AND-Verknuepfung
@@ -1370,14 +1373,14 @@
                                                                                
                                pController->getNumberFormatter(),
                                                                                
                                aLocale,
                                                                                
                                static_cast<sal_Char>(sDecimal.toChar()),
-                                                                               
                                &pController->getParser()->getContext());
+                                                                               
                                &pController->getParser().getContext());
 
                                        
pCondition->getChild(0)->parseNodeToPredicateStr(       aColumnName,
                                                                                
                                                                xMetaData,
                                                                                
                                                                
pController->getNumberFormatter(),
                                                                                
                                                                aLocale,
                                                                                
                                                                
static_cast<sal_Char>(sDecimal.toChar()),
-                                                                               
                                                                
&pController->getParser()->getContext());
+                                                                               
                                                                
&pController->getParser().getContext());
 
                                        // don't display the column name
                                        aCondition = 
aCondition.copy(aColumnName.getLength());
@@ -1392,7 +1395,7 @@
                        {
                                eErrorCode = eNoColumnInLike;
                                String 
sError(ModuleRes(STR_QRY_LIKE_LEFT_NO_COLUMN));
-                               
_pView->getController()->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000")
 ),1000,Any()));
+                               
_pView->getController()->appendError(SQLException(sError,NULL,getStandardSQLState(
 SQL_GENERAL_ERROR ),1000,Any()));
                        }
                }
                else if(        
SQL_ISRULEOR2(pCondition,test_for_null,in_predicate)
@@ -1436,7 +1439,7 @@
        SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
                                                        OSelectionBrowseBox* 
_pSelectionBrw,
                                                        const 
::connectivity::OSQLParseNode * pCondition,
-                                                       const int nLevel,
+                                                       const sal_uInt16 nLevel,
                                                        sal_Bool bHaving)
        {
                SqlParseError eErrorCode = eOk;
@@ -1457,14 +1460,14 @@
                                                                                
                pController->getNumberFormatter(),
                                                                                
                _pView->getLocale(),
                                                                                
                static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
-                                                                               
                &pController->getParser()->getContext());
+                                                                               
                &pController->getParser().getContext());
 
                        pFunction->parseNodeToPredicateStr(aColumnName,
                                                                                
                xMetaData,
                                                                                
                pController->getNumberFormatter(),
                                                                                
                _pView->getLocale(),
                                                                                
                static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
-                                                                               
                &pController->getParser()->getContext());
+                                                                               
                &pController->getParser().getContext());
                        // don't display the column name
                        aCondition = aCondition.copy(aColumnName.getLength());
                        aCondition = aCondition.trim();
@@ -1497,7 +1500,7 @@
                                        ::rtl::OUString sParameterValue;
                                        pParamNode->parseNodeToStr(     
sParameterValue,
                                                                                
                xConnection->getMetaData(),
-                                                                               
                &pController->getParser()->getContext());
+                                                                               
                &pController->getParser().getContext());
                                        nFunctionType |= FKT_NUMERIC;
                                        aDragLeft->SetField(sParameterValue);
                                        eErrorCode = eOk;
@@ -1525,7 +1528,7 @@
        SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
                                                        OSelectionBrowseBox* 
_pSelectionBrw,
                                                        const 
::connectivity::OSQLParseNode * pCondition,
-                                                       const int nLevel,
+                                                       const sal_uInt16 nLevel,
                                                        sal_Bool bHaving )
        {
                SqlParseError eErrorCode = eOk;
@@ -1625,7 +1628,7 @@
                                                                                
                pController->getNumberFormatter(),
                                                                                
                _pView->getLocale(),
                                                                                
                static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
-                                                                               
                &pController->getParser()->getContext());
+                                                                               
                &pController->getParser().getContext());
                                }
                        }
                        // else ???
@@ -1659,7 +1662,7 @@
                                Reference< XDatabaseMetaData >  xMetaData = 
xConnection->getMetaData();
                                pLhs->parseNodeToStr(aName,
                                                                                
        xMetaData,
-                                                                               
        &pController->getParser()->getContext(),
+                                                                               
        &pController->getParser().getContext(),
                                                                                
        sal_True);
                                // Kriterium
                                aCondition = 
pCondition->getChild(1)->getTokenValue();
@@ -1668,7 +1671,7 @@
                                                                                
                                        pController->getNumberFormatter(),
                                                                                
                                        _pView->getLocale(),
                                                                                
                                        
static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
-                                                                               
                                        
&pController->getParser()->getContext());
+                                                                               
                                        &pController->getParser().getContext());
                        }
 
                        OTableFieldDescRef aDragLeft = new OTableFieldDesc();
@@ -1679,6 +1682,23 @@
                }
                return eErrorCode;
        }
+
+    
//------------------------------------------------------------------------------
+    namespace
+    {
+        OQueryTableWindow* lcl_findColumnInTables( const ::rtl::OUString& 
_rColumName, const OJoinTableView::OTableWindowMap& _rTabList, 
OTableFieldDescRef& _rInfo )
+        {
+                       OJoinTableView::OTableWindowMap::const_iterator aIter = 
_rTabList.begin();
+                       for ( ; aIter != _rTabList.end(); ++aIter )
+                       {
+                               OQueryTableWindow* pTabWin = static_cast< 
OQueryTableWindow* >( aIter->second );
+                               if ( pTabWin && pTabWin->ExistsField( 
_rColumName, _rInfo ) )
+                                       return pTabWin;
+                       }
+            return NULL;
+        }
+    }
+
        
//------------------------------------------------------------------------------
        void InsertColumnRef(const OQueryDesignView* _pView,
                                                const 
::connectivity::OSQLParseNode * pColumnRef,
@@ -1698,18 +1718,9 @@
                if (!aTableRange.getLength())
                {
                        // SELECT column, ...
-                       OJoinTableView::OTableWindowMap::iterator aIter = 
pTabList->begin();
-                       for(;aIter != pTabList->end();++aIter)
-                       {
-                               OQueryTableWindow* pTabWin = 
static_cast<OQueryTableWindow*>(aIter->second);
-                               if (pTabWin && pTabWin->ExistsField( 
aColumnName, _raInfo ) )
-                               {
-                                       if(aColumnName.toChar() != '*')
+            bFound = NULL != lcl_findColumnInTables( aColumnName, *pTabList, 
_raInfo );
+                       if ( bFound && ( aColumnName.toChar() != '*' ) )
                                                
_raInfo->SetFieldAlias(aColumnAlias);
-                                       bFound = sal_True;
-                                       break;
-                               }
-                       }
                }
                else
                {
@@ -1821,27 +1832,48 @@
                ::connectivity::OSQLParseTreeIterator& aIterator = 
pController->getParseIterator();
                const ::connectivity::OSQLParseNode* pParseTree = 
aIterator.getParseTree();
 
-               if (pParseTree)
+        do
+        {
+            if ( !pParseTree )
+            {
+                           // now we have to insert the fields which aren't in 
the statement
+                           insertUnUsedFields(_pView,_pSelectionBrw);
+                break;
+            }
+
+            if ( !pController->isEsacpeProcessing() ) // not allowed in this 
mode
                {
-                       if (!pController->isEsacpeProcessing()) // not allowed 
in this mode
                                eErrorCode = eNativeMode;
-                       else if (SQL_ISRULE(pParseTree,select_statement))
+                break;
+            }
+
+                       if ( !( SQL_ISRULE( pParseTree, select_statement ) ) )
                        {
-                               const OSQLTables& aMap = aIterator.getTables();
-                               ::comphelper::UStringMixLess 
aTmp(aMap.key_comp());
-                               ::comphelper::UStringMixEqual 
aKeyComp(static_cast< ::comphelper::UStringMixLess*>(&aTmp)->isCaseSensitive());
+                               eErrorCode = eNoSelectStatement;
+                break;
+            }
 
                                Reference< XConnection> xConnection = 
pController->getConnection();
-                               if(xConnection.is())
+                       if ( !xConnection.is() )
                                {
-                                       sal_Int32 nMax = 0;
+                DBG_ERROR( "InitFromParseNodeImpl: no connection? no 
connection!" );
+                break;
+            }
+
+                       const OSQLTables& aMap = aIterator.getTables();
+                       ::comphelper::UStringMixLess aTmp(aMap.key_comp());
+                       ::comphelper::UStringMixEqual aKeyComp( 
aTmp.isCaseSensitive() );
+
                                        Reference< XDatabaseMetaData >  
xMetaData = xConnection->getMetaData();
                                        try
                                        {
-                                               nMax = 
xMetaData->getMaxTablesInSelect();
-
-                                               if(!nMax || nMax >= 
(sal_Int32)aMap.size()) // Anzahl der Tabellen im Select-Statement "uberpr"ufen
+                           sal_Int32 nMax = xMetaData->getMaxTablesInSelect();
+                if ( nMax && nMax < (sal_Int32)aMap.size() )
                                                {
+                                       eErrorCode = eTooManyTables;
+                    break;
+                }
+
                                                        ::rtl::OUString 
sComposedName;
                                                        ::rtl::OUString 
aQualifierName;
                                                        ::rtl::OUString sAlias;
@@ -1851,26 +1883,40 @@
                                                        for(;aIter != 
aMap.end();++aIter)
                                                        {
                                                                OSQLTable 
xTable = aIter->second;
-                                                               sComposedName = 
::dbtools::composeTableName(xMetaData,Reference<XPropertySet>(xTable,UNO_QUERY),sal_False,::dbtools::eInDataManipulation);
+                    Reference< XPropertySet > xTableProps( xTable, 
UNO_QUERY_THROW );
+
                                                                sAlias = 
aIter->first;
-                                                               
if(aKeyComp(sComposedName,aIter->first))
+
+                    // check whether this is a query
+                    Reference< XPropertySetInfo > xPSI = 
xTableProps->getPropertySetInfo();
+                    bool bIsQuery = xPSI.is() && xPSI->hasPropertyByName( 
PROPERTY_COMMAND );
+
+                    if ( bIsQuery )
+                        OSL_VERIFY( xTableProps->getPropertyValue( 
PROPERTY_NAME ) >>= sComposedName );
+                    else
+                    {
+                        sComposedName = ::dbtools::composeTableName( 
xMetaData, xTableProps, ::dbtools::eInDataManipulation, false, false, false );
+
+                        // if the alias is the complete (composed) table, then 
shorten it
+                        if ( aKeyComp( sComposedName, aIter->first ) )
                                                                {
-                                                                       
::rtl::OUString sCatalog,sSchema,sTable;
-                                                                       
::dbtools::qualifiedNameComponents(xMetaData,sComposedName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
+                                                   ::rtl::OUString sCatalog, 
sSchema, sTable;
+                                                   
::dbtools::qualifiedNameComponents( xMetaData, sComposedName, sCatalog, 
sSchema, sTable, ::dbtools::eInDataManipulation );
                                                                        sAlias 
= sTable;
                                                                }
+                    }
 
-
-                                                               
OQueryTableWindow* pExistentWin = pTableView->FindTable(sAlias);
-                                                               if 
(!pExistentWin)
+                    // find the existent window for this alias
+                                       OQueryTableWindow* pExistentWin = 
pTableView->FindTable( sAlias );
+                                       if ( !pExistentWin )
                                                                {
-                                                                       
pTableView->AddTabWin(sComposedName, sAlias,sal_False);// don't create data here
+                                               pTableView->AddTabWin( 
sComposedName, sAlias, sal_False );  // don't create data here
                                                                }
                                                                else
                                                                {
-                                                                       // es 
existiert schon ein Fenster mit dem selben Alias ...
-                                                                       if 
(!aKeyComp(pExistentWin->GetData()->GetComposedName(),sComposedName))
-                                                                               
// ... aber anderem Tabellennamen -> neues Fenster
+                                               // there already exists a 
window for this alias ....
+                                               if ( !aKeyComp( 
pExistentWin->GetData()->GetComposedName(), sComposedName ) )
+                                                       // ... but for another 
complete table name -> new window
                                                                                
pTableView->AddTabWin(sComposedName, sAlias);
                                                                }
                                                        }
@@ -1895,8 +1941,8 @@
                                                                }
                                                                if ( 
(eErrorCode = InstallFields(_pView,pParseTree, pTableView->GetTabWinMap())) == 
eOk )
                                                                {
-                                                                       // 
GetSelectionCriteria mu"s vor GetHavingCriteria aufgerufen werden
-                                                                       int 
nLevel=0;
+                                               // GetSelectionCriteria must be 
called before GetHavingCriteria
+                                               sal_uInt16 nLevel=0;
 
                                                                        if ( 
eOk == (eErrorCode = 
GetSelectionCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
                                                                        {
@@ -1912,23 +1958,12 @@
                                                                }
                                                        }
                                                }
-                                               else
-                                                       eErrorCode = 
eTooManyTables;
-                                       }
                                        catch(SQLException&)
                                        {
                                                
OSL_ASSERT(!"getMaxTablesInSelect!");
                                        }
                                }
-                       }
-                       else
-                               eErrorCode = eNoSelectStatement;
-               }
-               else
-               {
-                       // now we have to insert the fields which aren't in the 
statement
-                       insertUnUsedFields(_pView,_pSelectionBrw);
-               }
+        while ( false );
 
                // Durch das Neuerzeugen wurden wieder Undo-Actions in den 
Manager gestellt
                pController->getUndoMgr()->Clear();
@@ -1990,21 +2025,25 @@
                        {
                                ::connectivity::OSQLParseNode * pColumnRef = 
pParseTree->getChild(i);
 
+                do {
+
                                if ( SQL_ISRULE(pColumnRef,select_sublist) )
                                {
                                         eErrorCode = 
fillSelectSubList(_pView,pTabList);
+                     break;
                                }
-                               else if ( SQL_ISRULE(pColumnRef,derived_column) 
)
-                               {
-                                       if ( xConnection.is() )
+
+                if ( SQL_ISRULE(pColumnRef,derived_column) )
                                        {
+                                       if ( !xConnection.is() )
+                        break;
+
                                                Reference< XDatabaseMetaData >  
xMetaData = xConnection->getMetaData();
                                                ::rtl::OUString 
aColumnAlias(pController->getParseIterator().getColumnAlias(pColumnRef)); // 
kann leer sein
                                                pColumnRef = 
pColumnRef->getChild(0);
                                                OTableFieldDescRef aInfo = new 
OTableFieldDesc();
 
-                                               if (    
-                                                               
pColumnRef->count() == 3 &&
+                                       if (    pColumnRef->count() == 3 &&
                                                                
SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") &&
                                                                
SQL_ISPUNCTUATION(pColumnRef->getChild(2),")")
                                                        )
@@ -2024,7 +2063,7 @@
                                                        ::rtl::OUString 
aColumns;
                                                        
pColumnRef->parseNodeToStr(     aColumns,
                                                                                
                                xMetaData,
-                                                                               
                                &pController->getParser()->getContext(),
+                                                                               
                        &pController->getParser().getContext(),
                                                                                
                                sal_True,
                                                                                
                                sal_True); // quote is to true because we need 
quoted elements inside the function
 
@@ -2066,7 +2105,7 @@
                                                                                
sFieldName = ::rtl::OUString();
                                                                                
pParamRef->parseNodeToStr(      sFieldName,
                                                                                
                                        xMetaData,
-                                                                               
                                        &pController->getParser()->getContext(),
+                                                                               
                                &pController->getParser().getContext(),
                                                                                
                                        sal_True,
                                                                                
                                        sal_True); // quote is to true because 
we need quoted elements inside the function
                                                                        }
@@ -2095,7 +2134,7 @@
 
                                                                        
nDataType = OSQLParser::getFunctionReturnType(
                                                                                
                                sFunctionName
-                                                                               
                                ,&pController->getParser()->getContext());
+                                                                               
                        ,&pController->getParser().getContext());
                                                                }
                                                                
aInfo->SetDataType(nDataType);
                                                                
aInfo->SetFieldType(TAB_NORMAL_FIELD);
@@ -2121,13 +2160,30 @@
                                                        ::rtl::OUString 
aColumns;
                                                        
pColumnRef->parseNodeToStr(     aColumns,
                                                                                
                                xMetaData,
-                                                                               
                                &pController->getParser()->getContext(),
+                                                                               
                        &pController->getParser().getContext(),
                                                                                
                                sal_True,
                                                                                
                                sal_True); // quote is to true because we need 
quoted elements inside the function
 
+                        aInfo->SetTabWindow( NULL );
+
+                        // since we support queries in queries, the thingie 
might belong to an existing "table"
+                        if ( !lcl_findColumnInTables( aColumns, *pTabList, 
aInfo ) )
+                        {
+                            // okay, it doesn't belong to a query directly. In 
this case, it must belong
+                            // to the (only) table in the FROM part
+                            DBG_ASSERT( pTabList->size() == 1, "InstallFields: 
unqualified expression, but more or less than one table!" );
+                            if ( !pTabList->empty() )
+                            {
+                                OQueryTableWindow* pWindow = static_cast< 
OQueryTableWindow* >( pTabList->begin()->second );
+                                aInfo->SetTabWindow( pWindow );
+                                                   aInfo->SetTable( 
pWindow->GetTableName() );
+                                                   aInfo->SetAlias( 
pWindow->GetAliasName() );
+                                                   aInfo->SetDatabase( 
pWindow->GetComposedName() );
+                            }
+                        }
+
                                                        
aInfo->SetDataType(DataType::DOUBLE);
                                                        
aInfo->SetFieldType(TAB_NORMAL_FIELD);
-                                                       
aInfo->SetTabWindow(NULL);
                                                        
aInfo->SetField(aColumns);
                                                        
aInfo->SetFieldAlias(aColumnAlias);
                                                        
aInfo->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
@@ -2135,8 +2191,13 @@
                                                        eErrorCode = 
_pView->InsertField(aInfo, sal_True, bFirstField);
                                                        bFirstField = sal_False;
                                                }
+
+                    break;
                                        }
-                               }
+
+                DBG_ERROR( "InstallFields: don't know how to interpret this 
parse node!" );
+
+                } while ( false );
                        }
                }
                else
@@ -2201,7 +2262,7 @@
        SqlParseError GetHavingCriteria(        OQueryDesignView* _pView,
                                                        OSelectionBrowseBox* 
_pSelectionBrw,
                                                        const 
::connectivity::OSQLParseNode* pSelectRoot,
-                                                       int &rLevel )
+                                                       sal_uInt16& rLevel )
        {
                SqlParseError eErrorCode = eOk;
                if (!pSelectRoot->getChild(3)->getChild(3)->isLeaf())
@@ -2282,7 +2343,7 @@
                //      ErrorBox( _pWindow, ModuleRes( nResId ) ).Execute();
                ModuleRes aRes(nResId);
                String sError(aRes);
-               
_pEnvironment->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000")
 ),1000,Any()));
+               
_pEnvironment->appendError(SQLException(sError,NULL,getStandardSQLState( 
SQL_GENERAL_ERROR ),1000,Any()));
        }
        // 
-----------------------------------------------------------------------------
 
@@ -2813,7 +2874,7 @@
        if(!xConnection.is())
                return NULL;
 
-       ::connectivity::OSQLParser* pParser = 
static_cast<OQueryController*>(getController())->getParser();
+       ::connectivity::OSQLParser& rParser( 
static_cast<OQueryController*>(getController())->getParser() );
        OQueryTableWindow* pWin = 
static_cast<OQueryTableWindow*>(pEntry->GetTabWindow());
 
        String sTest(_sCriteria);
@@ -2830,7 +2891,7 @@
                if(sFunction.GetTokenCount('(') > 1)
                        sFunction = sFunction.GetToken(0,'('); // this should 
be the name of the function
 
-               sal_Int32 nType = 
::connectivity::OSQLParser::getFunctionReturnType(sFunction,&pParser->getContext());
+               sal_Int32 nType = 
::connectivity::OSQLParser::getFunctionReturnType(sFunction,&rParser.getContext());
                if ( nType == DataType::OTHER || (!sFunction.Len() && 
pEntry->isNumericOrAggreateFunction()) )
                {
                        // first try the international version
@@ -2839,7 +2900,7 @@
                        sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" 
FROM x WHERE "));
                        sSql += pEntry->GetField();
                        sSql += _sCriteria;
-                       OSQLParseNode* pParseNode = pParser->parseTree( 
_rsErrorMessage,sSql,sal_True);
+                       OSQLParseNode* pParseNode = rParser.parseTree( 
_rsErrorMessage, sSql, sal_True );
                        nType = DataType::DOUBLE;
                        if ( pParseNode )
                        {
@@ -2881,7 +2942,7 @@
                }
        }
 
-       OSQLParseNode* pParseNode = pParser->predicateTree(     _rsErrorMessage,
+       OSQLParseNode* pParseNode = rParser.predicateTree(      _rsErrorMessage,
                                                                                
                                sTest,
                                                                                
                                
static_cast<OQueryController*>(getController())->getNumberFormatter(),
                                                                                
                                _rxColumn);




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

Reply via email to