User: obo     
Date: 2006/07/10 08:05:47

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

Log:
 INTEGRATION: CWS qiq (1.29.124); FILE MERGED
 2006/07/06 07:13:12 fs 1.29.124.7: #i46159# when retrieving composer columns, 
also use our own fallback when there is an _empty_ columns collection
 2006/07/03 19:48:47 fs 1.29.124.6: #i51143# warning when trying to obtain 
columns for a query whose statement does not produce a result set
 2006/06/30 13:27:17 fs 1.29.124.5: #i51143# protect against recusive sub 
queries
 2006/06/27 11:51:49 fs 1.29.124.4: RESYNC: (1.29-1.30); FILE MERGED
 2006/06/06 13:59:41 fs 1.29.124.3: #i51143# implCollectColumns: provide 
columns even if the QueryComposer cannot parse our statement (as long as at 
least the underlying connection can)
 2006/06/01 12:49:35 fs 1.29.124.2: oops. implCollectColumns should throw if 
not parsable
 2006/06/01 12:32:48 fs 1.29.124.1: #i51143# also try to retrieve columns if 
the EscapeProcessing is FALSE - may be we're lucky ... (needed when such a 
query is added to the query designer)

File Changes:

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

File [changed]: query.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/query.cxx?r1=1.30&r2=1.31
Delta lines:  +80 -55
---------------------
--- query.cxx   20 Jun 2006 02:39:43 -0000      1.30
+++ query.cxx   10 Jul 2006 15:05:45 -0000      1.31
@@ -42,6 +42,15 @@
 #ifndef DBA_CORE_WARNINGS_HXX
 #include "warnings.hxx"
 #endif
+#ifndef DBA_HELPERCOLLECTIONS_HXX
+#include "HelperCollections.hxx"
+#endif
+#ifndef _DBA_CORE_RESOURCE_HXX_
+#include "core_resource.hxx"
+#endif
+#ifndef _DBA_CORE_RESOURCE_HRC_
+#include "core_resource.hrc"
+#endif
 
 #ifndef _CPPUHELPER_QUERYINTERFACE_HXX_
 #include <cppuhelper/queryinterface.hxx>
@@ -49,6 +58,9 @@
 #ifndef _TOOLS_DEBUG_HXX
 #include <tools/debug.hxx>
 #endif
+#ifndef TOOLS_DIAGNOSE_EX_H
+#include <tools/diagnose_ex.h>
+#endif
 #ifndef _COMPHELPER_PROPERTY_AGGREGATION_HXX_
 #include <comphelper/propagg.hxx>
 #endif
@@ -56,27 +68,33 @@
 #include <comphelper/sequence.hxx>
 #endif
 
+/** === begin UNO includes === **/
 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
 #include <com/sun/star/sdbc/XConnection.hpp>
 #endif
 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
 #include <com/sun/star/lang/DisposedException.hpp>
 #endif
+#ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
+#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
+#endif
+#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
+#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
+#endif
+/** === end UNO includes === **/
+
 #ifndef _COMPHELPER_TYPES_HXX_ 
 #include <comphelper/types.hxx>
 #endif
 #ifndef _COMPHELPER_PROPERTY_HXX_
 #include <comphelper/property.hxx>
 #endif
+#ifndef UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX
+#include <unotools/sharedunocomponent.hxx>
+#endif
 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
 #include "definitioncolumn.hxx"
 #endif
-#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSERFACTORY_HPP_
-#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
-#endif
-#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
-#include <com/sun/star/sdb/XSQLQueryComposer.hpp>
-#endif
 
 #include <functional>
 
@@ -105,6 +123,7 @@
 using namespace ::comphelper;
 using namespace ::osl;
 using namespace ::cppu;
+using namespace ::utl;
 
 //........................................................................
 namespace dbaccess
@@ -164,12 +183,13 @@
 IMPLEMENT_GETTYPES3(OQuery,OQueryDescriptor_Base,ODataSettings,OContentHelper);
 IMPLEMENT_FORWARD_XINTERFACE3( 
OQuery,OContentHelper,OQueryDescriptor_Base,ODataSettings)
 //--------------------------------------------------------------------------
