Tag: cws_src680_qiq
User: fs      
Date: 06/06/01 05:29:03

Modified:
 /dba/dbaccess/source/core/api/
  SingleSelectQueryComposer.cxx

Log:
 #i51143# getColumns: also create columns if we don't have any SelectColumns 
from the parser (can be built from the ResultSetMetaData)

File Changes:

Directory: /dba/dbaccess/source/core/api/
=========================================

File [changed]: SingleSelectQueryComposer.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/SingleSelectQueryComposer.cxx?r1=1.13.18.5&r2=1.13.18.6
Delta lines:  +150 -108
-----------------------
--- SingleSelectQueryComposer.cxx       24 May 2006 06:40:20 -0000      
1.13.18.5
+++ SingleSelectQueryComposer.cxx       1 Jun 2006 12:29:00 -0000       
1.13.18.6
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: SingleSelectQueryComposer.cxx,v $
  *
- *  $Revision: 1.13.18.5 $
+ *  $Revision: 1.13.18.6 $
  *
- *  last change: $Author: fs $ $Date: 2006/05/24 06:40:20 $
+ *  last change: $Author: fs $ $Date: 2006/06/01 12:29:00 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -89,6 +89,9 @@
 #ifndef _TOOLS_DEBUG_HXX
 #include <tools/debug.hxx>
 #endif
+#ifndef TOOLS_DIAGNOSE_EX_H
+#include <tools/diagnose_ex.h>
+#endif
 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
 #include <com/sun/star/beans/PropertyAttribute.hpp>
 #endif
