LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - FStatement.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 327 0.0 %
Date: 2014-04-14 Functions: 0 38 0.0 %
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             : #include <osl/diagnose.h>
      21             : #include "file/FStatement.hxx"
      22             : #include "file/FConnection.hxx"
      23             : #include "file/FDriver.hxx"
      24             : #include "file/FResultSet.hxx"
      25             : #include <comphelper/property.hxx>
      26             : #include <comphelper/uno3.hxx>
      27             : #include <osl/thread.h>
      28             : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
      29             : #include <com/sun/star/sdbc/ResultSetType.hpp>
      30             : #include <com/sun/star/sdbc/FetchDirection.hpp>
      31             : #include <com/sun/star/lang/DisposedException.hpp>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <comphelper/sequence.hxx>
      34             : #include <cppuhelper/typeprovider.hxx>
      35             : #include "connectivity/dbexception.hxx"
      36             : #include "resource/file_res.hrc"
      37             : #include <algorithm>
      38             : #include <tools/debug.hxx>
      39             : 
      40             : namespace connectivity
      41             : {
      42             :     namespace file
      43             :     {
      44             : 
      45             : 
      46             : using namespace dbtools;
      47             : using namespace com::sun::star::uno;
      48             : using namespace com::sun::star::lang;
      49             : using namespace com::sun::star::beans;
      50             : using namespace com::sun::star::sdbc;
      51             : using namespace com::sun::star::sdbcx;
      52             : using namespace com::sun::star::container;
      53             : 
      54           0 : OStatement_Base::OStatement_Base(OConnection* _pConnection )
      55             :     :OStatement_BASE(m_aMutex)
      56             :     ,::comphelper::OPropertyContainer(OStatement_BASE::rBHelper)
      57           0 :     ,m_xDBMetaData(_pConnection->getMetaData())
      58             :     ,m_aParser( _pConnection->getDriver()->getComponentContext() )
      59           0 :     ,m_aSQLIterator( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser, NULL )
      60             :     ,m_pConnection(_pConnection)
      61             :     ,m_pParseTree(NULL)
      62             :     ,m_pSQLAnalyzer(NULL)
      63             :     ,m_pEvaluationKeySet(NULL)
      64             :     ,m_pTable(NULL)
      65             :     ,m_nMaxFieldSize(0)
      66             :     ,m_nMaxRows(0)
      67             :     ,m_nQueryTimeOut(0)
      68             :     ,m_nFetchSize(0)
      69             :     ,m_nResultSetType(ResultSetType::FORWARD_ONLY)
      70             :     ,m_nFetchDirection(FetchDirection::FORWARD)
      71             :     ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
      72             :     ,m_bEscapeProcessing(sal_True)
      73           0 :     ,rBHelper(OStatement_BASE::rBHelper)
      74             : {
      75             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::OStatement_Base" );
      76             : 
      77           0 :     m_pConnection->acquire();
      78             : 
      79           0 :     sal_Int32 nAttrib = 0;
      80             : 
      81           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME),      PROPERTY_ID_CURSORNAME,         nAttrib,&m_aCursorName,     ::getCppuType(static_cast< OUString*>(0)));
      82           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE),    PROPERTY_ID_MAXFIELDSIZE,       nAttrib,&m_nMaxFieldSize,       ::getCppuType(static_cast<sal_Int32*>(0)));
      83           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS),         PROPERTY_ID_MAXROWS,            nAttrib,&m_nMaxRows,        ::getCppuType(static_cast<sal_Int32*>(0)));
      84           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT),    PROPERTY_ID_QUERYTIMEOUT,       nAttrib,&m_nQueryTimeOut,   ::getCppuType(static_cast<sal_Int32*>(0)));
      85           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),       PROPERTY_ID_FETCHSIZE,          nAttrib,&m_nFetchSize,      ::getCppuType(static_cast<sal_Int32*>(0)));
      86           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE),   PROPERTY_ID_RESULTSETTYPE,      nAttrib,&m_nResultSetType,  ::getCppuType(static_cast<sal_Int32*>(0)));
      87           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION),  PROPERTY_ID_FETCHDIRECTION,     nAttrib,&m_nFetchDirection, ::getCppuType(static_cast<sal_Int32*>(0)));
      88           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING),PROPERTY_ID_ESCAPEPROCESSING,   nAttrib,&m_bEscapeProcessing,::getCppuBooleanType());
      89             : 
      90           0 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY),        PROPERTY_ID_RESULTSETCONCURRENCY,   nAttrib,&m_nResultSetConcurrency,       ::getCppuType(static_cast<sal_Int32*>(0)));
      91           0 : }
      92             : 
      93           0 : OStatement_Base::~OStatement_Base()
      94             : {
      95           0 :     osl_atomic_increment( &m_refCount );
      96           0 :     disposing();
      97           0 :     delete m_pSQLAnalyzer;
      98           0 : }
      99             : 
     100           0 : void OStatement_BASE2::disposing()
     101             : {
     102           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     103             : 
     104           0 :     if(m_pSQLAnalyzer)
     105           0 :         m_pSQLAnalyzer->dispose();
     106             : 
     107           0 :     if(m_aRow.is())
     108             :     {
     109           0 :         m_aRow->get().clear();
     110           0 :         m_aRow = NULL;
     111             :     }
     112             : 
     113           0 :     m_aSQLIterator.dispose();
     114             : 
     115           0 :     if(m_pTable)
     116             :     {
     117           0 :         m_pTable->release();
     118           0 :         m_pTable = NULL;
     119             :     }
     120             : 
     121           0 :     if (m_pConnection)
     122             :     {
     123           0 :         m_pConnection->release();
     124           0 :         m_pConnection = NULL;
     125             :     }
     126             : 
     127           0 :     dispose_ChildImpl();
     128             : 
     129           0 :     if ( m_pParseTree )
     130             :     {
     131           0 :         delete m_pParseTree;
     132           0 :         m_pParseTree = NULL;
     133             :     }
     134             : 
     135           0 :     OStatement_Base::disposing();
     136           0 : }
     137             : 
     138           0 : void SAL_CALL OStatement_Base::acquire() throw()
     139             : {
     140           0 :     OStatement_BASE::acquire();
     141           0 : }
     142             : 
     143           0 : void SAL_CALL OStatement_BASE2::release() throw()
     144             : {
     145           0 :     relase_ChildImpl();
     146           0 : }
     147             : 
     148           0 : Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     149             : {
     150             :     //SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::queryInterface" );
     151           0 :     const Any aRet = OStatement_BASE::queryInterface(rType);
     152           0 :     return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
     153             : }
     154             : 
     155           0 : Sequence< Type > SAL_CALL OStatement_Base::getTypes(  ) throw(RuntimeException, std::exception)
     156             : {
     157             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::getTypes" );
     158           0 :     ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
     159           0 :                                                                     ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
     160           0 :                                                                     ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
     161             : 
     162           0 :     return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes());
     163             : }
     164             : 
     165             : 
     166           0 : void SAL_CALL OStatement_Base::cancel(  ) throw(RuntimeException, std::exception)
     167             : {
     168             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::cancel" );
     169           0 : }
     170             : 
     171             : 
     172           0 : void SAL_CALL OStatement_Base::close(  ) throw(SQLException, RuntimeException, std::exception)
     173             : {
     174             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::close" );
     175             :     {
     176           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     177           0 :         checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     178             :     }
     179           0 :     dispose();
     180           0 : }
     181             : 
     182             : 
     183           0 : void OStatement_Base::reset() throw (SQLException)
     184             : {
     185             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::reset" );
     186           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     187           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     188             : 
     189           0 :     clearWarnings ();
     190             : 
     191           0 : }
     192             : 
     193             : 
     194           0 : Any SAL_CALL OStatement_Base::getWarnings(  ) throw(SQLException, RuntimeException, std::exception)
     195             : {
     196             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::getWarnings" );
     197           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     198           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     199             : 
     200           0 :     return makeAny(m_aLastWarning);
     201             : }
     202             : 
     203           0 : void SAL_CALL OStatement_Base::clearWarnings(  ) throw(SQLException, RuntimeException, std::exception)
     204             : {
     205             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::clearWarnings" );
     206           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     207           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     208             : 
     209           0 :     m_aLastWarning = SQLWarning();
     210           0 : }
     211             : 
     212           0 : ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
     213             : {
     214             :     //SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::createArrayHelper" );
     215           0 :     Sequence< Property > aProps;
     216           0 :     describeProperties(aProps);
     217           0 :     return new ::cppu::OPropertyArrayHelper(aProps);
     218             : }
     219             : 
     220             : 
     221           0 : ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper()
     222             : {
     223             :     //SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::getInfoHelper" );
     224           0 :     return *const_cast<OStatement_Base*>(this)->getArrayHelper();
     225             : }
     226             : 
     227           0 : OResultSet* OStatement::createResultSet()
     228             : {
     229           0 :     return new OResultSet(this,m_aSQLIterator);
     230             : }
     231             : 
     232           0 : IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbc.driver.file.Statement","com.sun.star.sdbc.Statement");
     233             : 
     234           0 : void SAL_CALL OStatement::acquire() throw()
     235             : {
     236           0 :     OStatement_BASE2::acquire();
     237           0 : }
     238             : 
     239           0 : void SAL_CALL OStatement::release() throw()
     240             : {
     241           0 :     OStatement_BASE2::release();
     242           0 : }
     243             : 
     244             : 
     245           0 : sal_Bool SAL_CALL OStatement::execute( const OUString& sql ) throw(SQLException, RuntimeException, std::exception)
     246             : {
     247           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     248             : 
     249           0 :     executeQuery(sql);
     250             : 
     251           0 :     return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT;
     252             : }
     253             : 
     254             : 
     255             : 
     256           0 : Reference< XResultSet > SAL_CALL OStatement::executeQuery( const OUString& sql ) throw(SQLException, RuntimeException, std::exception)
     257             : {
     258           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     259           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     260             : 
     261           0 :     construct(sql);
     262           0 :     Reference< XResultSet > xRS;
     263           0 :     OResultSet* pResult = createResultSet();
     264           0 :     xRS = pResult;
     265           0 :     initializeResultSet(pResult);
     266             : 
     267           0 :     pResult->OpenImpl();
     268             : 
     269           0 :     return xRS;
     270             : }
     271             : 
     272           0 : Reference< XConnection > SAL_CALL OStatement::getConnection(  ) throw(SQLException, RuntimeException, std::exception)
     273             : {
     274           0 :     return (Reference< XConnection >)m_pConnection;
     275             : }
     276             : 
     277           0 : sal_Int32 SAL_CALL OStatement::executeUpdate( const OUString& sql ) throw(SQLException, RuntimeException, std::exception)
     278             : {
     279           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     280           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     281             : 
     282             : 
     283           0 :     construct(sql);
     284           0 :     OResultSet* pResult = createResultSet();
     285           0 :     Reference< XResultSet > xRS = pResult;
     286           0 :     initializeResultSet(pResult);
     287           0 :     pResult->OpenImpl();
     288             : 
     289           0 :     return pResult->getRowCountResult();
     290             : }
     291             : 
     292             : 
     293           0 : void SAL_CALL OStatement_Base::disposing(void)
     294             : {
     295             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::disposing" );
     296           0 :     if(m_aEvaluateRow.is())
     297             :     {
     298           0 :         m_aEvaluateRow->get().clear();
     299           0 :         m_aEvaluateRow = NULL;
     300             :     }
     301           0 :     delete m_pEvaluationKeySet;
     302           0 :     OStatement_BASE::disposing();
     303           0 : }
     304             : 
     305           0 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo(  ) throw(RuntimeException, std::exception)
     306             : {
     307             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::getPropertySetInfo" );
     308           0 :     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
     309             : }
     310             : 
     311           0 : Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     312             : {
     313           0 :     Any aRet = OStatement_XStatement::queryInterface( rType);
     314           0 :     return aRet.hasValue() ? aRet : OStatement_BASE2::queryInterface( rType);
     315             : }
     316             : 
     317           0 : OSQLAnalyzer* OStatement_Base::createAnalyzer()
     318             : {
     319             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::createAnalyzer" );
     320           0 :     return new OSQLAnalyzer(m_pConnection);
     321             : }
     322             : 
     323           0 : void OStatement_Base::anylizeSQL()
     324             : {
     325             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::anylizeSQL" );
     326             :     OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::anylizeSQL: Analyzer isn't set!");
     327             :     // start analysing the statement
     328           0 :     m_pSQLAnalyzer->setOrigColumns(m_xColNames);
     329           0 :     m_pSQLAnalyzer->start(m_pParseTree);
     330             : 
     331           0 :     const OSQLParseNode* pOrderbyClause = m_aSQLIterator.getOrderTree();
     332           0 :     if(pOrderbyClause)
     333             :     {
     334           0 :         OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2);
     335             :         OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Fehler im Parse Tree");
     336             : 
     337           0 :         for (sal_uInt32 m = 0; m < pOrderingSpecCommalist->count(); m++)
     338             :         {
     339           0 :             OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m);
     340             :             OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Fehler im Parse Tree");
     341             :             OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Fehler im Parse Tree");
     342             : 
     343           0 :             OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0);
     344           0 :             if(!SQL_ISRULE(pColumnRef,column_ref))
     345             :             {
     346           0 :                 throw SQLException();
     347             :             }
     348           0 :             OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1);
     349           0 :             setOrderbyColumn(pColumnRef,pAscendingDescending);
     350             :         }
     351             :     }
     352           0 : }
     353             : 
     354           0 : void OStatement_Base::setOrderbyColumn( OSQLParseNode* pColumnRef,
     355             :                                         OSQLParseNode* pAscendingDescending)
     356             : {
     357             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::setOrderbyColumn" );
     358           0 :     OUString aColumnName;
     359           0 :     if (pColumnRef->count() == 1)
     360           0 :         aColumnName = pColumnRef->getChild(0)->getTokenValue();
     361           0 :     else if (pColumnRef->count() == 3)
     362             :     {
     363           0 :         pColumnRef->getChild(2)->parseNodeToStr( aColumnName, getOwnConnection(), NULL, false, false );
     364             :     }
     365             :     else
     366             :     {
     367           0 :         throw SQLException();
     368             :     }
     369             : 
     370           0 :     Reference<XColumnLocate> xColLocate(m_xColNames,UNO_QUERY);
     371           0 :     if(!xColLocate.is())
     372           0 :         return;
     373             :     // Everything tested and we have the name of the Column.
     374             :     // What number is the Column?
     375           0 :     ::rtl::Reference<OSQLColumns> aSelectColumns = m_aSQLIterator.getSelectColumns();
     376           0 :     ::comphelper::UStringMixEqual aCase;
     377           0 :     OSQLColumns::Vector::const_iterator aFind = ::connectivity::find(aSelectColumns->get().begin(),aSelectColumns->get().end(),aColumnName,aCase);
     378           0 :     if ( aFind == aSelectColumns->get().end() )
     379           0 :         throw SQLException();
     380           0 :     m_aOrderbyColumnNumber.push_back((aFind - aSelectColumns->get().begin()) + 1);
     381             : 
     382             :     // Ascending or Descending?
     383           0 :     m_aOrderbyAscending.push_back((SQL_ISTOKEN(pAscendingDescending,DESC)) ? SQL_DESC : SQL_ASC);
     384             : }
     385             : 
     386             : 
     387           0 : void OStatement_Base::construct(const OUString& sql)  throw(SQLException, RuntimeException)
     388             : {
     389             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::construct" );
     390           0 :     OUString aErr;
     391           0 :     m_pParseTree = m_aParser.parseTree(aErr,sql);
     392           0 :     if(m_pParseTree)
     393             :     {
     394           0 :         m_aSQLIterator.setParseTree(m_pParseTree);
     395           0 :         m_aSQLIterator.traverseAll();
     396           0 :         const OSQLTables& xTabs = m_aSQLIterator.getTables();
     397             : 
     398             :         // sanity checks
     399           0 :         if ( xTabs.empty() )
     400             :             // no tables -> nothing to operate on -> error
     401           0 :             m_pConnection->throwGenericSQLException(STR_QUERY_NO_TABLE,*this);
     402             : 
     403           0 :         if ( xTabs.size() > 1 || m_aSQLIterator.hasErrors() )
     404             :             // more than one table -> can't operate on them -> error
     405           0 :             m_pConnection->throwGenericSQLException(STR_QUERY_MORE_TABLES,*this);
     406             : 
     407           0 :         if ( (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT) && m_aSQLIterator.getSelectColumns()->get().empty() )
     408             :             // SELECT statement without columns -> error
     409           0 :             m_pConnection->throwGenericSQLException(STR_QUERY_NO_COLUMN,*this);
     410             : 
     411           0 :         switch(m_aSQLIterator.getStatementType())
     412             :         {
     413             :             case SQL_STATEMENT_CREATE_TABLE:
     414             :             case SQL_STATEMENT_ODBC_CALL:
     415             :             case SQL_STATEMENT_UNKNOWN:
     416           0 :                 m_pConnection->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,*this);
     417           0 :                 break;
     418             :             default:
     419           0 :                 break;
     420             :         }
     421             : 
     422             :         // at this moment we support only one table per select statement
     423           0 :         Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(xTabs.begin()->second,UNO_QUERY);
     424           0 :         if(xTunnel.is())
     425             :         {
     426           0 :             if(m_pTable)
     427           0 :                 m_pTable->release();
     428           0 :             m_pTable = reinterpret_cast<OFileTable*>(xTunnel->getSomething(OFileTable::getUnoTunnelImplementationId()));
     429           0 :             if(m_pTable)
     430           0 :                 m_pTable->acquire();
     431             :         }
     432             :         OSL_ENSURE(m_pTable,"No table!");
     433           0 :         if ( m_pTable )
     434           0 :             m_xColNames     = m_pTable->getColumns();
     435           0 :         Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
     436             :         // set the binding of the resultrow
     437           0 :         m_aRow          = new OValueRefVector(xNames->getCount());
     438           0 :         (m_aRow->get())[0]->setBound(true);
     439           0 :         ::std::for_each(m_aRow->get().begin()+1,m_aRow->get().end(),TSetRefBound(false));
     440             : 
     441             :         // set the binding of the resultrow
     442           0 :         m_aEvaluateRow  = new OValueRefVector(xNames->getCount());
     443             : 
     444           0 :         (m_aEvaluateRow->get())[0]->setBound(true);
     445           0 :         ::std::for_each(m_aEvaluateRow->get().begin()+1,m_aEvaluateRow->get().end(),TSetRefBound(false));
     446             : 
     447             :         // set the select row
     448           0 :         m_aSelectRow = new OValueRefVector(m_aSQLIterator.getSelectColumns()->get().size());
     449           0 :         ::std::for_each(m_aSelectRow->get().begin(),m_aSelectRow->get().end(),TSetRefBound(true));
     450             : 
     451             :         // create the column mapping
     452           0 :         createColumnMapping();
     453             : 
     454           0 :         m_pSQLAnalyzer  = createAnalyzer();
     455             : 
     456           0 :         Reference<XIndexesSupplier> xIndexSup(xTunnel,UNO_QUERY);
     457           0 :         if(xIndexSup.is())
     458           0 :             m_pSQLAnalyzer->setIndexes(xIndexSup->getIndexes());
     459             : 
     460           0 :         anylizeSQL();
     461             :     }
     462             :     else
     463           0 :         throw SQLException(aErr,*this,OUString(),0,Any());
     464           0 : }
     465             : 
     466           0 : void OStatement_Base::createColumnMapping()
     467             : {
     468             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::createColumnMapping" );
     469             :     // initialize the column index map (mapping select columns to table columns)
     470           0 :     ::rtl::Reference<connectivity::OSQLColumns> xColumns = m_aSQLIterator.getSelectColumns();
     471           0 :     m_aColMapping.resize(xColumns->get().size() + 1);
     472           0 :     for (sal_Int32 i=0; i<(sal_Int32)m_aColMapping.size(); ++i)
     473           0 :         m_aColMapping[i] = i;
     474             : 
     475           0 :     Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
     476             :     // now check which columns are bound
     477           0 :     OResultSet::setBoundedColumns(m_aRow,m_aSelectRow,xColumns,xNames,sal_True,m_xDBMetaData,m_aColMapping);
     478           0 : }
     479             : 
     480           0 : void OStatement_Base::initializeResultSet(OResultSet* _pResult)
     481             : {
     482             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::initializeResultSet" );
     483           0 :     GetAssignValues();
     484             : 
     485           0 :     _pResult->setSqlAnalyzer(m_pSQLAnalyzer);
     486           0 :     _pResult->setOrderByColumns(m_aOrderbyColumnNumber);
     487           0 :     _pResult->setOrderByAscending(m_aOrderbyAscending);
     488           0 :     _pResult->setBindingRow(m_aRow);
     489           0 :     _pResult->setColumnMapping(m_aColMapping);
     490           0 :     _pResult->setEvaluationRow(m_aEvaluateRow);
     491           0 :     _pResult->setAssignValues(m_aAssignValues);
     492           0 :     _pResult->setSelectRow(m_aSelectRow);
     493             : 
     494           0 :     m_pSQLAnalyzer->bindSelectRow(m_aRow);
     495           0 :     m_pEvaluationKeySet = m_pSQLAnalyzer->bindEvaluationRow(m_aEvaluateRow);    // Set values in the code of the Compiler
     496           0 :     _pResult->setEvaluationKeySet(m_pEvaluationKeySet);
     497           0 : }
     498             : 
     499           0 : void OStatement_Base::GetAssignValues()
     500             : {
     501             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::GetAssignValues" );
     502           0 :     if (m_pParseTree == NULL)
     503             :     {
     504           0 :         ::dbtools::throwFunctionSequenceException(*this);
     505           0 :         return;
     506             :     }
     507             : 
     508           0 :     if (SQL_ISRULE(m_pParseTree,select_statement))
     509             :         // no values have to be set for SELECT
     510           0 :         return;
     511           0 :     else if (SQL_ISRULE(m_pParseTree,insert_statement))
     512             :     {
     513             :         // Create Row for the values to be set (Reference trough new)
     514           0 :         if(m_aAssignValues.is())
     515           0 :             m_aAssignValues->get().clear();
     516           0 :         sal_Int32 nCount = Reference<XIndexAccess>(m_xColNames,UNO_QUERY)->getCount();
     517           0 :         m_aAssignValues = new OAssignValues(nCount);
     518             :         // unbound all
     519           0 :         ::std::for_each(m_aAssignValues->get().begin()+1,m_aAssignValues->get().end(),TSetRefBound(false));
     520             : 
     521           0 :         m_aParameterIndexes.resize(nCount+1,SQL_NO_PARAMETER);
     522             : 
     523             :         // List of Column-Names, that exist in the column_commalist (separated by ;):
     524           0 :         ::std::vector<OUString> aColumnNameList;
     525             : 
     526             :         OSL_ENSURE(m_pParseTree->count() >= 4,"OResultSet: Fehler im Parse Tree");
     527             : 
     528           0 :         OSQLParseNode * pOptColumnCommalist = m_pParseTree->getChild(3);
     529             :         OSL_ENSURE(pOptColumnCommalist != NULL,"OResultSet: Fehler im Parse Tree");
     530             :         OSL_ENSURE(SQL_ISRULE(pOptColumnCommalist,opt_column_commalist),"OResultSet: Fehler im Parse Tree");
     531           0 :         if (pOptColumnCommalist->count() == 0)
     532             :         {
     533           0 :             const Sequence< OUString>& aNames = m_xColNames->getElementNames();
     534           0 :             const OUString* pBegin = aNames.getConstArray();
     535           0 :             const OUString* pEnd = pBegin + aNames.getLength();
     536           0 :             for (; pBegin != pEnd; ++pBegin)
     537           0 :                 aColumnNameList.push_back(*pBegin);
     538             :         }
     539             :         else
     540             :         {
     541             :             OSL_ENSURE(pOptColumnCommalist->count() == 3,"OResultSet: Fehler im Parse Tree");
     542             : 
     543           0 :             OSQLParseNode * pColumnCommalist = pOptColumnCommalist->getChild(1);
     544             :             OSL_ENSURE(pColumnCommalist != NULL,"OResultSet: Fehler im Parse Tree");
     545             :             OSL_ENSURE(SQL_ISRULE(pColumnCommalist,column_commalist),"OResultSet: Fehler im Parse Tree");
     546             :             OSL_ENSURE(pColumnCommalist->count() > 0,"OResultSet: Fehler im Parse Tree");
     547             : 
     548             :             // All Columns in the column_commalist ...
     549           0 :             for (sal_uInt32 i = 0; i < pColumnCommalist->count(); i++)
     550             :             {
     551           0 :                 OSQLParseNode * pCol = pColumnCommalist->getChild(i);
     552             :                 OSL_ENSURE(pCol != NULL,"OResultSet: Fehler im Parse Tree");
     553           0 :                 aColumnNameList.push_back(pCol->getTokenValue());
     554             :             }
     555             :         }
     556           0 :         if ( aColumnNameList.empty() )
     557           0 :             throwFunctionSequenceException(*this);
     558             : 
     559             :         // Values ...
     560           0 :         OSQLParseNode * pValuesOrQuerySpec = m_pParseTree->getChild(4);
     561             :         OSL_ENSURE(pValuesOrQuerySpec != NULL,"OResultSet: pValuesOrQuerySpec darf nicht NULL sein!");
     562             :         OSL_ENSURE(SQL_ISRULE(pValuesOrQuerySpec,values_or_query_spec),"OResultSet: ! SQL_ISRULE(pValuesOrQuerySpec,values_or_query_spec)");
     563             :         OSL_ENSURE(pValuesOrQuerySpec->count() > 0,"OResultSet: pValuesOrQuerySpec->count() <= 0");
     564             : 
     565             :         // just "VALUES" is allowed ...
     566           0 :         if (! SQL_ISTOKEN(pValuesOrQuerySpec->getChild(0),VALUES))
     567           0 :             throwFunctionSequenceException(*this);
     568             : 
     569             :         OSL_ENSURE(pValuesOrQuerySpec->count() == 4,"OResultSet: pValuesOrQuerySpec->count() != 4");
     570             : 
     571             :         // List of values
     572           0 :         OSQLParseNode * pInsertAtomCommalist = pValuesOrQuerySpec->getChild(2);
     573             :         OSL_ENSURE(pInsertAtomCommalist != NULL,"OResultSet: pInsertAtomCommalist darf nicht NULL sein!");
     574             :         OSL_ENSURE(pInsertAtomCommalist->count() > 0,"OResultSet: pInsertAtomCommalist <= 0");
     575             : 
     576             :         OSQLParseNode * pRow_Value_Const;
     577           0 :         sal_Int32 nIndex=0;
     578           0 :         for (sal_uInt32 i = 0; i < pInsertAtomCommalist->count(); i++)
     579             :         {
     580           0 :             pRow_Value_Const = pInsertAtomCommalist->getChild(i); // row_value_constructor
     581             :             OSL_ENSURE(pRow_Value_Const != NULL,"OResultSet: pRow_Value_Const darf nicht NULL sein!");
     582           0 :             if(SQL_ISRULE(pRow_Value_Const,parameter))
     583             :             {
     584           0 :                 ParseAssignValues(aColumnNameList,pRow_Value_Const,nIndex++); // only one Columnname allowed per loop
     585             :             }
     586           0 :             else if(pRow_Value_Const->isToken())
     587           0 :                 ParseAssignValues(aColumnNameList,pRow_Value_Const,i);
     588             :             else
     589             :             {
     590           0 :                 if(pRow_Value_Const->count() == aColumnNameList.size())
     591             :                 {
     592           0 :                     for (sal_uInt32 j = 0; j < pRow_Value_Const->count(); ++j)
     593           0 :                         ParseAssignValues(aColumnNameList,pRow_Value_Const->getChild(j),nIndex++);
     594             :                 }
     595             :                 else
     596           0 :                     throwFunctionSequenceException(*this);
     597             :             }
     598           0 :         }
     599             :     }
     600           0 :     else if (SQL_ISRULE(m_pParseTree,update_statement_searched))
     601             :     {
     602           0 :         if(m_aAssignValues.is())
     603           0 :             m_aAssignValues->get().clear();
     604           0 :         sal_Int32 nCount = Reference<XIndexAccess>(m_xColNames,UNO_QUERY)->getCount();
     605           0 :         m_aAssignValues = new OAssignValues(nCount);
     606             :         // unbound all
     607           0 :         ::std::for_each(m_aAssignValues->get().begin()+1,m_aAssignValues->get().end(),TSetRefBound(false));
     608             : 
     609           0 :         m_aParameterIndexes.resize(nCount+1,SQL_NO_PARAMETER);
     610             : 
     611             :         OSL_ENSURE(m_pParseTree->count() >= 4,"OResultSet: Fehler im Parse Tree");
     612             : 
     613           0 :         OSQLParseNode * pAssignmentCommalist = m_pParseTree->getChild(3);
     614             :         OSL_ENSURE(pAssignmentCommalist != NULL,"OResultSet: pAssignmentCommalist == NULL");
     615             :         OSL_ENSURE(SQL_ISRULE(pAssignmentCommalist,assignment_commalist),"OResultSet: Fehler im Parse Tree");
     616             :         OSL_ENSURE(pAssignmentCommalist->count() > 0,"OResultSet: pAssignmentCommalist->count() <= 0");
     617             : 
     618             :         // work on all assignments (commalist) ...
     619           0 :         ::std::vector< OUString> aList(1);
     620           0 :         for (sal_uInt32 i = 0; i < pAssignmentCommalist->count(); i++)
     621             :         {
     622           0 :             OSQLParseNode * pAssignment = pAssignmentCommalist->getChild(i);
     623             :             OSL_ENSURE(pAssignment != NULL,"OResultSet: pAssignment == NULL");
     624             :             OSL_ENSURE(SQL_ISRULE(pAssignment,assignment),"OResultSet: Fehler im Parse Tree");
     625             :             OSL_ENSURE(pAssignment->count() == 3,"OResultSet: pAssignment->count() != 3");
     626             : 
     627           0 :             OSQLParseNode * pCol = pAssignment->getChild(0);
     628             :             OSL_ENSURE(pCol != NULL,"OResultSet: pCol == NULL");
     629             : 
     630           0 :             OSQLParseNode * pComp = pAssignment->getChild(1);
     631             :             OSL_ENSURE(pComp != NULL,"OResultSet: pComp == NULL");
     632             :             OSL_ENSURE(pComp->getNodeType() == SQL_NODE_EQUAL,"OResultSet: pComp->getNodeType() != SQL_NODE_COMPARISON");
     633           0 :             if (pComp->getTokenValue().toChar() != '=')
     634             :             {
     635           0 :                 throwFunctionSequenceException(*this);
     636             :             }
     637             : 
     638           0 :             OSQLParseNode * pVal = pAssignment->getChild(2);
     639             :             OSL_ENSURE(pVal != NULL,"OResultSet: pVal == NULL");
     640           0 :             aList[0] = pCol->getTokenValue();
     641           0 :             ParseAssignValues(aList,pVal,0);
     642           0 :         }
     643             : 
     644             :     }
     645             : }
     646             : 
     647           0 : void OStatement_Base::ParseAssignValues(const ::std::vector< OUString>& aColumnNameList,OSQLParseNode* pRow_Value_Constructor_Elem, sal_Int32 nIndex)
     648             : {
     649             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::ParseAssignValues" );
     650             :     OSL_ENSURE(size_t(nIndex) <= aColumnNameList.size(),"SdbFileCursor::ParseAssignValues: nIndex > aColumnNameList.GetTokenCount()");
     651           0 :     OUString aColumnName(aColumnNameList[nIndex]);
     652             :     OSL_ENSURE(aColumnName.getLength() > 0,"OResultSet: Column-Name nicht gefunden");
     653             :     OSL_ENSURE(pRow_Value_Constructor_Elem != NULL,"OResultSet: pRow_Value_Constructor_Elem darf nicht NULL sein!");
     654             : 
     655           0 :     if (pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_STRING ||
     656           0 :         pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_INTNUM ||
     657           0 :         pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_APPROXNUM)
     658             :     {
     659             :         // set value:
     660           0 :         SetAssignValue(aColumnName, pRow_Value_Constructor_Elem->getTokenValue());
     661             :     }
     662           0 :     else if (SQL_ISTOKEN(pRow_Value_Constructor_Elem,NULL))
     663             :     {
     664             :         // set NULL
     665           0 :         SetAssignValue(aColumnName, OUString(), sal_True);
     666             :     }
     667           0 :     else if (SQL_ISRULE(pRow_Value_Constructor_Elem,parameter))
     668           0 :         parseParamterElem(aColumnName,pRow_Value_Constructor_Elem);
     669             :     else
     670             :     {
     671           0 :         throwFunctionSequenceException(*this);
     672           0 :     }
     673           0 : }
     674             : 
     675           0 : void OStatement_Base::SetAssignValue(const OUString& aColumnName,
     676             :                                      const OUString& aValue,
     677             :                                      sal_Bool bSetNull,
     678             :                                      sal_uInt32 nParameter)
     679             : {
     680             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::SetAssignValue" );
     681           0 :     Reference<XPropertySet> xCol;
     682           0 :     m_xColNames->getByName(aColumnName) >>= xCol;
     683           0 :     sal_Int32 nId = Reference<XColumnLocate>(m_xColNames,UNO_QUERY)->findColumn(aColumnName);
     684             :     // does this column actually exist in the file?
     685             : 
     686           0 :     if (!xCol.is())
     687             :     {
     688             :         // This Column doesn't exist!
     689           0 :         throwFunctionSequenceException(*this);
     690             :     }
     691             : 
     692             : 
     693             :     // Everything tested and we have the names of the Column.
     694             :     // Now allocate one Value, set the value and tie the value to the Row.
     695           0 :     if (bSetNull)
     696           0 :         (m_aAssignValues->get())[nId]->setNull();
     697             :     else
     698             :     {
     699           0 :         switch (::comphelper::getINT32(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
     700             :         {
     701             :             // put criteria depending on the Type as String or double in the variable
     702             :         case DataType::CHAR:
     703             :         case DataType::VARCHAR:
     704             :         case DataType::LONGVARCHAR:
     705           0 :             *(m_aAssignValues->get())[nId] = ORowSetValue(aValue);
     706             :             //Characterset is already converted, since the entire statement was converted
     707           0 :             break;
     708             : 
     709             :         case DataType::BIT:
     710           0 :             if (aValue.equalsIgnoreAsciiCase("TRUE")  || aValue[0] == '1')
     711           0 :                 *(m_aAssignValues->get())[nId] = sal_True;
     712           0 :             else if (aValue.equalsIgnoreAsciiCase("FALSE") || aValue[0] == '0')
     713           0 :                 *(m_aAssignValues->get())[nId] = sal_False;
     714             :             else
     715           0 :                 throwFunctionSequenceException(*this);
     716           0 :             break;
     717             :         case DataType::TINYINT:
     718             :         case DataType::SMALLINT:
     719             :         case DataType::INTEGER:
     720             :         case DataType::DECIMAL:
     721             :         case DataType::NUMERIC:
     722             :         case DataType::REAL:
     723             :         case DataType::DOUBLE:
     724             :         case DataType::DATE:
     725             :         case DataType::TIME:
     726             :         case DataType::TIMESTAMP:
     727           0 :             *(m_aAssignValues->get())[nId] = ORowSetValue(aValue);
     728           0 :             break;
     729             :         default:
     730           0 :             throwFunctionSequenceException(*this);
     731             :         }
     732             :     }
     733             : 
     734             :     // save Parameter-No. (as User Data)
     735             :     // SQL_NO_PARAMETER = no Parameter.
     736           0 :     m_aAssignValues->setParameterIndex(nId,nParameter);
     737           0 :     if(nParameter != SQL_NO_PARAMETER)
     738           0 :         m_aParameterIndexes[nParameter] = nId;
     739           0 : }
     740             : 
     741           0 : void OStatement_Base::parseParamterElem(const OUString& /*_sColumnName*/,OSQLParseNode* /*pRow_Value_Constructor_Elem*/)
     742             : {
     743             :     SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::parseParamterElem" );
     744             :     // do nothing here
     745           0 : }
     746             : 
     747             :     } // namespace file
     748             : 
     749             : }// namespace connectivity
     750             : 
     751             : 
     752             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10