-void OQuery::implCollectColumns( )
+void OQuery::rebuildColumns()
 {
+    OSL_PRECOND( getColumnCount() == 0, "OQuery::rebuildColumns: column 
container should be empty!" );
+        // the base class' definition of rebuildColumns promised that 
clearColumns is called before rebuildColumns
+
        try
        {
-               // empty the target container
-               clearColumns( );
                m_pMediator = NULL;
                m_xColumnMediator = NULL;
 
@@ -185,29 +205,42 @@
                }
 
                // fill the columns with columns from the statement
-               Reference< XSQLQueryComposerFactory >  xFactory(m_xConnection, 
UNO_QUERY);
-               Reference< XSQLQueryComposer > xComposer;
-               if ( xFactory.is() && m_bEscapeProcessing )
-               {
+               Reference< XMultiServiceFactory > xFactory( m_xConnection, 
UNO_QUERY_THROW );
+        SharedUNOComponent< XSingleSelectQueryComposer, DisposableComponent > 
xComposer(
+            Reference< XSingleSelectQueryComposer >( xFactory->createInstance( 
SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW ) );
+
+        Reference< XNameAccess > xColumns;
+        Reference< XIndexAccess > xColumnsIndexed;
                        try
                        {
-                               xComposer = xFactory->createQueryComposer();
-                       }
-                       catch (Exception&)
-                       {
-                               xComposer = NULL;
-                       }
+                       xComposer->setQuery( m_sCommand );
+                   Reference< XColumnsSupplier > xCols( xComposer, 
UNO_QUERY_THROW );
+                   xColumns.set( xCols->getColumns(), UNO_QUERY_THROW );
+            xColumnsIndexed.set( xColumns, UNO_QUERY_THROW );
+        }
+        catch( const SQLException& ) { }
+
+        SharedUNOComponent< XPreparedStatement, DisposableComponent > 
xPreparedStatement;
+        if ( !xColumns.is() || ( xColumnsIndexed->getCount() == 0 ) )
+        {   // the QueryComposer could not parse it. Try a lean version.
+            xPreparedStatement.set( m_xConnection->prepareStatement( 
m_sCommand ), UNO_QUERY_THROW );
+                   Reference< XResultSetMetaDataSupplier > xResMetaDataSup( 
xPreparedStatement, UNO_QUERY_THROW );
+            Reference< XResultSetMetaData > xResultSetMeta( 
xResMetaDataSup->getMetaData() );
+            if ( !xResultSetMeta.is() )
+            {
+                ::rtl::OUString sError( DBA_RES( 
RID_STR_STATEMENT_WITHOUT_RESULT_SET ) );
+                ::dbtools::throwSQLException( sError, SQL_GENERAL_ERROR, *this 
);
+            }
+
+            Reference< XDatabaseMetaData > xDBMeta( 
m_xConnection->getMetaData(), UNO_QUERY_THROW );
+            ::vos::ORef< OSQLColumns > aParseColumns(
+                
::connectivity::parse::OParseColumn::createColumnsForResultSet( xResultSetMeta, 
xDBMeta ) );
+            xColumns = OPrivateColumns::createWithIntrinsicNames(
+                aParseColumns, xDBMeta->storesMixedCaseQuotedIdentifiers(), 
*this, m_aMutex );
+            if ( !xColumns.is() )
+                throw RuntimeException();
                }
-               if(xComposer.is())
-               {
-                       xComposer->setQuery(m_sCommand);
 
-                       //      
xComposer->setFilter(::rtl::OUString::createFromAscii("0=1")); // i21125 
-                       //      aFilterStatement = 
m_xComposer->getComposedQuery();
-                       Reference<XColumnsSupplier> xCols(xComposer,UNO_QUERY);
-                       Reference< XNameAccess > xColumns = xCols->getColumns();
-                       if(xColumns.is())
-                       {
                                Sequence< ::rtl::OUString> aNames = 
xColumns->getElementNames();
                                const ::rtl::OUString* pBegin = 
aNames.getConstArray();
                                const ::rtl::OUString* pEnd   = pBegin + 
aNames.getLength();
@@ -225,8 +258,6 @@
                                                
m_pMediator->notifyElementCreated(*pBegin,xDest);
                                }
                        }
-               }
-       }
        catch( const SQLContext& e )
        {
                if ( m_pWarnings )
@@ -244,14 +275,8 @@
        }
        catch( const Exception& )
        {
-               DBG_ERROR( "OQuery::implCollectColumns: caught a strange 
exception!" );
+               DBG_UNHANDLED_EXCEPTION();
        }
-}
-
-//--------------------------------------------------------------------------
-void OQuery::rebuildColumns()
-{
-       implCollectColumns( );
 }
 
 // XServiceInfo




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

Reply via email to