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

Generated by: LCOV version 1.10