LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - WrappedResultSet.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 52 104 50.0 %
Date: 2014-11-03 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          46 : void WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
      40             : {
      41          46 :     OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
      42          46 :     m_xUpd.set(_xDriverSet,UNO_QUERY_THROW);
      43          46 :     m_xRowLocate.set(_xDriverSet,UNO_QUERY_THROW);
      44          46 :     m_xUpdRow.set(_xDriverSet,UNO_QUERY_THROW);
      45          46 : }
      46             : 
      47           2 : void WrappedResultSet::reset(const Reference< XResultSet>& _xDriverSet)
      48             : {
      49           2 :     construct(_xDriverSet, m_sRowSetFilter);
      50           2 : }
      51             : 
      52         358 : Any SAL_CALL WrappedResultSet::getBookmark() throw(SQLException, RuntimeException)
      53             : {
      54         358 :     if ( m_xRowLocate.is() )
      55             :     {
      56         358 :         return m_xRowLocate->getBookmark( );
      57             :     }
      58           0 :     return makeAny(m_xDriverSet->getRow());
      59             : }
      60             : 
      61          32 : bool SAL_CALL WrappedResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
      62             : {
      63          32 :     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         286 : sal_Int32 SAL_CALL WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
      72             : {
      73         286 :     return m_xRowLocate->compareBookmarks( _first,_second );
      74             : }
      75             : 
      76           2 : bool SAL_CALL WrappedResultSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
      77             : {
      78           2 :     return m_xRowLocate->hasOrderedBookmarks();
      79             : }
      80             : 
      81           4 : sal_Int32 SAL_CALL WrappedResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
      82             : {
      83           4 :     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           2 : void SAL_CALL WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
      98             : {
      99           2 :     m_xUpd->moveToInsertRow();
     100           2 :     sal_Int32 i = 1;
     101           2 :     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
     102          64 :     for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
     103             :     {
     104          62 :         aIter->setSigned(m_aSignedFlags[i-1]);
     105          62 :         updateColumn(i,m_xUpdRow,*aIter);
     106             :     }
     107           2 :     m_xUpd->insertRow();
     108           2 :     (*_rInsertRow->get().begin()) = getBookmark();
     109           2 : }
     110             : 
     111           8 : void SAL_CALL WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
     112             : {
     113           8 :     sal_Int32 i = 1;
     114           8 :     connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->get().begin()+1;
     115           8 :     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
     116          56 :     for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
     117             :     {
     118          48 :         aIter->setSigned(aOrgIter->isSigned());
     119          48 :         updateColumn(i,m_xUpdRow,*aIter);
     120             :     }
     121           8 :     m_xUpd->updateRow();
     122           8 : }
     123             : 
     124           2 : void SAL_CALL WrappedResultSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
     125             : {
     126           2 :     m_xUpd->deleteRow();
     127           2 : }
     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         356 : void WrappedResultSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
     145             : {
     146         356 :     OCacheSet::fillValueRow(_rRow,_nPosition);
     147         356 : }
     148             : 
     149         110 : void WrappedResultSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
     150             : {
     151         110 :     if(_rValue.isBound() && _rValue.isModified())
     152             :     {
     153          10 :         if(_rValue.isNull())
     154           0 :             _xParameter->updateNull(nPos);
     155             :         else
     156             :         {
     157             : 
     158          10 :             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          10 :                     _xParameter->updateString(nPos,_rValue);
     167          10 :                     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         110 : }
     225             : 
     226             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10