LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mork - MStatement.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 115 207 55.6 %
Date: 2014-11-03 Functions: 18 39 46.2 %
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 ) ( OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr())
      53             : #else /* OSL_DEBUG_LEVEL */
      54             : # define OUtoCStr( x ) ("dummy")
      55             : #endif /* OSL_DEBUG_LEVEL */
      56             : 
      57           2 : 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           0 : }
      75             : 
      76           4 : OCommonStatement::OCommonStatement(OConnection* _pConnection )
      77             :     :OCommonStatement_IBASE(m_aMutex)
      78             :     ,OPropertySetHelper(OCommonStatement_IBASE::rBHelper)
      79             :     ,OCommonStatement_SBASE((::cppu::OWeakObject*)_pConnection, this)
      80             :     ,m_pTable(NULL)
      81             :     ,m_pConnection(_pConnection)
      82             :     ,m_aParser( comphelper::getComponentContext(_pConnection->getDriver()->getFactory()) )
      83          16 :     ,m_pSQLIterator( new OSQLParseTreeIterator( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser, NULL ) )
      84          20 :     ,rBHelper(OCommonStatement_IBASE::rBHelper)
      85             : {
      86           4 :     m_xDBMetaData = _pConnection->getMetaData();
      87           4 :     m_pParseTree = NULL;
      88           4 :     m_pConnection->acquire();
      89           4 : }
      90             : 
      91             : 
      92           4 : OCommonStatement::~OCommonStatement()
      93             : {
      94           4 : }
      95             : 
      96             : 
      97           4 : void OCommonStatement::disposing()
      98             : {
      99           4 :     ::osl::MutexGuard aGuard(m_aMutex);
     100             : 
     101           4 :     clearWarnings();
     102           4 :     clearCachedResultSet();
     103             : 
     104           4 :     if (m_pConnection)
     105           4 :         m_pConnection->release();
     106           4 :     m_pConnection = NULL;
     107             : 
     108           4 :     m_pSQLIterator->dispose();
     109           4 :     delete m_pParseTree;
     110             : 
     111           4 :     dispose_ChildImpl();
     112           4 :     OCommonStatement_IBASE::disposing();
     113           4 : }
     114             : 
     115          12 : Any SAL_CALL OCommonStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     116             : {
     117          12 :     Any aRet = OCommonStatement_IBASE::queryInterface(rType);
     118          12 :     if(!aRet.hasValue())
     119           0 :         aRet = OPropertySetHelper::queryInterface(rType);
     120          12 :     return aRet;
     121             : }
     122             : 
     123           0 : Sequence< Type > SAL_CALL OCommonStatement::getTypes(  ) throw(RuntimeException, std::exception)
     124             : {
     125           0 :     ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(),
     126           0 :                                     cppu::UnoType<XFastPropertySet>::get(),
     127           0 :                                     cppu::UnoType<XPropertySet>::get());
     128             : 
     129           0 :     return ::comphelper::concatSequences(aTypes.getTypes(),OCommonStatement_IBASE::getTypes());
     130             : }
     131             : 
     132           4 : void SAL_CALL OCommonStatement::close(  ) throw(SQLException, RuntimeException, std::exception)
     133             : {
     134             :     {
     135           4 :         ::osl::MutexGuard aGuard( m_aMutex );
     136           4 :         checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     137             :     }
     138           4 :     dispose();
     139           4 : }
     140             : 
     141             : 
     142             : 
     143           0 : void OCommonStatement::createTable( ) throw ( SQLException, RuntimeException )
     144             : {
     145             : /*
     146             :     if(m_pParseTree)
     147             :     {
     148             :         ::rtl::Reference<connectivity::OSQLColumns> xCreateColumn;
     149             :         if (m_pSQLIterator->getStatementType() == SQL_STATEMENT_CREATE_TABLE)
     150             :         {
     151             :             const OSQLTables& xTabs = m_pSQLIterator->getTables();
     152             :             OSL_ENSURE( !xTabs.empty(), "Need a Table");
     153             :             OUString ouTableName=xTabs.begin()->first;
     154             :             xCreateColumn     = m_pSQLIterator->getCreateColumns();
     155             :             OSL_ENSURE(xCreateColumn.is(), "Need the Columns!!");
     156             : 
     157             :             const OColumnAlias& aColumnAlias = m_pConnection->getColumnAlias();
     158             : 
     159             :             OSQLColumns::Vector::const_iterator aIter = xCreateColumn->get().begin();
     160             :             const OUString sProprtyName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
     161             :             OUString sName;
     162             :             for (sal_Int32 i = 1; aIter != xCreateColumn->get().end();++aIter, i++)
     163             :             {
     164             :                 (*aIter)->getPropertyValue(sProprtyName) >>= sName;
     165             :                 if ( !aColumnAlias.hasAlias( sName ) )
     166             :                 {
     167             : 
     168             :                     const OUString sError( getOwnConnection()->getResources().getResourceStringWithSubstitution(
     169             :                             STR_INVALID_COLUMNNAME,
     170             :                             "$columnname$", sName
     171             :                          ) );
     172             :                     ::dbtools::throwGenericSQLException(sError,*this);
     173             :                 }
     174             :             }
     175             :             MDatabaseMetaDataHelper     _aDbHelper;
     176             :             if (!_aDbHelper.NewAddressBook(m_pConnection,ouTableName))
     177             :             {
     178             :                 getOwnConnection()->throwSQLException( _aDbHelper.getError(), *this );
     179             :             }
     180             :             m_pSQLIterator.reset( new ::connectivity::OSQLParseTreeIterator(
     181             :                 m_pConnection, m_pConnection->createCatalog()->getTables(), m_aParser, NULL ) );
     182             :         }
     183             : 
     184             :     }
     185             :     else
     186             :         getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
     187             : */
     188           0 : }
     189             : 
     190           4 : OCommonStatement::StatementType OCommonStatement::parseSql( const OUString& sql , bool bAdjusted)
     191             :     throw ( SQLException, RuntimeException )
     192             : {
     193           4 :     OUString aErr;
     194             : 
     195           4 :     m_pParseTree = m_aParser.parseTree(aErr,sql);
     196             : 
     197             : #if OSL_DEBUG_LEVEL > 0
     198             :     {
     199             :         OSL_TRACE("ParseSQL: %s", OUtoCStr( sql ) );
     200             :     }
     201             : #endif // OSL_DEBUG_LEVEL
     202             : 
     203           4 :     if(m_pParseTree)
     204             :     {
     205           4 :         m_pSQLIterator->setParseTree(m_pParseTree);
     206           4 :         m_pSQLIterator->traverseAll();
     207           4 :         const OSQLTables& xTabs = m_pSQLIterator->getTables();
     208             : 
     209           4 :         if (xTabs.empty())
     210             :         {
     211           0 :             getOwnConnection()->throwSQLException( STR_QUERY_AT_LEAST_ONE_TABLES, *this );
     212             :         }
     213             : 
     214             : #if OSL_DEBUG_LEVEL > 0
     215             :         OSQLTables::const_iterator citer;
     216             :         for( citer = xTabs.begin(); citer != xTabs.end(); ++citer ) {
     217             :             OSL_TRACE("SELECT Table : %s", OUtoCStr(citer->first) );
     218             :         }
     219             : #endif
     220             : 
     221           4 :         Reference<XIndexAccess> xNames;
     222           4 :         switch(m_pSQLIterator->getStatementType())
     223             :         {
     224             :         case SQL_STATEMENT_SELECT:
     225             : 
     226             :             // at this moment we support only one table per select statement
     227             : 
     228             :             OSL_ENSURE( xTabs.begin() != xTabs.end(), "Need a Table");
     229             : 
     230           4 :             m_pTable = static_cast< OTable* > (xTabs.begin()->second.get());
     231           4 :             m_xColNames     = m_pTable->getColumns();
     232           4 :             xNames = Reference<XIndexAccess>(m_xColNames,UNO_QUERY);
     233             :             // set the binding of the resultrow
     234           4 :             m_aRow          = new OValueVector(xNames->getCount());
     235           4 :             (m_aRow->get())[0].setBound(true);
     236           4 :             ::std::for_each(m_aRow->get().begin()+1,m_aRow->get().end(),TSetBound(false));
     237             :             // create the column mapping
     238           4 :             createColumnMapping();
     239             : 
     240           4 :             analyseSQL();
     241           4 :             return eSelect;
     242             : 
     243             :         case SQL_STATEMENT_CREATE_TABLE:
     244           0 :             createTable();
     245           0 :             return eCreateTable;
     246             : 
     247             :         default:
     248           0 :             break;
     249           0 :         }
     250             :     }
     251           0 :     else if(!bAdjusted) //Our sql parser does not support a statement like "create table foo"
     252             :                         // So we append ("E-mail" varchar) to the last of it to make it work
     253             :     {
     254           0 :         return parseSql(sql + "(""E-mail"" character)", true);
     255             :     }
     256             : 
     257           0 :     getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
     258             :     OSL_FAIL( "OCommonStatement::parseSql: unreachable!" );
     259           0 :     return eSelect;
     260             : 
     261             : }
     262             : 
     263           4 : Reference< XResultSet > OCommonStatement::impl_executeCurrentQuery()
     264             : {
     265           4 :     clearCachedResultSet();
     266             : 
     267           4 :     ::rtl::Reference< OResultSet > pResult( new OResultSet( this, m_pSQLIterator ) );
     268           4 :     initializeResultSet( pResult.get() );
     269             : 
     270           4 :     pResult->executeQuery();
     271           4 :     cacheResultSet( pResult );  // only cache if we survived the execution
     272             : 
     273           4 :     return pResult.get();
     274             : 
     275             : }
     276             : 
     277             : 
     278           4 : void OCommonStatement::initializeResultSet( OResultSet* _pResult )
     279             : {
     280           4 :     ENSURE_OR_THROW( _pResult, "invalid result set" );
     281             : 
     282           4 :     _pResult->setColumnMapping(m_aColMapping);
     283           4 :     _pResult->setOrderByColumns(m_aOrderbyColumnNumber);
     284           4 :     _pResult->setOrderByAscending(m_aOrderbyAscending);
     285           4 :     _pResult->setBindingRow(m_aRow);
     286           4 :     _pResult->setTable(m_pTable);
     287           4 : }
     288             : 
     289             : 
     290           8 : void OCommonStatement::clearCachedResultSet()
     291             : {
     292           8 :     Reference< XResultSet > xResultSet( m_xResultSet.get(), UNO_QUERY );
     293           8 :     if ( !xResultSet.is() )
     294          12 :         return;
     295             : 
     296           4 :     Reference< XCloseable >( xResultSet, UNO_QUERY_THROW )->close();
     297             : 
     298           4 :     m_xResultSet.clear();
     299             : }
     300             : 
     301             : 
     302           4 : void OCommonStatement::cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult )
     303             : {
     304           4 :     ENSURE_OR_THROW( _pResult.is(), "invalid result set" );
     305           4 :     m_xResultSet = Reference< XResultSet >( _pResult.get() );
     306           4 : }
     307             : 
     308             : 
     309           0 : sal_Bool SAL_CALL OCommonStatement::execute( const OUString& sql ) throw(SQLException, RuntimeException, std::exception)
     310             : {
     311           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     312           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     313             : 
     314             :     OSL_TRACE("Statement::execute( %s )", OUtoCStr( sql ) );
     315             : 
     316           0 :     Reference< XResultSet > xRS = executeQuery( sql );
     317             :     // returns true when a resultset is available
     318           0 :     return xRS.is();
     319             : }
     320             : 
     321             : 
     322           0 : Reference< XResultSet > SAL_CALL OCommonStatement::executeQuery( const OUString& sql ) throw(SQLException, RuntimeException, std::exception)
     323             : {
     324           0 :     ::osl::MutexGuard aGuard( m_ThreadMutex );
     325           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     326             : 
     327             :     OSL_TRACE("Statement::executeQuery( %s )", OUtoCStr( sql ) );
     328             : 
     329             :     // parse the statement
     330           0 :     StatementType eStatementType = parseSql( sql );
     331           0 :     if ( eStatementType != eSelect )
     332           0 :         return NULL;
     333             : 
     334           0 :     return impl_executeCurrentQuery();
     335             : }
     336             : 
     337             : 
     338           0 : Reference< XConnection > SAL_CALL OCommonStatement::getConnection(  ) throw(SQLException, RuntimeException, std::exception)
     339             : {
     340           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     341           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     342             : 
     343             :     // just return our connection here
     344           0 :     return Reference< XConnection >(m_pConnection);
     345             : }
     346             : 
     347           0 : Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     348             : {
     349           0 :     Any aRet = ::cppu::queryInterface(rType,static_cast< XServiceInfo*> (this));
     350           0 :     if(!aRet.hasValue())
     351           0 :         aRet = OCommonStatement::queryInterface(rType);
     352           0 :     return aRet;
     353             : }
     354             : 
     355           0 : sal_Int32 SAL_CALL OCommonStatement::executeUpdate( const OUString& /*sql*/ ) throw(SQLException, RuntimeException, std::exception)
     356             : {
     357           0 :     ::dbtools::throwFeatureNotImplementedSQLException( "XStatement::executeUpdate", *this );
     358           0 :     return 0;
     359             : 
     360             : }
     361             : 
     362           0 : Any SAL_CALL OCommonStatement::getWarnings(  ) throw(SQLException, RuntimeException, std::exception)
     363             : {
     364           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     365           0 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     366             : 
     367           0 :     return makeAny(m_aLastWarning);
     368             : }
     369             : 
     370             : 
     371             : 
     372           4 : void SAL_CALL OCommonStatement::clearWarnings(  ) throw(SQLException, RuntimeException, std::exception)
     373             : {
     374           4 :     ::osl::MutexGuard aGuard( m_aMutex );
     375           4 :     checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed);
     376             : 
     377             : 
     378           4 :     m_aLastWarning = SQLWarning();
     379           4 : }
     380             : 
     381           0 : ::cppu::IPropertyArrayHelper* OCommonStatement::createArrayHelper( ) const
     382             : {
     383             :     // this properties are define by the service resultset
     384             :     // they must in alphabetic order
     385           0 :     Sequence< Property > aProps(9);
     386           0 :     Property* pProperties = aProps.getArray();
     387           0 :     sal_Int32 nPos = 0;
     388           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME),
     389           0 :         PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0);
     390           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING),
     391           0 :         PROPERTY_ID_ESCAPEPROCESSING, ::getBooleanCppuType(), 0);
     392           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION),
     393           0 :         PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0);
     394           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),
     395           0 :         PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0);
     396           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE),
     397           0 :         PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0);
     398           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS),
     399           0 :         PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0);
     400           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT),
     401           0 :         PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0);
     402           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY),
     403           0 :         PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0);
     404           0 :     pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE),
     405           0 :         PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0);
     406             : 
     407           0 :     return new ::cppu::OPropertyArrayHelper(aProps);
     408             : }
     409             : 
     410             : 
     411           0 : ::cppu::IPropertyArrayHelper & OCommonStatement::getInfoHelper()
     412             : {
     413           0 :     return *const_cast<OCommonStatement*>(this)->getArrayHelper();
     414             : }
     415             : 
     416           0 : sal_Bool OCommonStatement::convertFastPropertyValue(
     417             :                             Any & /*rConvertedValue*/,
     418             :                             Any & /*rOldValue*/,
     419             :                             sal_Int32 /*nHandle*/,
     420             :                             const Any& /*rValue*/ )
     421             :                                 throw (::com::sun::star::lang::IllegalArgumentException)
     422             : {
     423           0 :     bool bConverted = false;
     424             :     // here we have to try to convert
     425           0 :     return bConverted;
     426             : }
     427             : 
     428           0 : void OCommonStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& /*rValue*/) throw (Exception, std::exception)
     429             : {
     430             :     // set the value to whatever is necessary
     431             :     switch(nHandle)
     432             :     {
     433             :         case PROPERTY_ID_QUERYTIMEOUT:
     434             :         case PROPERTY_ID_MAXFIELDSIZE:
     435             :         case PROPERTY_ID_MAXROWS:
     436             :         case PROPERTY_ID_RESULTSETCONCURRENCY:
     437             :         case PROPERTY_ID_RESULTSETTYPE:
     438             :         case PROPERTY_ID_FETCHDIRECTION:
     439             :         case PROPERTY_ID_FETCHSIZE:
     440             :         case PROPERTY_ID_ESCAPEPROCESSING:
     441             :         default:
     442             :             ;
     443             :     }
     444           0 : }
     445             : 
     446           0 : void OCommonStatement::getFastPropertyValue(Any& /*rValue*/,sal_Int32 nHandle) const
     447             : {
     448             :     switch(nHandle)
     449             :     {
     450             :         case PROPERTY_ID_QUERYTIMEOUT:
     451             :         case PROPERTY_ID_MAXFIELDSIZE:
     452             :         case PROPERTY_ID_MAXROWS:
     453             :         case PROPERTY_ID_RESULTSETCONCURRENCY:
     454             :         case PROPERTY_ID_RESULTSETTYPE:
     455             :         case PROPERTY_ID_FETCHDIRECTION:
     456             :         case PROPERTY_ID_FETCHSIZE:
     457             :         case PROPERTY_ID_ESCAPEPROCESSING:
     458             :         default:
     459             :             ;
     460             :     }
     461           0 : }
     462             : 
     463           0 : IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
     464             : 
     465          36 : void SAL_CALL OCommonStatement::acquire() throw()
     466             : {
     467          36 :     OCommonStatement_IBASE::acquire();
     468          36 : }
     469             : 
     470          36 : void SAL_CALL OCommonStatement::release() throw()
     471             : {
     472          36 :     relase_ChildImpl();
     473          36 : }
     474             : 
     475           0 : void SAL_CALL OStatement::acquire() throw()
     476             : {
     477           0 :     OCommonStatement::acquire();
     478           0 : }
     479             : 
     480           0 : void SAL_CALL OStatement::release() throw()
     481             : {
     482           0 :     OCommonStatement::release();
     483           0 : }
     484             : 
     485           0 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OCommonStatement::getPropertySetInfo(  ) throw(RuntimeException, std::exception)
     486             : {
     487           0 :     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
     488             : }
     489             : 
     490           4 : void OCommonStatement::createColumnMapping()
     491             : {
     492             :     size_t i;
     493             : 
     494             :     // initialize the column index map (mapping select columns to table columns)
     495           4 :     ::rtl::Reference<connectivity::OSQLColumns> xColumns = m_pSQLIterator->getSelectColumns();
     496           4 :     m_aColMapping.resize(xColumns->get().size() + 1);
     497          12 :     for (i=0; i<m_aColMapping.size(); ++i)
     498           8 :         m_aColMapping[i] = static_cast<sal_Int32>(i);
     499             : 
     500           8 :     Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
     501             :     // now check which columns are bound
     502             : #if OSL_DEBUG_LEVEL > 0
     503             :     for ( i = 0; i < m_aColMapping.size(); i++ )
     504             :         OSL_TRACE("BEFORE Mapped: %d -> %d", i, m_aColMapping[i] );
     505             : #endif
     506           8 :     OResultSet::setBoundedColumns(m_aRow,xColumns,xNames,true,m_xDBMetaData,m_aColMapping);
     507             : #if OSL_DEBUG_LEVEL > 0
     508             :     for ( i = 0; i < m_aColMapping.size(); i++ )
     509             :         OSL_TRACE("AFTER  Mapped: %d -> %d", i, m_aColMapping[i] );
     510             : #endif
     511           4 : }
     512             : 
     513             : 
     514           4 : void OCommonStatement::analyseSQL()
     515             : {
     516           4 :     const OSQLParseNode* pOrderbyClause = m_pSQLIterator->getOrderTree();
     517           4 :     if(pOrderbyClause)
     518             :     {
     519           2 :         OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2);
     520             :         OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Fehler im Parse Tree");
     521             : 
     522           4 :         for (sal_uInt32 m = 0; m < pOrderingSpecCommalist->count(); m++)
     523             :         {
     524           2 :             OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m);
     525             :             OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Fehler im Parse Tree");
     526             :             OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Fehler im Parse Tree");
     527             : 
     528           2 :             OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0);
     529           2 :             if(!SQL_ISRULE(pColumnRef,column_ref))
     530             :             {
     531           0 :                 throw SQLException();
     532             :             }
     533           2 :             OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1);
     534           2 :             setOrderbyColumn(pColumnRef,pAscendingDescending);
     535             :         }
     536             :     }
     537           4 : }
     538             : 
     539           2 : void OCommonStatement::setOrderbyColumn(    OSQLParseNode* pColumnRef,
     540             :                                         OSQLParseNode* pAscendingDescending)
     541             : {
     542           2 :     OUString aColumnName;
     543           2 :     if (pColumnRef->count() == 1)
     544           2 :         aColumnName = pColumnRef->getChild(0)->getTokenValue();
     545           0 :     else if (pColumnRef->count() == 3)
     546             :     {
     547           0 :         pColumnRef->getChild(2)->parseNodeToStr( aColumnName, getOwnConnection(), NULL, false, false );
     548             :     }
     549             :     else
     550             :     {
     551           0 :         throw SQLException();
     552             :     }
     553             : 
     554           4 :     Reference<XColumnLocate> xColLocate(m_xColNames,UNO_QUERY);
     555           2 :     if(!xColLocate.is())
     556           2 :         return;
     557             : 
     558           2 :     m_aOrderbyColumnNumber.push_back(xColLocate->findColumn(aColumnName));
     559             : 
     560             :     // Ascending or Descending?
     561           4 :     m_aOrderbyAscending.push_back((SQL_ISTOKEN(pAscendingDescending,DESC)) ? SQL_DESC : SQL_ASC);
     562           6 : }
     563             : 
     564             : 
     565             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10