@@ -723,19 +726,28 @@
 {
        ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
        ::osl::MutexGuard aGuard( m_aMutex );
-       if ( !m_aCurrentColumns[SelectColumns] )
-       {
+       if ( !!m_aCurrentColumns[SelectColumns] )
+        return m_aCurrentColumns[SelectColumns];
+
                ::std::vector< ::rtl::OUString> aNames;
-               ::vos::ORef< OSQLColumns> aCols;
+       ::vos::ORef< OSQLColumns> aSelectColumns;
                sal_Bool bCase = sal_True;
+
+    do {
+
                try
                {
                        bCase = m_xMetaData->storesMixedCaseQuotedIdentifiers();
-                       aCols = m_aSqlIterator.getSelectColumns();
+               aSelectColumns = m_aSqlIterator.getSelectColumns();
                        // now set the columns we have to look if the order of 
the columns is correct
                        Reference<XStatement> xStmt = 
m_xConnection->createStatement();                 
-                       if ( xStmt.is() )
+               if ( !xStmt.is() )
                        {
+                       for(OSQLColumns::const_iterator aIter = 
aSelectColumns->begin(); aIter != aSelectColumns->end();++aIter)
+                               
aNames.push_back(getString((*aIter)->getPropertyValue(PROPERTY_NAME)));
+            break;
+        }
+
                                ::rtl::OUString sSql = m_aPureSelectSQL;
                                sSql += STR_WHERE;
                                sSql += 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" 0 = 1 "));
@@ -752,51 +764,84 @@
 
                                Reference<XResultSetMetaDataSupplier> 
xResMetaDataSup;
                                xResMetaDataSup = 
Reference<XResultSetMetaDataSupplier>(xStmt->executeQuery(sSql),UNO_QUERY);
-                               Reference<XResultSetMetaData> xMeta = 
xResMetaDataSup->getMetaData();
+               Reference<XResultSetMetaData> xResultSetMeta = 
xResMetaDataSup->getMetaData();
 
-                               sal_Int32 nCount = xMeta.is() ? 
xMeta->getColumnCount() : sal_Int32(0);
-                               ::comphelper::UStringMixEqual 
bCase(m_xMetaData->storesMixedCaseQuotedIdentifiers());
-                               ::comphelper::TStringMixEqualFunctor 
bCase2(m_xMetaData->storesMixedCaseQuotedIdentifiers());
-                               ::std::map<OSQLColumns::const_iterator,int> 
aColumnMap;
+        const ::comphelper::UStringMixEqual aCaseCompare( bCase );
+               const ::comphelper::TStringMixEqualFunctor aCaseCompareFunctor( 
bCase );
+        typedef ::std::set< size_t > SizeTSet;
+        SizeTSet aUsedSelectColumns;
 
+               sal_Int32 nCount = xResultSetMeta.is() ? 
xResultSetMeta->getColumnCount() : sal_Int32(0);
                                for(sal_Int32 i=1;i<=nCount;++i)
                                {
-                                       ::rtl::OUString sName = 
xMeta->getColumnName(i);
+                       ::rtl::OUString sName = 
xResultSetMeta->getColumnName(i);
                     sal_Bool bFound = sal_False;
-                                       OSQLColumns::const_iterator aFind = 
::connectivity::find(aCols->begin(),aCols->end(),sName,bCase);
-                                       if(aFind != aCols->end())
-                                               //aNames.end() == 
::std::find_if(aNames.begin(),aNames.end(),::std::bind2nd(bCase2,sName)))
+                       OSQLColumns::const_iterator aFind = 
::connectivity::find(aSelectColumns->begin(),aSelectColumns->end(),sName,aCaseCompare);
+            size_t nFoundSelectColumnPos = aFind - aSelectColumns->begin();
+                       if ( aFind != aSelectColumns->end() )
                                        {
-                                               if(aColumnMap.find(aFind) != 
aColumnMap.end())
+                if ( aUsedSelectColumns.find( nFoundSelectColumnPos ) != 
aUsedSelectColumns.end() )
                                                {       // we found a column 
name which exists twice
                                                        // so we start after 
the first found
                                                        do
                                                        {
-                                                               aFind = 
::connectivity::findRealName(++aFind,aCols->end(),sName,bCase);
+                                               aFind = 
::connectivity::findRealName(++aFind,aSelectColumns->end(),sName,aCaseCompare);
+                        nFoundSelectColumnPos = aFind - 
aSelectColumns->begin();
                                                        }
-                                                       
while(aColumnMap.find(aFind) != aColumnMap.end() && aFind != aCols->end());
+                                       while   (   ( aUsedSelectColumns.find( 
nFoundSelectColumnPos ) != aUsedSelectColumns.end() )
+                            &&  ( aFind != aSelectColumns->end() )
+                            );
                                                }
-                                               if(aFind != aCols->end())
+                               if ( aFind != aSelectColumns->end() )
                                                {
                                                        
(*aFind)->getPropertyValue(PROPERTY_NAME) >>= sName;
-                                                       
aColumnMap.insert(::std::map<OSQLColumns::const_iterator,int>::value_type(aFind,0));
+                                       aUsedSelectColumns.insert( 
nFoundSelectColumnPos );
                                                        aNames.push_back(sName);
                             bFound = sal_True;
                                                }
                                        }
-                                       if ( !bFound )
-                                       { // we can now only look if we found 
it under the realname propertery
-                                               OSQLColumns::const_iterator 
aRealFind = 
::connectivity::findRealName(aCols->begin(),aCols->end(),sName,bCase);
-
-                                               if ( i <= static_cast< 
sal_Int32>(aCols->size()) )
-                                               {
-                                                       if(aRealFind == 
aCols->end())
-                                                       { // here we have to 
make the assumption that the position is correct
-                                                               
OSQLColumns::iterator aFind2 = aCols->begin() + i-1;
-                                                               
Reference<XPropertySet> xProp(*aFind2,UNO_QUERY);
-                                                               if(xProp.is() 
&& xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME))
+
+            if ( bFound )
+                continue;
+
+                       OSQLColumns::const_iterator aRealFind = 
::connectivity::findRealName(
+                aSelectColumns->begin(), aSelectColumns->end(), sName, 
aCaseCompare );
+
+            if ( i > static_cast< sal_Int32>( aSelectColumns->size() ) )
                                                                {
-                                                                       
::connectivity::parse::OParseColumn* pColumn = new 
::connectivity::parse::OParseColumn(xProp,m_xMetaData->storesMixedCaseQuotedIdentifiers());
+                               ::connectivity::parse::OParseColumn* pColumn = 
new ::connectivity::parse::OParseColumn(
+                    sName,
+                               xResultSetMeta->getColumnTypeName( i ),
+                    ::rtl::OUString(),
+                    xResultSetMeta->isNullable( i ),
+                    xResultSetMeta->getPrecision( i ),
+                    xResultSetMeta->getScale( i ),
+                    xResultSetMeta->getColumnType( i ),
+                    xResultSetMeta->isAutoIncrement( i ),
+                    xResultSetMeta->isCurrency( i ),
+                    bCase
+                );
+                pColumn->setTableName(  ::dbtools::composeTableName( 
m_xMetaData,
+                    xResultSetMeta->getCatalogName( i ),
+                    xResultSetMeta->getSchemaName( i ),
+                    xResultSetMeta->getTableName( i ),
+                    sal_False,
+                    eComplete
+                ) );
+
+                aSelectColumns->push_back( pColumn );
+                OSL_ENSURE( aSelectColumns->size() == (size_t)i, 
"OSingleSelectQueryComposer::getColumns: inconsistency!" );
+            }
+            else if ( aRealFind == aSelectColumns->end() )
+                       {
+                // we can now only look if we found it under the realname 
propertery
+                // here we have to make the assumption that the position is 
correct
+                               OSQLColumns::iterator aFind2 = 
aSelectColumns->begin() + i-1;
+                               Reference<XPropertySet> 
xProp(*aFind2,UNO_QUERY);
+                               if ( !xProp.is() || 
!xProp->getPropertySetInfo()->hasPropertyByName( PROPERTY_REALNAME ) )
+                    continue;
+
+                               ::connectivity::parse::OParseColumn* pColumn = 
new ::connectivity::parse::OParseColumn(xProp,bCase);
                                     
pColumn->setFunction(::comphelper::getBOOL(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Function")))));
                                                                        
pColumn->setAggregateFunction(::comphelper::getBOOL(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AggregateFunction")))));
 
@@ -807,39 +852,36 @@
                                                                                
xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
 
                                     
-                                    aFindName = 
::std::find_if(aNames.begin(),aNames.end(),::std::bind2nd(bCase2,sName));
+                aFindName = 
::std::find_if(aNames.begin(),aNames.end(),::std::bind2nd(aCaseCompareFunctor,sName));
                                     sal_Int32 j = 0;
                                     while ( aFindName != aNames.end() )
                                     {                                        
                                         sName += ::rtl::OUString::valueOf(++j);
-                                        aFindName = 
::std::find_if(aNames.begin(),aNames.end(),::std::bind2nd(bCase2,sName));
+                    aFindName = 
::std::find_if(aNames.begin(),aNames.end(),::std::bind2nd(aCaseCompareFunctor,sName));
                                     }
 
                                     pColumn->setName(sName);
                                                                        
pColumn->setRealName(sRealName);
                                                                        
pColumn->setTableName(::comphelper::getString(xProp->getPropertyValue(PROPERTY_TABLENAME)));
                                                                        
-                                                                       
(*aCols)[i-1] = pColumn;
-                                    
aColumnMap.insert(::std::map<OSQLColumns::const_iterator,int>::value_type((*aCols).begin()
 + i-1,0));
-                                                               }
-                                                       }
-                                                       aNames.push_back(sName);
-                                               }
-                                       }
-                               }
-                               ::comphelper::disposeComponent(xStmt);
+                               (*aSelectColumns)[i-1] = pColumn;
                        }
                        else
-                       {
-                               for(OSQLColumns::const_iterator aIter = 
aCols->begin(); aIter != aCols->end();++aIter)
-                                       
aNames.push_back(getString((*aIter)->getPropertyValue(PROPERTY_NAME)));
+                continue;
+
+            aUsedSelectColumns.insert( (size_t)(i - 1) );
+            aNames.push_back( sName );
                        }
+               ::comphelper::disposeComponent(xStmt);
                }
-               catch(Exception&)
+       catch(const Exception&)
                {
+        DBG_UNHANDLED_EXCEPTION();
                }
-               m_aCurrentColumns[SelectColumns] = new 
OPrivateColumns(aCols,bCase,*this,m_aMutex,aNames);
-       }
+
+    } while ( false );
+
+    m_aCurrentColumns[SelectColumns] = new 
OPrivateColumns(aSelectColumns,bCase,*this,m_aMutex,aNames);
        return m_aCurrentColumns[SelectColumns];
 }
 // -------------------------------------------------------------------------




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

Reply via email to