LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/drivers/mork - MStatement.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 197 45.7 %
Date: 2012-12-27 Functions: 14 39 35.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <stdio.h>
      22             : #include <osl/diagnose.h>
      23             : #include <comphelper/property.hxx>
      24             : #include <comphelper/uno3.hxx>
      25             : #include <osl/thread.h>
      26             : #include <tools/diagnose_ex.h>
      27             : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
      28             : #include <com/sun/star/sdbc/ResultSetType.hpp>
      29             : #include <com/sun/star/sdbc/FetchDirection.hpp>
      30             : #include <com/sun/star/lang/DisposedException.hpp>
      31             : #include <comphelper/sequence.hxx>
      32             : #include <cppuhelper/typeprovider.hxx>
      33             : #include <comphelper/processfactory.hxx>
      34             : #include <comphelper/extract.hxx>
      35             : #include <comphelper/types.hxx>
      36             : #include <connectivity/dbexception.hxx>
      37             : #include <com/sun/star/container/XIndexAccess.hpp>
      38             : 
      39             : #include <algorithm>
      40             : 
      41             : #include "diagnose_ex.h"
      42             : #include "MDriver.hxx"
      43             : #include "MStatement.hxx"
      44             : #include "MConnection.hxx"
      45             : #include "MResultSet.hxx"
      46             : #include "MDatabaseMetaData.hxx"
      47             : 
      48             : #include "resource/mork_res.hrc"
      49             : #include "resource/common_res.hrc"
      50             : 
      51             : #if OSL_DEBUG_LEVEL > 0
      52             : # define OUtoCStr( x ) ( ::rtl::OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr())
      53             : #else /* OSL_DEBUG_LEVEL */
      54             : # define OUtoCStr( x ) ("dummy")
      55             : #endif /* OSL_DEBUG_LEVEL */
      56             : 
      57           1 : static ::osl::Mutex m_ThreadMutex;
      58             : 
      59             : using namespace ::comphelper;
      60             : using namespace connectivity::mork;
      61             : using namespace connectivity;
      62             : //------------------------------------------------------------------------------
      63             : using namespace com::sun::star::uno;
      64             : using namespace com::sun::star::lang;
      65             : using namespace com::sun::star::beans;
      66             : using namespace com::sun::star::sdbc;
      67             : using namespace com::sun::star::container;
      68             : using namespace com::sun::star::io;
      69             : using namespace com::sun::star::util;
      70             : //------------------------------------------------------------------------------
      71             : 
      72           0 : OStatement::OStatement( OConnection* _pConnection) : OCommonStatement( _pConnection)
      73             : {
      74             :     SAL_INFO("connectivity.mork", "=>  OStatement::OStatement()" );
      75           0 : }
      76             : 
      77           2 : OCommonStatement::OCommonStatement(OConnection* _pConnection )
      78             :     :OCommonStatement_IBASE(m_aMutex)
      79             :     ,OPropertySetHelper(OCommonStatement_IBASE::rBHelper)
      80             :     ,OCommonStatement_SBASE((::cppu::OWeakObject*)_pConnection, this)
      81             :     ,m_pTable(NULL)
      82             :     ,m_pConnection(_pConnection)
      83             :     ,m_aParser( comphelper::getComponentContext(_pConnection->getDriver()->getFactory()) )
      84           8 :     ,m_pSQLIterator( new OSQLParseTreeIterator( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser, NULL ) )
      85          10 :     ,rBHelper(OCommonStatement_IBASE::rBHelper)
      86             : {
      87             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::OCommonStatement()" );
      88           2 :     m_xDBMetaData = _pConnection->getMetaData();
      89           2 :     m_pParseTree = NULL;
      90           2 :     m_pConnection->acquire();
      91           2 : }
      92             : 
      93             : // -----------------------------------------------------------------------------
      94           0 : OCommonStatement::~OCommonStatement()
      95             : {
      96           0 : }
      97             : 
      98             : //------------------------------------------------------------------------------
      99           0 : void OCommonStatement::disposing()
     100             : {
     101           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     102             : 
     103           0 :     clearWarnings();
     104           0 :     clearCachedResultSet();
     105             : 
     106           0 :     if (m_pConnection)
     107           0 :         m_pConnection->release();
     108           0 :     m_pConnection = NULL;
     109             : 
     110           0 :     m_pSQLIterator->dispose();
     111             : 
     112           0 :     dispose_ChildImpl();
     113           0 :     OCommonStatement_IBASE::disposing();
     114           0 : }
     115             : //-----------------------------------------------------------------------------
     116           4 : Any SAL_CALL OCommonStatement::queryInterface( const Type & rType ) throw(RuntimeException)
     117             : {
     118           4 :     Any aRet = OCommonStatement_IBASE::queryInterface(rType);
     119           4 :     if(!aRet.hasValue())
     120           0 :         aRet = OPropertySetHelper::queryInterface(rType);
     121           4 :     return aRet;
     122             : }
     123             : // -------------------------------------------------------------------------
     124           0 : Sequence< Type > SAL_CALL OCommonStatement::getTypes(  ) throw(RuntimeException)
     125             : {
     126           0 :     ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
     127           0 :                                     ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
     128           0 :                                     ::getCppuType( (const Reference< XPropertySet > *)0 ));
     129             : 
     130           0 :     return ::comphelper::concatSequences(aTypes.getTypes(),OCommonStatement_IBASE::getTypes());
     131             : }
     132             : // -------------------------------------------------------------------------
     133           0 : void SAL_CALL OCommonStatement::close(  ) throw(SQLException, RuntimeException)
     134             : {
     135             :     {
     136           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     137           0 :         checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     138             :     }
     139           0 :     dispose();
     140           0 : }
     141             : 
     142             : 
     143             : // -------------------------------------------------------------------------
     144           0 : void OCommonStatement::createTable( ) throw ( SQLException, RuntimeException )
     145             : {
     146             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::createTable()" );
     147             : 
     148             : /*
     149             :     if(m_pParseTree)
     150             :     {
     151             :         ::rtl::Reference<connectivity::OSQLColumns> xCreateColumn;
     152             :         if (m_pSQLIterator->getStatementType() == SQL_STATEMENT_CREATE_TABLE)
     153             :         {
     154             :             const OSQLTables& xTabs = m_pSQLIterator->getTables();
     155             :             OSL_ENSURE( !xTabs.empty(), "Need a Table");
     156             :             ::rtl::OUString ouTableName=xTabs.begin()->first;
     157             :             xCreateColumn     = m_pSQLIterator->getCreateColumns();
     158             :             OSL_ENSURE(xCreateColumn.is(), "Need the Columns!!");
     159             : 
     160             :             const OColumnAlias& aColumnAlias = m_pConnection->getColumnAlias();
     161             : 
     162             :             OSQLColumns::Vector::const_iterator aIter = xCreateColumn->get().begin();
     163             :             const ::rtl::OUString sProprtyName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
     164             :             ::rtl::OUString sName;
     165             :             for (sal_Int32 i = 1; aIter != xCreateColumn->get().end();++aIter, i++)
     166             :             {
     167             :                 (*aIter)->getPropertyValue(sProprtyName) >>= sName;
     168             :                 if ( !aColumnAlias.hasAlias( sName ) )
     169             :                 {
     170             : 
     171             :                     const ::rtl::OUString sError( getOwnConnection()->getResources().getResourceStringWithSubstitution(
     172             :                             STR_INVALID_COLUMNNAME,
     173             :                             "$columnname$", sName
     174             :                          ) );
     175             :                     ::dbtools::throwGenericSQLException(sError,*this);
     176             :                 }
     177             :             }
     178             :             MDatabaseMetaDataHelper     _aDbHelper;
     179             :             if (!_aDbHelper.NewAddressBook(m_pConnection,ouTableName))
     180             :             {
     181             :                 getOwnConnection()->throwSQLException( _aDbHelper.getError(), *this );
     182             :             }
     183             :             m_pSQLIterator.reset( new ::connectivity::OSQLParseTreeIterator(
     184             :                 m_pConnection, m_pConnection->createCatalog()->getTables(), m_aParser, NULL ) );
     185             :         }
     186             : 
     187             :     }
     188             :     else
     189             :         getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
     190             : */
     191           0 : }
     192             : // -------------------------------------------------------------------------
     193           2 : OCommonStatement::StatementType OCommonStatement::parseSql( const ::rtl::OUString& sql , sal_Bool bAdjusted)
     194             :     throw ( SQLException, RuntimeException )
     195             : {
     196             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::parseSql()" );
     197             : 
     198           2 :     ::rtl::OUString aErr;
     199             : 
     200           2 :     m_pParseTree = m_aParser.parseTree(aErr,sql);
     201             : 
     202             : #if OSL_DEBUG_LEVEL > 0
     203             :     {
     204             :         const char* str = OUtoCStr(sql);
     205             :         OSL_UNUSED( str );
     206             :         OSL_TRACE("ParseSQL: %s", OUtoCStr( sql ) );
     207             :     }
     208             : #endif // OSL_DEBUG_LEVEL
     209             : 
     210           2 :     if(m_pParseTree)
     211             :     {
     212           2 :         m_pSQLIterator->setParseTree(m_pParseTree);
     213           2 :         m_pSQLIterator->traverseAll();
     214           2 :         const OSQLTables& xTabs = m_pSQLIterator->getTables();
     215             : 
     216           2 :         if (xTabs.empty())
     217             :         {
     218           0 :             getOwnConnection()->throwSQLException( STR_QUERY_AT_LEAST_ONE_TABLES, *this );
     219             :         }
     220             : 
     221             : #if OSL_DEBUG_LEVEL > 0
     222             :         OSQLTables::const_iterator citer;
     223             :         for( citer = xTabs.begin(); citer != xTabs.end(); ++citer ) {
     224             :             OSL_TRACE("SELECT Table : %s", OUtoCStr(citer->first) );
     225             :         }
     226             : #endif
     227             : 
     228           2 :         Reference<XIndexAccess> xNames;
     229           2 :         switch(m_pSQLIterator->getStatementType())
     230             :         {
     231             :         case SQL_STATEMENT_SELECT:
     232             : 
     233             :             // at this moment we support only one table per select statement
     234             : 
     235             :             OSL_ENSURE( xTabs.begin() != xTabs.end(), "Need a Table");
     236             : 
     237           2 :             m_pTable = static_cast< OTable* > (xTabs.begin()->second.get());
     238           2 :             m_xColNames     = m_pTable->getColumns();
     239           2 :             xNames = Reference<XIndexAccess>(m_xColNames,UNO_QUERY);
     240             :             // set the binding of the resultrow
     241           2 :             m_aRow          = new OValueVector(xNames->getCount());
     242           2 :             (m_aRow->get())[0].setBound(sal_True);
     243           2 :             ::std::for_each(m_aRow->get().begin()+1,m_aRow->get().end(),TSetBound(sal_False));
     244             :             // create the column mapping
     245           2 :             createColumnMapping();
     246             : 
     247           2 :             analyseSQL();
     248           2 :             return eSelect;
     249             : 
     250             :         case SQL_STATEMENT_CREATE_TABLE:
     251           0 :             createTable();
     252           0 :             return eCreateTable;
     253             : 
     254             :         default:
     255           0 :             break;
     256           2 :         }
     257             :     }
     258           0 :     else if(!bAdjusted) //Our sql parser does not support a statement like "create table foo"
     259             :                         // So we append ("E-mail" varchar) to the last of it to make it work
     260             :     {
     261           0 :         return parseSql(sql + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("(""E-mail"" caracter)")),sal_True);
     262             :     }
     263             : 
     264           0 :     getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
     265             :     OSL_FAIL( "OCommonStatement::parseSql: unreachable!" );
     266           0 :     return eSelect;
     267             : 
     268             : }
     269             : // -------------------------------------------------------------------------
     270           2 : Reference< XResultSet > OCommonStatement::impl_executeCurrentQuery()
     271             : {
     272             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::impl_executeCurrentQuery()" );
     273             : 
     274           2 :     clearCachedResultSet();
     275             : 
     276           2 :     ::rtl::Reference< OResultSet > pResult( new OResultSet( this, m_pSQLIterator ) );
     277           2 :     initializeResultSet( pResult.get() );
     278             : 
     279           2 :     pResult->executeQuery();
     280           2 :     cacheResultSet( pResult );  // only cache if we survived the execution
     281             : 
     282           2 :     return pResult.get();
     283             : 
     284             : }
     285             : 
     286             : // -------------------------------------------------------------------------
     287           2 : void OCommonStatement::initializeResultSet( OResultSet* _pResult )
     288             : {
     289             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::initializeResultSet()" );
     290             : 
     291           2 :     ENSURE_OR_THROW( _pResult, "invalid result set" );
     292             : 
     293           2 :     _pResult->setColumnMapping(m_aColMapping);
     294           2 :     _pResult->setOrderByColumns(m_aOrderbyColumnNumber);
     295           2 :     _pResult->setOrderByAscending(m_aOrderbyAscending);
     296           2 :     _pResult->setBindingRow(m_aRow);
     297           2 :     _pResult->setTable(m_pTable);
     298           2 : }
     299             : 
     300             : // -------------------------------------------------------------------------
     301           2 : void OCommonStatement::clearCachedResultSet()
     302             : {
     303             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::clearCachedResultSet()" );
     304             : 
     305           2 :     Reference< XResultSet > xResultSet( m_xResultSet.get(), UNO_QUERY );
     306           2 :     if ( !xResultSet.is() )
     307           2 :         return;
     308             : 
     309           0 :     Reference< XCloseable >( xResultSet, UNO_QUERY_THROW )->close();
     310             : 
     311           0 :     m_xResultSet = Reference< XResultSet >();
     312             : }
     313             : 
     314             : // -------------------------------------------------------------------------
     315           2 : void OCommonStatement::cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult )
     316             : {
     317           2 :     ENSURE_OR_THROW( _pResult.is(), "invalid result set" );
     318           2 :     m_xResultSet = Reference< XResultSet >( _pResult.get() );
     319           2 : }
     320             : 
     321             : // -------------------------------------------------------------------------
     322           0 : sal_Bool SAL_CALL OCommonStatement::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
     323             : {
     324             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::execute()" );
     325             : 
     326           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     327           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     328             : 
     329             :     OSL_TRACE("Statement::execute( %s )", OUtoCStr( sql ) );
     330             : 
     331           0 :     Reference< XResultSet > xRS = executeQuery( sql );
     332             :     // returns true when a resultset is available
     333           0 :     return xRS.is();
     334             : }
     335             : // -------------------------------------------------------------------------
     336             : 
     337           0 : Reference< XResultSet > SAL_CALL OCommonStatement::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
     338             : {
     339             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::executeQuery()" );
     340             : 
     341           0 :     ::osl::MutexGuard aGuard( m_ThreadMutex );
     342           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     343             : 
     344             :     OSL_TRACE("Statement::executeQuery( %s )", OUtoCStr( sql ) );
     345             : 
     346             :     // parse the statement
     347           0 :     StatementType eStatementType = parseSql( sql );
     348           0 :     if ( eStatementType != eSelect )
     349           0 :         return NULL;
     350             : 
     351           0 :     return impl_executeCurrentQuery();
     352             : }
     353             : // -------------------------------------------------------------------------
     354             : 
     355           0 : Reference< XConnection > SAL_CALL OCommonStatement::getConnection(  ) throw(SQLException, RuntimeException)
     356             : {
     357             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::getConnection()" );
     358             : 
     359           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     360           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     361             : 
     362             :     // just return our connection here
     363           0 :     return (Reference< XConnection >)m_pConnection;
     364             : }
     365             : // -----------------------------------------------------------------------------
     366           0 : Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException)
     367             : {
     368             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::queryInterface()" );
     369             : 
     370           0 :     Any aRet = ::cppu::queryInterface(rType,static_cast< XServiceInfo*> (this));
     371           0 :     if(!aRet.hasValue())
     372           0 :         aRet = OCommonStatement::queryInterface(rType);
     373           0 :     return aRet;
     374             : }
     375             : // -------------------------------------------------------------------------
     376           0 : sal_Int32 SAL_CALL OCommonStatement::executeUpdate( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException)
     377             : {
     378           0 :     ::dbtools::throwFeatureNotImplementedException( "XStatement::executeUpdate", *this );
     379           0 :     return 0;
     380             : 
     381             : }
     382             : // -------------------------------------------------------------------------
     383           0 : Any SAL_CALL OCommonStatement::getWarnings(  ) throw(SQLException, RuntimeException)
     384             : {
     385           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     386           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     387             : 
     388           0 :     return makeAny(m_aLastWarning);
     389             : }
     390             : // -------------------------------------------------------------------------
     391             : 
     392             : // -------------------------------------------------------------------------
     393           0 : void SAL_CALL OCommonStatement::clearWarnings(  ) throw(SQLException, RuntimeException)
     394             : {
     395           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     396           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     397             : 
     398             : 
     399           0 :     m_aLastWarning = SQLWarning();
     400           0 : }
     401             : // -------------------------------------------------------------------------
     402           0 : ::cppu::IPropertyArrayHelper* OCommonStatement::createArrayHelper( ) const
     403             : {
     404             :     // this properties are define by the service resultset
     405             :     // they must in alphabetic order
     406           0 :     Sequence< Property > aProps(9);
     407           0 :     Property* pProperties = aProps.getArray();
     408           0 :     sal_Int32 nPos = 0;
     409           0 :     DECL_PROP0(CURSORNAME,  ::rtl::OUString);
     410           0 :     DECL_BOOL_PROP0(ESCAPEPROCESSING);
     411           0 :     DECL_PROP0(FETCHDIRECTION,sal_Int32);
     412           0 :     DECL_PROP0(FETCHSIZE,   sal_Int32);
     413           0 :     DECL_PROP0(MAXFIELDSIZE,sal_Int32);
     414           0 :     DECL_PROP0(MAXROWS,     sal_Int32);
     415           0 :     DECL_PROP0(QUERYTIMEOUT,sal_Int32);
     416           0 :     DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
     417           0 :     DECL_PROP0(RESULTSETTYPE,sal_Int32);
     418             : 
     419           0 :     return new ::cppu::OPropertyArrayHelper(aProps);
     420             : }
     421             : 
     422             : // -------------------------------------------------------------------------
     423           0 : ::cppu::IPropertyArrayHelper & OCommonStatement::getInfoHelper()
     424             : {
     425           0 :     return *const_cast<OCommonStatement*>(this)->getArrayHelper();
     426             : }
     427             : // -------------------------------------------------------------------------
     428           0 : sal_Bool OCommonStatement::convertFastPropertyValue(
     429             :                             Any & /*rConvertedValue*/,
     430             :                             Any & /*rOldValue*/,
     431             :                             sal_Int32 /*nHandle*/,
     432             :                             const Any& /*rValue*/ )
     433             :                                 throw (::com::sun::star::lang::IllegalArgumentException)
     434             : {
     435           0 :     sal_Bool bConverted = sal_False;
     436             :     // here we have to try to convert
     437           0 :     return bConverted;
     438             : }
     439             : // -------------------------------------------------------------------------
     440           0 : void OCommonStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& /*rValue*/) throw (Exception)
     441             : {
     442             :     // set the value to whatever is necessary
     443             :     switch(nHandle)
     444             :     {
     445             :         case PROPERTY_ID_QUERYTIMEOUT:
     446             :         case PROPERTY_ID_MAXFIELDSIZE:
     447             :         case PROPERTY_ID_MAXROWS:
     448             :         case PROPERTY_ID_RESULTSETCONCURRENCY:
     449             :         case PROPERTY_ID_RESULTSETTYPE:
     450             :         case PROPERTY_ID_FETCHDIRECTION:
     451             :         case PROPERTY_ID_FETCHSIZE:
     452             :         case PROPERTY_ID_ESCAPEPROCESSING:
     453             :         default:
     454             :             ;
     455             :     }
     456           0 : }
     457             : // -------------------------------------------------------------------------
     458           0 : void OCommonStatement::getFastPropertyValue(Any& /*rValue*/,sal_Int32 nHandle) const
     459             : {
     460             :     switch(nHandle)
     461             :     {
     462             :         case PROPERTY_ID_QUERYTIMEOUT:
     463             :         case PROPERTY_ID_MAXFIELDSIZE:
     464             :         case PROPERTY_ID_MAXROWS:
     465             :         case PROPERTY_ID_RESULTSETCONCURRENCY:
     466             :         case PROPERTY_ID_RESULTSETTYPE:
     467             :         case PROPERTY_ID_FETCHDIRECTION:
     468             :         case PROPERTY_ID_FETCHSIZE:
     469             :         case PROPERTY_ID_ESCAPEPROCESSING:
     470             :         default:
     471             :             ;
     472             :     }
     473           0 : }
     474             : // -------------------------------------------------------------------------
     475           0 : IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
     476             : // -----------------------------------------------------------------------------
     477          12 : void SAL_CALL OCommonStatement::acquire() throw()
     478             : {
     479          12 :     OCommonStatement_IBASE::acquire();
     480          12 : }
     481             : // -----------------------------------------------------------------------------
     482          10 : void SAL_CALL OCommonStatement::release() throw()
     483             : {
     484          10 :     relase_ChildImpl();
     485          10 : }
     486             : // -----------------------------------------------------------------------------
     487           0 : void SAL_CALL OStatement::acquire() throw()
     488             : {
     489           0 :     OCommonStatement::acquire();
     490           0 : }
     491             : // -----------------------------------------------------------------------------
     492           0 : void SAL_CALL OStatement::release() throw()
     493             : {
     494           0 :     OCommonStatement::release();
     495           0 : }
     496             : // -----------------------------------------------------------------------------
     497           0 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OCommonStatement::getPropertySetInfo(  ) throw(RuntimeException)
     498             : {
     499           0 :     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
     500             : }
     501             : // -----------------------------------------------------------------------------
     502           2 : void OCommonStatement::createColumnMapping()
     503             : {
     504             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::createColumnMapping()" );
     505             : 
     506             :     size_t i;
     507             : 
     508             :     // initialize the column index map (mapping select columns to table columns)
     509           2 :     ::rtl::Reference<connectivity::OSQLColumns> xColumns = m_pSQLIterator->getSelectColumns();
     510           2 :     m_aColMapping.resize(xColumns->get().size() + 1);
     511           6 :     for (i=0; i<m_aColMapping.size(); ++i)
     512           4 :         m_aColMapping[i] = static_cast<sal_Int32>(i);
     513             : 
     514           2 :     Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
     515             :     // now check which columns are bound
     516             : #if OSL_DEBUG_LEVEL > 0
     517             :     for ( i = 0; i < m_aColMapping.size(); i++ )
     518             :         OSL_TRACE("BEFORE Mapped: %d -> %d", i, m_aColMapping[i] );
     519             : #endif
     520           2 :     OResultSet::setBoundedColumns(m_aRow,xColumns,xNames,sal_True,m_xDBMetaData,m_aColMapping);
     521             : #if OSL_DEBUG_LEVEL > 0
     522             :     for ( i = 0; i < m_aColMapping.size(); i++ )
     523             :         OSL_TRACE("AFTER  Mapped: %d -> %d", i, m_aColMapping[i] );
     524             : #endif
     525           2 : }
     526             : // -----------------------------------------------------------------------------
     527             : 
     528           2 : void OCommonStatement::analyseSQL()
     529             : {
     530           2 :     const OSQLParseNode* pOrderbyClause = m_pSQLIterator->getOrderTree();
     531           2 :     if(pOrderbyClause)
     532             :     {
     533           1 :         OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2);
     534             :         OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Fehler im Parse Tree");
     535             : 
     536           2 :         for (sal_uInt32 m = 0; m < pOrderingSpecCommalist->count(); m++)
     537             :         {
     538           1 :             OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m);
     539             :             OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Fehler im Parse Tree");
     540             :             OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Fehler im Parse Tree");
     541             : 
     542           1 :             OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0);
     543           1 :             if(!SQL_ISRULE(pColumnRef,column_ref))
     544             :             {
     545           0 :                 throw SQLException();
     546             :             }
     547           1 :             OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1);
     548           1 :             setOrderbyColumn(pColumnRef,pAscendingDescending);
     549             :         }
     550             :     }
     551           2 : }
     552             : //------------------------------------------------------------------
     553           1 : void OCommonStatement::setOrderbyColumn(    OSQLParseNode* pColumnRef,
     554             :                                         OSQLParseNode* pAscendingDescending)
     555             : {
     556             :     SAL_INFO("connectivity.mork", "=>  OCommonStatement::setOrderbyColumn()" );
     557             : 
     558           1 :     ::rtl::OUString aColumnName;
     559           1 :     if (pColumnRef->count() == 1)
     560           1 :         aColumnName = pColumnRef->getChild(0)->getTokenValue();
     561           0 :     else if (pColumnRef->count() == 3)
     562             :     {
     563           0 :         pColumnRef->getChild(2)->parseNodeToStr( aColumnName, getOwnConnection(), NULL, sal_False, sal_False );
     564             :     }
     565             :     else
     566             :     {
     567           0 :         throw SQLException();
     568             :     }
     569             : 
     570           1 :     Reference<XColumnLocate> xColLocate(m_xColNames,UNO_QUERY);
     571           1 :     if(!xColLocate.is())
     572           1 :         return;
     573             : 
     574           1 :     m_aOrderbyColumnNumber.push_back(xColLocate->findColumn(aColumnName));
     575             : 
     576             :     // Ascending or Descending?
     577           1 :     m_aOrderbyAscending.push_back((SQL_ISTOKEN(pAscendingDescending,DESC)) ? SQL_DESC : SQL_ASC);
     578           3 : }
     579             : // -----------------------------------------------------------------------------
     580             : 
     581             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10