LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - FPreparedStatement.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 89 275 32.4 %
Date: 2014-11-03 Functions: 16 51 31.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 <stdio.h>
      22             : #include <connectivity/sdbcx/VColumn.hxx>
      23             : #include <osl/diagnose.h>
      24             : #include "file/FPreparedStatement.hxx"
      25             : #include <com/sun/star/sdbc/DataType.hpp>
      26             : #include "file/FResultSetMetaData.hxx"
      27             : #include <cppuhelper/typeprovider.hxx>
      28             : #include <comphelper/sequence.hxx>
      29             : #include <com/sun/star/lang/DisposedException.hpp>
      30             : #include <connectivity/dbconversion.hxx>
      31             : #include <connectivity/dbexception.hxx>
      32             : #include <connectivity/dbtools.hxx>
      33             : #include <connectivity/PColumn.hxx>
      34             : #include "diagnose_ex.h"
      35             : #include <comphelper/types.hxx>
      36             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      37             : #include "resource/file_res.hrc"
      38             : 
      39             : using namespace connectivity;
      40             : using namespace comphelper;
      41             : using namespace ::dbtools;
      42             : using namespace connectivity::file;
      43             : using namespace com::sun::star::uno;
      44             : using namespace com::sun::star::lang;
      45             : using namespace com::sun::star::beans;
      46             : using namespace com::sun::star::sdbc;
      47             : using namespace com::sun::star::sdbcx;
      48             : using namespace com::sun::star::container;
      49             : using namespace com::sun::star;
      50             : 
      51           0 : IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbc.driver.file.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
      52             : 
      53         110 : OPreparedStatement::OPreparedStatement( OConnection* _pConnection)
      54         110 :     : OStatement_BASE2( _pConnection )
      55             : {
      56         110 : }
      57             : 
      58             : 
      59         110 : OPreparedStatement::~OPreparedStatement()
      60             : {
      61         110 : }
      62             : 
      63             : 
      64         110 : void OPreparedStatement::disposing()
      65             : {
      66         110 :     ::osl::MutexGuard aGuard(m_aMutex);
      67             : 
      68         110 :     OStatement_BASE2::disposing();
      69             : 
      70         110 :     m_xParamColumns = NULL;
      71         110 :     m_xMetaData.clear();
      72         110 :     if(m_aParameterRow.is())
      73             :     {
      74          88 :         m_aParameterRow->get().clear();
      75          88 :         m_aParameterRow = NULL;
      76         110 :     }
      77         110 : }
      78             : 
      79         110 : void OPreparedStatement::construct(const OUString& sql)  throw(SQLException, RuntimeException)
      80             : {
      81         110 :     OStatement_Base::construct(sql);
      82             : 
      83          88 :     m_aParameterRow = new OValueRefVector();
      84          88 :     m_aParameterRow->get().push_back(new ORowSetValueDecorator(sal_Int32(0)) );
      85             : 
      86          88 :     Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
      87             : 
      88          88 :     if ( m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT )
      89          88 :         m_xParamColumns = m_aSQLIterator.getParameters();
      90             :     else
      91             :     {
      92           0 :         m_xParamColumns = new OSQLColumns();
      93             :         // describe all parameters need for the resultset
      94           0 :         describeParameter();
      95             :     }
      96             : 
      97         176 :     OValueRefRow aTemp;
      98         176 :     OResultSet::setBoundedColumns(m_aEvaluateRow,aTemp,m_xParamColumns,xNames,false,m_xDBMetaData,m_aColMapping);
      99          88 : }
     100             : 
     101          46 : rtl::Reference<OResultSet> OPreparedStatement::makeResultSet()
     102             : {
     103          46 :     closeResultSet();
     104             : 
     105          46 :     rtl::Reference<OResultSet> xResultSet(createResultSet());
     106          46 :     m_xResultSet = xResultSet.get();
     107          46 :     initializeResultSet(xResultSet.get());
     108          46 :     initResultSet(xResultSet.get());
     109          46 :     return xResultSet;
     110             : }
     111             : 
     112        1144 : Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     113             : {
     114        1144 :     Any aRet = OStatement_BASE2::queryInterface(rType);
     115        1144 :     return aRet.hasValue() ? aRet : ::cppu::queryInterface( rType,
     116             :                                         static_cast< XPreparedStatement*>(this),
     117             :                                         static_cast< XParameters*>(this),
     118        1144 :                                         static_cast< XResultSetMetaDataSupplier*>(this));
     119             : }
     120             : 
     121           0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     122             : {
     123           0 :         ::cppu::OTypeCollection aTypes( cppu::UnoType<XPreparedStatement>::get(),
     124           0 :                                         cppu::UnoType<XParameters>::get(),
     125           0 :                                         cppu::UnoType<XResultSetMetaDataSupplier>::get());
     126             : 
     127           0 :     return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes());
     128             : }
     129             : 
     130             : 
     131          94 : Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData(  ) throw(SQLException, RuntimeException, std::exception)
     132             : {
     133          94 :     ::osl::MutexGuard aGuard( m_aMutex );
     134          94 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     135             : 
     136             : 
     137          94 :     if(!m_xMetaData.is())
     138          88 :         m_xMetaData = new OResultSetMetaData(m_aSQLIterator.getSelectColumns(),m_aSQLIterator.getTables().begin()->first,m_pTable);
     139          94 :     return m_xMetaData;
     140             : }
     141             : 
     142             : 
     143          88 : void SAL_CALL OPreparedStatement::close(  ) throw(SQLException, RuntimeException, std::exception)
     144             : {
     145          88 :     ::osl::MutexGuard aGuard( m_aMutex );
     146          88 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     147             : 
     148          88 :     closeResultSet();
     149          88 : }
     150             : 
     151             : 
     152           0 : sal_Bool SAL_CALL OPreparedStatement::execute(  ) throw(SQLException, RuntimeException, std::exception)
     153             : {
     154           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     155           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     156             : 
     157           0 :     rtl::Reference<OResultSet> xRS(makeResultSet());
     158             :     // since we don't support the XMultipleResults interface, nobody will ever get that ResultSet...
     159           0 :     if(xRS.is())
     160           0 :         xRS->dispose();
     161             : 
     162           0 :     return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT;
     163             : }
     164             : 
     165             : 
     166           0 : sal_Int32 SAL_CALL OPreparedStatement::executeUpdate(  ) throw(SQLException, RuntimeException, std::exception)
     167             : {
     168           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     169           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     170             : 
     171           0 :     rtl::Reference<OResultSet> xRS(makeResultSet());
     172           0 :     if(xRS.is())
     173             :     {
     174           0 :         const sal_Int32 res(xRS->getRowCountResult());
     175             :         // nobody will ever get that ResultSet...
     176           0 :         xRS->dispose();
     177           0 :         return res;
     178             :     }
     179             :     else
     180           0 :         return 0;
     181             : }
     182             : 
     183             : 
     184          10 : void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x ) throw(SQLException, RuntimeException, std::exception)
     185             : {
     186          10 :     setParameter(parameterIndex,x);
     187          10 : }
     188             : 
     189             : 
     190           0 : Reference< XConnection > SAL_CALL OPreparedStatement::getConnection(  ) throw(SQLException, RuntimeException, std::exception)
     191             : {
     192           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     193           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     194             : 
     195           0 :     return Reference< XConnection >(m_pConnection);
     196             : }
     197             : 
     198             : 
     199          46 : Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery(  ) throw(SQLException, RuntimeException, std::exception)
     200             : {
     201          46 :     ::osl::MutexGuard aGuard( m_aMutex );
     202          46 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     203             : 
     204          46 :     return makeResultSet().get();
     205             : }
     206             : 
     207             : 
     208           0 : void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException, std::exception)
     209             : {
     210           0 :     setParameter(parameterIndex,static_cast<bool>(x));
     211           0 : }
     212             : 
     213           0 : void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException, std::exception)
     214             : {
     215           0 :     setParameter(parameterIndex,x);
     216           0 : }
     217             : 
     218             : 
     219           0 : void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const util::Date& aData ) throw(SQLException, RuntimeException, std::exception)
     220             : {
     221           0 :     setParameter(parameterIndex,DBTypeConversion::toDouble(aData));
     222           0 : }
     223             : 
     224           0 : void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const util::Time& aVal ) throw(SQLException, RuntimeException, std::exception)
     225             : {
     226           0 :     setParameter(parameterIndex,DBTypeConversion::toDouble(aVal));
     227           0 : }
     228             : 
     229             : 
     230           0 : void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const util::DateTime& aVal ) throw(SQLException, RuntimeException, std::exception)
     231             : {
     232           0 :     setParameter(parameterIndex,DBTypeConversion::toDouble(aVal));
     233           0 : }
     234             : 
     235             : 
     236           0 : void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException, std::exception)
     237             : {
     238           0 :     setParameter(parameterIndex,x);
     239           0 : }
     240             : 
     241             : 
     242             : 
     243           0 : void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException, std::exception)
     244             : {
     245           0 :     setParameter(parameterIndex,x);
     246           0 : }
     247             : 
     248             : 
     249           0 : void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException, std::exception)
     250             : {
     251           0 :     setParameter(parameterIndex,x);
     252           0 : }
     253             : 
     254             : 
     255           0 : void SAL_CALL OPreparedStatement::setLong( sal_Int32 /*parameterIndex*/, sal_Int64 /*aVal*/ ) throw(SQLException, RuntimeException, std::exception)
     256             : {
     257           0 :     throwFeatureNotImplementedSQLException( "XParameters::setLong", *this );
     258           0 : }
     259             : 
     260             : 
     261           0 : void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException, std::exception)
     262             : {
     263           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     264           0 :     checkAndResizeParameters(parameterIndex);
     265             : 
     266           0 :     if ( m_aAssignValues.is() )
     267           0 :         (m_aAssignValues->get())[m_aParameterIndexes[parameterIndex]]->setNull();
     268             :     else
     269           0 :         (m_aParameterRow->get())[parameterIndex]->setNull();
     270           0 : }
     271             : 
     272             : 
     273           0 : void SAL_CALL OPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException, std::exception)
     274             : {
     275           0 :     throwFeatureNotImplementedSQLException( "XParameters::setClob", *this );
     276           0 : }
     277             : 
     278             : 
     279           0 : void SAL_CALL OPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException, std::exception)
     280             : {
     281           0 :     throwFeatureNotImplementedSQLException( "XParameters::setBlob", *this );
     282           0 : }
     283             : 
     284             : 
     285           0 : void SAL_CALL OPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException, std::exception)
     286             : {
     287           0 :     throwFeatureNotImplementedSQLException( "XParameters::setArray", *this );
     288           0 : }
     289             : 
     290             : 
     291           0 : void SAL_CALL OPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException, std::exception)
     292             : {
     293           0 :     throwFeatureNotImplementedSQLException( "XParameters::setRef", *this );
     294           0 : }
     295             : 
     296             : 
     297           0 : void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException, std::exception)
     298             : {
     299           0 :     switch(sqlType)
     300             :     {
     301             :         case DataType::DECIMAL:
     302             :         case DataType::NUMERIC:
     303           0 :             setString(parameterIndex,::comphelper::getString(x));
     304           0 :             break;
     305             :         default:
     306           0 :             ::dbtools::setObjectWithInfo(this,parameterIndex,x,sqlType,scale);
     307           0 :             break;
     308             :     }
     309           0 : }
     310             : 
     311             : 
     312           0 : void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& /*typeName*/ ) throw(SQLException, RuntimeException, std::exception)
     313             : {
     314           0 :     setNull(parameterIndex,sqlType);
     315           0 : }
     316             : 
     317             : 
     318           0 : void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException, std::exception)
     319             : {
     320           0 :     if(!::dbtools::implSetObject(this,parameterIndex,x))
     321             :     {
     322           0 :         const OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
     323             :                 STR_UNKNOWN_PARA_TYPE,
     324             :                 "$position$", OUString::number(parameterIndex)
     325           0 :              ) );
     326           0 :         ::dbtools::throwGenericSQLException(sError,*this);
     327             :     }
     328             :     //  setObject (parameterIndex, x, sqlType, 0);
     329           0 : }
     330             : 
     331             : 
     332           0 : void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException, std::exception)
     333             : {
     334           0 :     setParameter(parameterIndex,x);
     335           0 : }
     336             : 
     337             : 
     338           0 : void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException, std::exception)
     339             : {
     340           0 :     setParameter(parameterIndex,x);
     341           0 : }
     342             : 
     343             : 
     344             : 
     345           0 : void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException, std::exception)
     346             : {
     347           0 :     setBinaryStream(parameterIndex,x,length );
     348           0 : }
     349             : 
     350             : 
     351           0 : void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException, std::exception)
     352             : {
     353           0 :     if(!x.is())
     354           0 :         ::dbtools::throwFunctionSequenceException(*this);
     355             : 
     356           0 :     Sequence<sal_Int8> aSeq;
     357           0 :     x->readBytes(aSeq,length);
     358           0 :     setParameter(parameterIndex,aSeq);
     359           0 : }
     360             : 
     361             : 
     362           0 : void SAL_CALL OPreparedStatement::clearParameters(  ) throw(SQLException, RuntimeException, std::exception)
     363             : {
     364           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     365           0 :     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     366             : 
     367           0 :     m_aParameterRow->get().clear();
     368           0 :     m_aParameterRow->get().push_back(new ORowSetValueDecorator(sal_Int32(0)) );
     369           0 : }
     370             : 
     371           0 : OResultSet* OPreparedStatement::createResultSet()
     372             : {
     373           0 :     return new OResultSet(this,m_aSQLIterator);
     374             : }
     375             : 
     376          46 : void OPreparedStatement::initResultSet(OResultSet *pResultSet)
     377             : {
     378             :     // check if we got enough parameters
     379          92 :     if ( (m_aParameterRow.is() && ( m_aParameterRow->get().size() -1 ) < m_xParamColumns->get().size()) ||
     380          92 :          (m_xParamColumns.is() && !m_aParameterRow.is() && !m_aParameterRow->get().empty()) )
     381           0 :          m_pConnection->throwGenericSQLException(STR_INVALID_PARA_COUNT,*this);
     382             : 
     383          46 :     pResultSet->OpenImpl();
     384          46 :     pResultSet->setMetaData(getMetaData());
     385          46 : }
     386             : 
     387        2514 : void SAL_CALL OPreparedStatement::acquire() throw()
     388             : {
     389        2514 :     OStatement_BASE2::acquire();
     390        2514 : }
     391             : 
     392        2514 : void SAL_CALL OPreparedStatement::release() throw()
     393             : {
     394        2514 :     OStatement_BASE2::release();
     395        2514 : }
     396             : 
     397          10 : void OPreparedStatement::checkAndResizeParameters(sal_Int32 parameterIndex)
     398             : {
     399          10 :     ::connectivity::checkDisposed(OStatement_BASE::rBHelper.bDisposed);
     400          10 :     if ( m_aAssignValues.is() && (parameterIndex < 1 || parameterIndex >= static_cast<sal_Int32>(m_aParameterIndexes.size())) )
     401           0 :         throwInvalidIndexException(*this);
     402          10 :     else if ( static_cast<sal_Int32>((m_aParameterRow->get()).size()) <= parameterIndex )
     403             :     {
     404           0 :         sal_Int32 i = m_aParameterRow->get().size();
     405           0 :         (m_aParameterRow->get()).resize(parameterIndex+1);
     406           0 :         for ( ; i <= parameterIndex; ++i)
     407             :         {
     408           0 :             if ( !(m_aParameterRow->get())[i].is() )
     409           0 :                 (m_aParameterRow->get())[i] = new ORowSetValueDecorator;
     410             :         }
     411             :     }
     412          10 : }
     413             : 
     414          10 : void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const ORowSetValue& x)
     415             : {
     416          10 :     ::osl::MutexGuard aGuard( m_aMutex );
     417          10 :     checkAndResizeParameters(parameterIndex);
     418             : 
     419          10 :     if(m_aAssignValues.is())
     420           0 :         *(m_aAssignValues->get())[m_aParameterIndexes[parameterIndex]] = x;
     421             :     else
     422          10 :         *((m_aParameterRow->get())[parameterIndex]) = x;
     423          10 : }
     424             : 
     425           0 : sal_uInt32 OPreparedStatement::AddParameter(OSQLParseNode * pParameter, const Reference<XPropertySet>& _xCol)
     426             : {
     427             :     OSL_UNUSED( pParameter );
     428             :     OSL_ENSURE(SQL_ISRULE(pParameter,parameter),"OResultSet::AddParameter: Argument ist kein Parameter");
     429             :     OSL_ENSURE(pParameter->count() > 0,"OResultSet: Fehler im Parse Tree");
     430             : #if OSL_DEBUG_LEVEL > 0
     431             :     OSQLParseNode * pMark = pParameter->getChild(0);
     432             :     OSL_UNUSED( pMark );
     433             : #endif
     434             : 
     435           0 :     OUString sParameterName;
     436             :     // set up Parameter-Column:
     437           0 :     sal_Int32 eType = DataType::VARCHAR;
     438           0 :     sal_uInt32 nPrecision = 255;
     439           0 :     sal_Int32 nScale = 0;
     440           0 :     sal_Int32 nNullable = ColumnValue::NULLABLE;
     441             : 
     442           0 :     if (_xCol.is())
     443             :     {
     444             :     // Use type, precision, scale ... from the given column,
     445             :     // because this Column will get a value assigned or
     446             :     // with this Column the value will be compared.
     447           0 :         _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))         >>= eType;
     448           0 :         _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))    >>= nPrecision;
     449           0 :         _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))        >>= nScale;
     450           0 :         _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))   >>= nNullable;
     451           0 :         _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))         >>= sParameterName;
     452             :     }
     453             : 
     454             :     Reference<XPropertySet> xParaColumn = new connectivity::parse::OParseColumn(sParameterName
     455             :                                                     ,OUString()
     456             :                                                     ,OUString()
     457             :                                                     ,OUString()
     458             :                                                     ,nNullable
     459             :                                                     ,nPrecision
     460             :                                                     ,nScale
     461             :                                                     ,eType
     462             :                                                     ,false
     463             :                                                     ,false
     464           0 :                                                     ,m_aSQLIterator.isCaseSensitive()
     465             :                                                     ,OUString()
     466             :                                                     ,OUString()
     467           0 :                                                     ,OUString());
     468           0 :     m_xParamColumns->get().push_back(xParaColumn);
     469           0 :     return m_xParamColumns->get().size();
     470             : }
     471             : 
     472           0 : void OPreparedStatement::describeColumn(OSQLParseNode* _pParameter,OSQLParseNode* _pNode,const OSQLTable& _xTable)
     473             : {
     474           0 :     Reference<XPropertySet> xProp;
     475           0 :     if(SQL_ISRULE(_pNode,column_ref))
     476             :     {
     477           0 :         OUString sColumnName,sTableRange;
     478           0 :         m_aSQLIterator.getColumnRange(_pNode,sColumnName,sTableRange);
     479           0 :         if ( !sColumnName.isEmpty() )
     480             :         {
     481           0 :             Reference<XNameAccess> xNameAccess = _xTable->getColumns();
     482           0 :             if(xNameAccess->hasByName(sColumnName))
     483           0 :                 xNameAccess->getByName(sColumnName) >>= xProp;
     484           0 :             AddParameter(_pParameter,xProp);
     485           0 :         }
     486           0 :     }
     487             :     //  else
     488             :         //  AddParameter(_pParameter,xProp);
     489           0 : }
     490             : 
     491           0 : void OPreparedStatement::describeParameter()
     492             : {
     493           0 :     ::std::vector< OSQLParseNode*> aParseNodes;
     494           0 :     scanParameter(m_pParseTree,aParseNodes);
     495           0 :     if ( !aParseNodes.empty() )
     496             :     {
     497             :         //  m_xParamColumns = new OSQLColumns();
     498           0 :         const OSQLTables& xTabs = m_aSQLIterator.getTables();
     499           0 :         if( !xTabs.empty() )
     500             :         {
     501           0 :             OSQLTable xTable = xTabs.begin()->second;
     502           0 :             ::std::vector< OSQLParseNode*>::const_iterator aIter = aParseNodes.begin();
     503           0 :             for (;aIter != aParseNodes.end();++aIter )
     504             :             {
     505           0 :                 describeColumn(*aIter,(*aIter)->getParent()->getChild(0),xTable);
     506           0 :             }
     507             :         }
     508           0 :     }
     509           0 : }
     510          46 : void OPreparedStatement::initializeResultSet(OResultSet* pRS)
     511             : {
     512          46 :     OStatement_Base::initializeResultSet(pRS);
     513             : 
     514          46 :     pRS->setParameterColumns(m_xParamColumns);
     515          46 :     pRS->setParameterRow(m_aParameterRow);
     516             : 
     517             :     // Substitute parameter (AssignValues and criteria):
     518          46 :     if (!m_xParamColumns->get().empty())
     519             :     {
     520             :         // begin with AssignValues
     521          12 :         sal_uInt16 nParaCount=0; // gives the current number of previously set Parameters
     522             : 
     523             :         // search for parameters to be substituted:
     524          12 :         size_t nCount = m_aAssignValues.is() ? m_aAssignValues->get().size() : 1; // 1 is important for the Criteria
     525          12 :         for (size_t j = 1; j < nCount; j++)
     526             :         {
     527           0 :             sal_uInt32 nParameter = (*m_aAssignValues).getParameterIndex(j);
     528           0 :             if (nParameter == SQL_NO_PARAMETER)
     529           0 :                 continue;   // this AssignValue is no Parameter
     530             : 
     531           0 :             ++nParaCount; // now the Parameter is valid
     532             :         }
     533             : 
     534          12 :         if (m_aParameterRow.is() &&  (m_xParamColumns->get().size()+1) != m_aParameterRow->get().size() )
     535             :         {
     536           0 :             sal_Int32 i = m_aParameterRow->get().size();
     537           0 :             sal_Int32 nParamColumns = m_xParamColumns->get().size()+1;
     538           0 :             m_aParameterRow->get().resize(nParamColumns);
     539           0 :             for ( ;i < nParamColumns; ++i )
     540             :             {
     541           0 :                 if ( !(m_aParameterRow->get())[i].is() )
     542           0 :                     (m_aParameterRow->get())[i] = new ORowSetValueDecorator;
     543             :             }
     544             :         }
     545          12 :         if (m_aParameterRow.is() && nParaCount < m_aParameterRow->get().size() )
     546          12 :             m_pSQLAnalyzer->bindParameterRow(m_aParameterRow);
     547             :     }
     548          46 : }
     549             : 
     550           0 : void OPreparedStatement::parseParamterElem(const OUString& _sColumnName, OSQLParseNode* pRow_Value_Constructor_Elem)
     551             : {
     552           0 :     Reference<XPropertySet> xCol;
     553           0 :     m_xColNames->getByName(_sColumnName) >>= xCol;
     554           0 :     sal_Int32 nParameter = -1;
     555           0 :     if(m_xParamColumns.is())
     556             :     {
     557           0 :         OSQLColumns::Vector::const_iterator aIter = find(m_xParamColumns->get().begin(),m_xParamColumns->get().end(),_sColumnName,::comphelper::UStringMixEqual(m_pTable->isCaseSensitive()));
     558           0 :         if(aIter != m_xParamColumns->get().end())
     559           0 :             nParameter = m_xParamColumns->get().size() - (m_xParamColumns->get().end() - aIter) + 1;// +1 because the rows start at 1
     560             :     }
     561           0 :     if(nParameter == -1)
     562           0 :         nParameter = AddParameter(pRow_Value_Constructor_Elem,xCol);
     563             :     // Save number of parameter in the variable:
     564           0 :     SetAssignValue(_sColumnName, OUString(), true, nParameter);
     565           0 : }
     566             : 
     567             : 
     568             : 
     569             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10