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

Generated by: LCOV version 1.11