LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - FPreparedStatement.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 92 271 33.9 %
Date: 2012-08-25 Functions: 15 50 30.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 86 518 16.6 %

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

Generated by: LCOV version 1.10