LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - WrappedResultSet.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 52 104 50.0 %
Date: 2015-06-13 12:38:46 Functions: 12 17 70.6 %
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 "WrappedResultSet.hxx"
      21             : #include "core_resource.hxx"
      22             : #include "core_resource.hrc"
      23             : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
      24             : #include <connectivity/dbexception.hxx>
      25             : 
      26             : #include <limits>
      27             : 
      28             : using namespace dbaccess;
      29             : using namespace ::connectivity;
      30             : using namespace ::dbtools;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::beans;
      33             : using namespace ::com::sun::star::sdbc;
      34             : using namespace ::com::sun::star::sdbcx;
      35             : using namespace ::com::sun::star::container;
      36             : using namespace ::com::sun::star::lang;
      37             : using namespace ::osl;
      38             : 
      39          29 : void WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
      40             : {
      41          29 :     OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
      42          29 :     m_xUpd.set(_xDriverSet,UNO_QUERY_THROW);
      43          29 :     m_xRowLocate.set(_xDriverSet,UNO_QUERY_THROW);
      44          29 :     m_xUpdRow.set(_xDriverSet,UNO_QUERY_THROW);
      45          29 : }
      46             : 
      47           1 : void WrappedResultSet::reset(const Reference< XResultSet>& _xDriverSet)
      48             : {
      49           1 :     construct(_xDriverSet, m_sRowSetFilter);
      50           1 : }
      51             : 
      52         239 : Any SAL_CALL WrappedResultSet::getBookmark() throw(SQLException, RuntimeException)
      53             : {
      54         239 :     if ( m_xRowLocate.is() )
      55             :     {
      56         239 :         return m_xRowLocate->getBookmark( );
      57             :     }
      58           0 :     return makeAny(m_xDriverSet->getRow());
      59             : }
      60             : 
      61          12 : bool SAL_CALL WrappedResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
      62             : {
      63          12 :     return m_xRowLocate->moveToBookmark( bookmark );
      64             : }
      65             : 
      66           0 : bool SAL_CALL WrappedResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
      67             : {
      68           0 :     return m_xRowLocate->moveRelativeToBookmark( bookmark,rows );
      69             : }
      70             : 
      71         536 : sal_Int32 SAL_CALL WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
      72             : {
      73         536 :     return m_xRowLocate->compareBookmarks( _first,_second );
      74             : }
      75             : 
      76           1 : bool SAL_CALL WrappedResultSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
      77             : {
      78           1 :     return m_xRowLocate->hasOrderedBookmarks();
      79             : }
      80             : 
      81           2 : sal_Int32 SAL_CALL WrappedResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
      82             : {
      83           2 :     return m_xRowLocate->hashBookmark(bookmark);
      84             : }
      85             : 
      86             : // ::com::sun::star::sdbcx::XDeleteRows
      87           0 : Sequence< sal_Int32 > SAL_CALL WrappedResultSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
      88             : {
      89           0 :     Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
      90           0 :     if(xDeleteRow.is())
      91             :     {
      92           0 :         return xDeleteRow->deleteRows(rows);
      93             :     }
      94           0 :     return Sequence< sal_Int32 >();
      95             : }
      96             : 
      97           1 : void SAL_CALL WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
      98             : {
      99           1 :     m_xUpd->moveToInsertRow();
     100           1 :     sal_Int32 i = 1;
     101           1 :     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
     102          32 :     for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
     103             :     {
     104          31 :         aIter->setSigned(m_aSignedFlags[i-1]);
     105          31 :         updateColumn(i,m_xUpdRow,*aIter);
     106             :     }
     107           1 :     m_xUpd->insertRow();
     108           1 :     (*_rInsertRow->get().begin()) = getBookmark();
     109           1 : }
     110             : 
     111           4 : void SAL_CALL WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
     112             : {
     113           4 :     sal_Int32 i = 1;
     114           4 :     connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->get().begin()+1;
     115           4 :     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
     116          28 :     for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
     117             :     {
     118          24 :         aIter->setSigned(aOrgIter->isSigned());
     119          24 :         updateColumn(i,m_xUpdRow,*aIter);
     120             :     }
     121           4 :     m_xUpd->updateRow();
     122           4 : }
     123             : 
     124           1 : void SAL_CALL WrappedResultSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
     125             : {
     126           1 :     m_xUpd->deleteRow();
     127           1 : }
     128             : 
     129           0 : void SAL_CALL WrappedResultSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
     130             : {
     131           0 :     m_xUpd->cancelRowUpdates();
     132           0 : }
     133             : 
     134           0 : void SAL_CALL WrappedResultSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
     135             : {
     136           0 :     m_xUpd->moveToInsertRow();
     137           0 : }
     138             : 
     139           0 : void SAL_CALL WrappedResultSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
     140             : {
     141           0 :     m_xUpd->moveToCurrentRow();
     142           0 : }
     143             : 
     144         238 : void WrappedResultSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
     145             : {
     146         238 :     OCacheSet::fillValueRow(_rRow,_nPosition);
     147         238 : }
     148             : 
     149          55 : void WrappedResultSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
     150             : {
     151          55 :     if(_rValue.isBound() && _rValue.isModified())
     152             :     {
     153           5 :         if(_rValue.isNull())
     154           0 :             _xParameter->updateNull(nPos);
     155             :         else
     156             :         {
     157             : 
     158           5 :             switch(_rValue.getTypeKind())
     159             :             {
     160             :                 case DataType::DECIMAL:
     161             :                 case DataType::NUMERIC:
     162           0 :                     _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
     163           0 :                     break;
     164             :                 case DataType::CHAR:
     165             :                 case DataType::VARCHAR:
     166           5 :                     _xParameter->updateString(nPos,_rValue);
     167           5 :                     break;
     168             :                 case DataType::BIGINT:
     169           0 :                     if ( _rValue.isSigned() )
     170           0 :                         _xParameter->updateLong(nPos,_rValue);
     171             :                     else
     172           0 :                         _xParameter->updateString(nPos,_rValue);
     173           0 :                     break;
     174             :                 case DataType::BIT:
     175             :                 case DataType::BOOLEAN:
     176           0 :                     _xParameter->updateBoolean(nPos,static_cast<bool>(_rValue));
     177           0 :                     break;
     178             :                 case DataType::TINYINT:
     179           0 :                     if ( _rValue.isSigned() )
     180           0 :                         _xParameter->updateByte(nPos,_rValue);
     181             :                     else
     182           0 :                         _xParameter->updateShort(nPos,_rValue);
     183           0 :                     break;
     184             :                 case DataType::SMALLINT:
     185           0 :                     if ( _rValue.isSigned() )
     186           0 :                         _xParameter->updateShort(nPos,_rValue);
     187             :                     else
     188           0 :                         _xParameter->updateInt(nPos,_rValue);
     189           0 :                     break;
     190             :                 case DataType::INTEGER:
     191           0 :                     if ( _rValue.isSigned() )
     192           0 :                         _xParameter->updateInt(nPos,_rValue);
     193             :                     else
     194           0 :                         _xParameter->updateLong(nPos,_rValue);
     195           0 :                     break;
     196             :                 case DataType::FLOAT:
     197           0 :                     _xParameter->updateFloat(nPos,_rValue);
     198           0 :                     break;
     199             :                 case DataType::DOUBLE:
     200             :                 case DataType::REAL:
     201           0 :                     _xParameter->updateDouble(nPos,_rValue);
     202           0 :                     break;
     203             :                 case DataType::DATE:
     204           0 :                     _xParameter->updateDate(nPos,_rValue);
     205           0 :                     break;
     206             :                 case DataType::TIME:
     207           0 :                     _xParameter->updateTime(nPos,_rValue);
     208           0 :                     break;
     209             :                 case DataType::TIMESTAMP:
     210           0 :                     _xParameter->updateTimestamp(nPos,_rValue);
     211           0 :                     break;
     212             :                 case DataType::BINARY:
     213             :                 case DataType::VARBINARY:
     214             :                 case DataType::LONGVARBINARY:
     215           0 :                     _xParameter->updateBytes(nPos,_rValue);
     216           0 :                     break;
     217             :                 case DataType::BLOB:
     218             :                 case DataType::CLOB:
     219           0 :                     _xParameter->updateObject(nPos,_rValue.getAny());
     220           0 :                     break;
     221             :             }
     222             :         }
     223             :     }
     224          55 : }
     225             : 
     226             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11