LCOV - code coverage report
Current view: top level - connectivity/source/drivers/postgresql - pq_baseresultset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 305 0.0 %
Date: 2012-08-25 Functions: 0 55 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  *  Effective License of whole file:
       5                 :            :  *
       6                 :            :  *    This library is free software; you can redistribute it and/or
       7                 :            :  *    modify it under the terms of the GNU Lesser General Public
       8                 :            :  *    License version 2.1, as published by the Free Software Foundation.
       9                 :            :  *
      10                 :            :  *    This library is distributed in the hope that it will be useful,
      11                 :            :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13                 :            :  *    Lesser General Public License for more details.
      14                 :            :  *
      15                 :            :  *    You should have received a copy of the GNU Lesser General Public
      16                 :            :  *    License along with this library; if not, write to the Free Software
      17                 :            :  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      18                 :            :  *    MA  02111-1307  USA
      19                 :            :  *
      20                 :            :  *  Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
      21                 :            :  *
      22                 :            :  *    The Contents of this file are made available subject to the terms of
      23                 :            :  *    the GNU Lesser General Public License Version 2.1
      24                 :            :  *
      25                 :            :  *    Copyright: 2000 by Sun Microsystems, Inc.
      26                 :            :  *
      27                 :            :  *    Contributor(s): Joerg Budischewski
      28                 :            :  *
      29                 :            :  *  All parts contributed on or after August 2011:
      30                 :            :  *
      31                 :            :  *    Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
      32                 :            :  *
      33                 :            :  *    The contents of this file are subject to the Mozilla Public License Version
      34                 :            :  *    1.1 (the "License"); you may not use this file except in compliance with
      35                 :            :  *    the License or as specified alternatively below. You may obtain a copy of
      36                 :            :  *    the License at http://www.mozilla.org/MPL/
      37                 :            :  *
      38                 :            :  *    Software distributed under the License is distributed on an "AS IS" basis,
      39                 :            :  *    WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      40                 :            :  *    for the specific language governing rights and limitations under the
      41                 :            :  *    License.
      42                 :            :  *
      43                 :            :  *    Major Contributor(s):
      44                 :            :  *    [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
      45                 :            :  *
      46                 :            :  *    All Rights Reserved.
      47                 :            :  *
      48                 :            :  *    For minor contributions see the git repository.
      49                 :            :  *
      50                 :            :  *    Alternatively, the contents of this file may be used under the terms of
      51                 :            :  *    either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      52                 :            :  *    the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
      53                 :            :  *    in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
      54                 :            :  *    instead of those above.
      55                 :            :  *
      56                 :            :  ************************************************************************/
      57                 :            : 
      58                 :            : #include <osl/thread.h>
      59                 :            : 
      60                 :            : #include <rtl/ustrbuf.hxx>
      61                 :            : 
      62                 :            : #include <cppuhelper/typeprovider.hxx>
      63                 :            : #include <cppuhelper/queryinterface.hxx>
      64                 :            : 
      65                 :            : #include "pq_tools.hxx"
      66                 :            : #include "pq_array.hxx"
      67                 :            : #include "pq_statement.hxx"
      68                 :            : #include "pq_baseresultset.hxx"
      69                 :            : #include "pq_resultsetmetadata.hxx"
      70                 :            : 
      71                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      72                 :            : 
      73                 :            : using osl::Mutex;
      74                 :            : using osl::MutexGuard;
      75                 :            : 
      76                 :            : using rtl::OUString;
      77                 :            : using rtl::OUStringToOString;
      78                 :            : using rtl::OUStringBuffer;
      79                 :            : using rtl::OString;
      80                 :            : 
      81                 :            : using com::sun::star::beans::XPropertySetInfo;
      82                 :            : using com::sun::star::beans::XPropertySet;
      83                 :            : using com::sun::star::beans::XMultiPropertySet;
      84                 :            : using com::sun::star::beans::XFastPropertySet;
      85                 :            : 
      86                 :            : using com::sun::star::uno::Any;
      87                 :            : using com::sun::star::uno::makeAny;
      88                 :            : using com::sun::star::uno::Type;
      89                 :            : using com::sun::star::uno::RuntimeException;
      90                 :            : using com::sun::star::uno::Exception;
      91                 :            : using com::sun::star::uno::Sequence;
      92                 :            : using com::sun::star::uno::Reference;
      93                 :            : using com::sun::star::uno::XInterface;
      94                 :            : 
      95                 :            : using com::sun::star::lang::IllegalArgumentException;
      96                 :            : 
      97                 :            : using com::sun::star::sdbc::XWarningsSupplier;
      98                 :            : using com::sun::star::sdbc::XCloseable;
      99                 :            : using com::sun::star::sdbc::XStatement;
     100                 :            : using com::sun::star::sdbc::XResultSet;
     101                 :            : using com::sun::star::sdbc::XConnection;
     102                 :            : using com::sun::star::sdbc::SQLException;
     103                 :            : using com::sun::star::sdbc::XRow;
     104                 :            : using com::sun::star::sdbc::XColumnLocate;
     105                 :            : using com::sun::star::sdbc::XResultSetMetaData;
     106                 :            : using com::sun::star::sdbc::XResultSetMetaDataSupplier;
     107                 :            : 
     108                 :            : 
     109                 :            : using com::sun::star::beans::Property;
     110                 :            : 
     111                 :            : namespace pq_sdbc_driver
     112                 :            : {
     113                 :          0 : static ::cppu::IPropertyArrayHelper & getResultSetPropertyArrayHelper()
     114                 :            : {
     115                 :            :     static ::cppu::IPropertyArrayHelper *pArrayHelper;
     116                 :          0 :     if( ! pArrayHelper )
     117                 :            :     {
     118                 :          0 :         MutexGuard guard( Mutex::getGlobalMutex() );
     119                 :          0 :         if( ! pArrayHelper )
     120                 :            :         {
     121                 :            :             static Property aTable[] =
     122                 :            :                 {
     123                 :            :                     // LEM TODO: this needs to be kept in sync with other, e.g. pq_statics.css:508
     124                 :            :                     // Should really share!
     125                 :            :                     // At least use for the handles the #define'd values in .hxx file...
     126                 :            :                     Property(
     127                 :            :                         OUString( RTL_CONSTASCII_USTRINGPARAM("CursorName") ), 0,
     128                 :          0 :                         ::getCppuType( (OUString *)0) , 0 ),
     129                 :            :                     Property(
     130                 :            :                         OUString( RTL_CONSTASCII_USTRINGPARAM("EscapeProcessing") ), 1,
     131                 :          0 :                         ::getBooleanCppuType() , 0 ),
     132                 :            :                     Property(
     133                 :            :                         OUString( RTL_CONSTASCII_USTRINGPARAM("FetchDirection") ), 2,
     134                 :          0 :                         ::getCppuType( (sal_Int32 *)0) , 0 ),
     135                 :            :                     Property(
     136                 :            :                         OUString( RTL_CONSTASCII_USTRINGPARAM("FetchSize") ), 3,
     137                 :          0 :                         ::getCppuType( (sal_Int32 *)0) , 0 ),
     138                 :            :                     Property(
     139                 :            :                         OUString( RTL_CONSTASCII_USTRINGPARAM("IsBookmarkable") ), 4,
     140                 :          0 :                         ::getBooleanCppuType() , 0 ),
     141                 :            :                     Property(
     142                 :            :                         OUString( RTL_CONSTASCII_USTRINGPARAM("ResultSetConcurrency") ), 5,
     143                 :          0 :                         ::getCppuType( (sal_Int32 *)0) , 0 ),
     144                 :            :                     Property(
     145                 :            :                         OUString( RTL_CONSTASCII_USTRINGPARAM("ResultSetType") ), 6,
     146                 :          0 :                         ::getCppuType( (sal_Int32 *)0) , 0 )
     147                 :          0 :                 };
     148                 :            :             OSL_ASSERT( sizeof(aTable) / sizeof(Property) == BASERESULTSET_SIZE );
     149                 :          0 :             static ::cppu::OPropertyArrayHelper arrayHelper( aTable, BASERESULTSET_SIZE, sal_True );
     150                 :          0 :             pArrayHelper = &arrayHelper;
     151                 :          0 :         }
     152                 :            :     }
     153                 :          0 :     return *pArrayHelper;
     154                 :            : }
     155                 :            : 
     156                 :          0 : BaseResultSet::BaseResultSet(
     157                 :            :     const ::rtl::Reference< RefCountedMutex > & refMutex,
     158                 :            :     const Reference< XInterface > & owner,
     159                 :            :     sal_Int32 rowCount,
     160                 :            :     sal_Int32 colCount,
     161                 :            :     const Reference< com::sun::star::script::XTypeConverter > & tc )
     162                 :          0 :     : OComponentHelper( refMutex->mutex ),
     163                 :            :       OPropertySetHelper( OComponentHelper::rBHelper ),
     164                 :            :       m_owner( owner ),
     165                 :            :       m_tc( tc ),
     166                 :            :       m_refMutex( refMutex ),
     167                 :            :       m_row( -1 ),
     168                 :            :       m_rowCount( rowCount ),
     169                 :          0 :       m_fieldCount( colCount )
     170                 :            : {
     171                 :            :     POSTGRE_TRACE( "ctor BaseResultSet" );
     172                 :          0 : }
     173                 :            : 
     174                 :            : // LEM TODO: refMutex->mutex should live longer than OComponentHelper,
     175                 :            : // but calling OComponentHelper::dispose explicitly here calls
     176                 :            : // BaseResultSet::~BaseResultSet in an infinite loop :(
     177                 :          0 : BaseResultSet::~BaseResultSet()
     178                 :            : {
     179                 :            :     POSTGRE_TRACE( "dtor BaseResultSet" );
     180                 :          0 : }
     181                 :            : 
     182                 :          0 : Any BaseResultSet::queryInterface( const Type & reqType ) throw (RuntimeException)
     183                 :            : {
     184                 :          0 :     Any ret;
     185                 :            : 
     186                 :          0 :     ret = OComponentHelper::queryInterface( reqType );
     187                 :          0 :     if( ! ret.hasValue() )
     188                 :            :         ret = ::cppu::queryInterface( reqType,
     189                 :            :                                     static_cast< XResultSet * > ( this  ),
     190                 :            :                                     static_cast< XResultSetMetaDataSupplier * > ( this ),
     191                 :            :                                     static_cast< XRow * > ( this ),
     192                 :            :                                     static_cast< XColumnLocate * > ( this ),
     193                 :            :                                     static_cast< XCloseable * > ( this ),
     194                 :            :                                     static_cast< XPropertySet * > ( this ),
     195                 :            :                                     static_cast< XMultiPropertySet * > ( this ),
     196                 :          0 :                                     static_cast< XFastPropertySet * > ( this ) );
     197                 :          0 :     return ret;
     198                 :            : }
     199                 :            : 
     200                 :            : // void BaseResultSet::close(  ) throw (SQLException, RuntimeException)
     201                 :            : // {
     202                 :            : //     Reference< XInterface > owner;
     203                 :            : //     {
     204                 :            : //         ResultSetGuard guard(*this);
     205                 :            : //         if( m_result )
     206                 :            : //         {
     207                 :            : //             PQclear(m_result );
     208                 :            : //             m_result = 0;
     209                 :            : //             m_row = -1;
     210                 :            : //         }
     211                 :            : //         owner = m_owner;
     212                 :            : //         m_owner.clear();
     213                 :            : //     }
     214                 :            : // }
     215                 :            : 
     216                 :          0 : Sequence<Type > BaseResultSet::getTypes() throw( RuntimeException )
     217                 :            : {
     218                 :            :     static cppu::OTypeCollection *pCollection;
     219                 :          0 :     if( ! pCollection )
     220                 :            :     {
     221                 :          0 :         MutexGuard guard( osl::Mutex::getGlobalMutex() );
     222                 :          0 :         if( !pCollection )
     223                 :            :         {
     224                 :            :             static cppu::OTypeCollection collection(
     225                 :          0 :                 getCppuType( (Reference< XResultSet> *) 0 ),
     226                 :          0 :                 getCppuType( (Reference< XResultSetMetaDataSupplier> *) 0 ),
     227                 :          0 :                 getCppuType( (Reference< XRow> *) 0 ),
     228                 :          0 :                 getCppuType( (Reference< XColumnLocate> *) 0 ),
     229                 :          0 :                 getCppuType( (Reference< XCloseable> *) 0 ),
     230                 :          0 :                 getCppuType( (Reference< XPropertySet >*) 0 ),
     231                 :          0 :                 getCppuType( (Reference< XFastPropertySet > *) 0 ),
     232                 :          0 :                 getCppuType( (Reference< XMultiPropertySet > *) 0 ),
     233                 :          0 :                 OComponentHelper::getTypes());
     234                 :          0 :             pCollection = &collection;
     235                 :          0 :         }
     236                 :            :     }
     237                 :          0 :     return pCollection->getTypes();
     238                 :            : }
     239                 :            : 
     240                 :          0 : Sequence< sal_Int8> BaseResultSet::getImplementationId() throw( RuntimeException )
     241                 :            : {
     242                 :            :     static cppu::OImplementationId *pId;
     243                 :          0 :     if( ! pId )
     244                 :            :     {
     245                 :          0 :         MutexGuard guard( osl::Mutex::getGlobalMutex() );
     246                 :          0 :         if( ! pId )
     247                 :            :         {
     248                 :          0 :             static cppu::OImplementationId id(sal_False);
     249                 :          0 :             pId = &id;
     250                 :          0 :         }
     251                 :            :     }
     252                 :          0 :     return pId->getImplementationId();
     253                 :            : }
     254                 :            : 
     255                 :            : // Reference< XResultSetMetaData > BaseResultSet::getMetaData(  ) throw (SQLException, RuntimeException)
     256                 :            : // {
     257                 :            : //     ResultSetGuard guard(*this);
     258                 :            : //     checkClosed();
     259                 :            : //     return new ResultSetMetaData( m_refMutex, this, &m_result );
     260                 :            : // }
     261                 :            : 
     262                 :          0 : sal_Bool BaseResultSet::next(  ) throw (SQLException, RuntimeException)
     263                 :            : {
     264                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     265                 :          0 :     checkClosed();
     266                 :          0 :     m_row ++;
     267                 :          0 :     return m_row < m_rowCount;
     268                 :            : }
     269                 :            : 
     270                 :          0 : sal_Bool BaseResultSet::isBeforeFirst(  ) throw (SQLException, RuntimeException)
     271                 :            : {
     272                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     273                 :          0 :     checkClosed();
     274                 :          0 :     return m_row == -1;
     275                 :            : }
     276                 :            : 
     277                 :          0 : sal_Bool BaseResultSet::isAfterLast(  ) throw (SQLException, RuntimeException)
     278                 :            : {
     279                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     280                 :          0 :     checkClosed();
     281                 :          0 :     return m_row >= m_rowCount;
     282                 :            : }
     283                 :            : 
     284                 :          0 : sal_Bool BaseResultSet::isFirst(  ) throw (SQLException, RuntimeException)
     285                 :            : {
     286                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     287                 :          0 :     checkClosed();
     288                 :          0 :     return m_row == 0 && m_rowCount;
     289                 :            : }
     290                 :            : 
     291                 :          0 : sal_Bool BaseResultSet::isLast(  ) throw (SQLException, RuntimeException)
     292                 :            : {
     293                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     294                 :          0 :     checkClosed();
     295                 :          0 :     return m_row >= 0 && m_row + 1 == m_rowCount;
     296                 :            : }
     297                 :            : 
     298                 :          0 : void BaseResultSet::beforeFirst(  ) throw (SQLException, RuntimeException)
     299                 :            : {
     300                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     301                 :          0 :     checkClosed();
     302                 :          0 :     m_row = -1;
     303                 :          0 : }
     304                 :            : 
     305                 :          0 : void BaseResultSet::afterLast(  ) throw (SQLException, RuntimeException)
     306                 :            : {
     307                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     308                 :          0 :     checkClosed();
     309                 :          0 :     m_row = m_rowCount;
     310                 :          0 : }
     311                 :            : 
     312                 :          0 : sal_Bool BaseResultSet::first(  ) throw (SQLException, RuntimeException)
     313                 :            : {
     314                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     315                 :          0 :     checkClosed();
     316                 :          0 :     sal_Bool bRet = ( m_rowCount > 0 );
     317                 :          0 :     if( bRet )
     318                 :          0 :         m_row = 0;
     319                 :          0 :     return bRet;
     320                 :            : }
     321                 :            : 
     322                 :          0 : sal_Bool BaseResultSet::last(  ) throw (SQLException, RuntimeException)
     323                 :            : {
     324                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     325                 :          0 :     checkClosed();
     326                 :          0 :     sal_Bool bRet = ( m_rowCount > 0 );
     327                 :          0 :     if( bRet )
     328                 :          0 :         m_row = m_rowCount -1;
     329                 :          0 :     return bRet;
     330                 :            : }
     331                 :            : 
     332                 :          0 : sal_Int32 BaseResultSet::getRow(  ) throw (SQLException, RuntimeException)
     333                 :            : {
     334                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     335                 :          0 :     checkClosed();
     336                 :          0 :     return m_row +1;
     337                 :            : }
     338                 :            : 
     339                 :          0 : sal_Bool BaseResultSet::absolute( sal_Int32 row ) throw (SQLException, RuntimeException)
     340                 :            : {
     341                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     342                 :          0 :     checkClosed();
     343                 :          0 :     if( row > 0 )
     344                 :            :     {
     345                 :          0 :         m_row = row -1;
     346                 :          0 :         if( m_row > m_rowCount )
     347                 :          0 :             m_row = m_rowCount;
     348                 :            :     }
     349                 :            :     else
     350                 :            :     {
     351                 :          0 :         m_row = m_rowCount + row;
     352                 :          0 :         if( m_row < -1 )
     353                 :          0 :             m_row = -1;
     354                 :            :     }
     355                 :          0 :     return sal_True;
     356                 :            : }
     357                 :            : 
     358                 :          0 : sal_Bool BaseResultSet::relative( sal_Int32 rows ) throw (SQLException, RuntimeException)
     359                 :            : {
     360                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     361                 :          0 :     checkClosed();
     362                 :          0 :     m_row += rows;
     363                 :            : 
     364                 :          0 :     if( m_row > m_rowCount )
     365                 :          0 :         m_row = m_rowCount;
     366                 :          0 :     else if ( m_row < -1 )
     367                 :          0 :         m_row = -1;
     368                 :          0 :     return sal_True;
     369                 :            : }
     370                 :            : 
     371                 :          0 : sal_Bool BaseResultSet::previous(  ) throw (SQLException, RuntimeException)
     372                 :            : {
     373                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     374                 :          0 :     checkClosed();
     375                 :          0 :     sal_Bool bRet = ( m_row != -1 );
     376                 :          0 :     if( bRet )
     377                 :          0 :         m_row --;
     378                 :          0 :     return bRet;
     379                 :            : }
     380                 :            : 
     381                 :          0 : void BaseResultSet::refreshRow(  ) throw (SQLException, RuntimeException)
     382                 :            : {
     383                 :            :     // TODO: not supported for now
     384                 :          0 : }
     385                 :            : 
     386                 :          0 : sal_Bool BaseResultSet::rowUpdated(  ) throw (SQLException, RuntimeException)
     387                 :            : {
     388                 :          0 :     return sal_False;
     389                 :            : }
     390                 :            : 
     391                 :          0 : sal_Bool BaseResultSet::rowInserted(  ) throw (SQLException, RuntimeException)
     392                 :            : {
     393                 :          0 :     return sal_False;
     394                 :            : }
     395                 :            : 
     396                 :          0 : sal_Bool BaseResultSet::rowDeleted(  ) throw (SQLException, RuntimeException)
     397                 :            : {
     398                 :          0 :     return sal_False;
     399                 :            : }
     400                 :            : 
     401                 :          0 : Reference< XInterface > BaseResultSet::getStatement() throw (SQLException, RuntimeException)
     402                 :            : {
     403                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     404                 :          0 :     checkClosed();
     405                 :          0 :     return m_owner;
     406                 :            : }
     407                 :            : 
     408                 :            : 
     409                 :            : //----------------- XRow interface ----------------------------------------------------
     410                 :            : 
     411                 :          0 : sal_Bool BaseResultSet::wasNull(  ) throw (SQLException, RuntimeException)
     412                 :            : {
     413                 :          0 :     return m_wasNull;
     414                 :            : }
     415                 :            : 
     416                 :          0 : Any BaseResultSet::convertTo( const Any & val , const Type & type )
     417                 :            : {
     418                 :          0 :     Any aRet;
     419                 :            :     try
     420                 :            :     {
     421                 :          0 :         aRet = m_tc->convertTo( val , type );
     422                 :            :     }
     423                 :          0 :     catch( com::sun::star::lang::IllegalArgumentException & )
     424                 :            :     {}
     425                 :          0 :     catch( com::sun::star::script::CannotConvertException & )
     426                 :            :     {}
     427                 :          0 :     return aRet;
     428                 :            : }
     429                 :            : 
     430                 :          0 : sal_Bool BaseResultSet::getBoolean( sal_Int32 columnIndex ) throw (SQLException, RuntimeException)
     431                 :            : {
     432                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     433                 :          0 :     checkClosed();
     434                 :          0 :     checkColumnIndex( columnIndex );
     435                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     436                 :            : 
     437                 :          0 :     OUString str = getString( columnIndex );
     438                 :            : 
     439                 :          0 :     if( str.getLength() > 0 )
     440                 :            :     {
     441                 :          0 :         switch(str[0])
     442                 :            :         {
     443                 :            :         case '1':
     444                 :            :         case 't':
     445                 :            :         case 'T':
     446                 :            :         case 'y':
     447                 :            :         case 'Y':
     448                 :            : 
     449                 :          0 :             return sal_True;
     450                 :            :         }
     451                 :            :     }
     452                 :          0 :     return sal_False;
     453                 :            : }
     454                 :            : 
     455                 :          0 : sal_Int8 BaseResultSet::getByte( sal_Int32 columnIndex )
     456                 :            :         throw (SQLException, RuntimeException)
     457                 :            : {
     458                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     459                 :          0 :     checkClosed();
     460                 :          0 :     checkColumnIndex( columnIndex );
     461                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     462                 :          0 :     sal_Int8 b = 0;
     463                 :          0 :     convertTo( getValue( columnIndex ), getCppuType( &b )) >>= b;
     464                 :          0 :     return b;
     465                 :            : }
     466                 :            : 
     467                 :          0 : sal_Int16 BaseResultSet::getShort( sal_Int32 columnIndex )
     468                 :            :         throw (SQLException, RuntimeException)
     469                 :            : {
     470                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     471                 :          0 :     checkClosed();
     472                 :          0 :     checkColumnIndex( columnIndex );
     473                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     474                 :          0 :     sal_Int16 i = 0;
     475                 :          0 :     convertTo( getValue( columnIndex ), getCppuType( &i )) >>= i;
     476                 :          0 :     return i;
     477                 :            : }
     478                 :            : 
     479                 :          0 : OUString BaseResultSet::getString( sal_Int32 columnIndex ) throw (SQLException, RuntimeException)
     480                 :            : {
     481                 :          0 :     MutexGuard guard(m_refMutex->mutex);
     482                 :          0 :     checkClosed();
     483                 :          0 :     checkColumnIndex( columnIndex );
     484                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     485                 :          0 :     OUString ret;
     486                 :          0 :     convertTo( getValue(  columnIndex ), getCppuType( &ret ) ) >>= ret;
     487                 :            : //     printf( "BaseResultSet::getString() %s\n" , OUStringToOString( ret, RTL_TEXTENCODING_ASCII_US ).getStr() );
     488                 :          0 :     return ret;
     489                 :            : }
     490                 :            : 
     491                 :          0 : sal_Int32 BaseResultSet::getInt( sal_Int32 columnIndex )
     492                 :            :         throw (SQLException, RuntimeException)
     493                 :            : {
     494                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     495                 :          0 :     checkClosed();
     496                 :          0 :     checkColumnIndex( columnIndex );
     497                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     498                 :          0 :     sal_Int32 i = 0;
     499                 :          0 :     convertTo( getValue( columnIndex ), getCppuType( &i )) >>= i;
     500                 :          0 :     return i;
     501                 :            : }
     502                 :            : 
     503                 :          0 : sal_Int64 BaseResultSet::getLong( sal_Int32 columnIndex )
     504                 :            :         throw (SQLException, RuntimeException)
     505                 :            : {
     506                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     507                 :          0 :     checkClosed();
     508                 :          0 :     checkColumnIndex( columnIndex );
     509                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     510                 :          0 :     sal_Int64 i = 0;
     511                 :          0 :     convertTo( getValue( columnIndex ), getCppuType( &i )) >>= i;
     512                 :          0 :     return i;
     513                 :            : }
     514                 :            : 
     515                 :          0 : float BaseResultSet::getFloat( sal_Int32 columnIndex )
     516                 :            :         throw (SQLException, RuntimeException)
     517                 :            : {
     518                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     519                 :          0 :     checkClosed();
     520                 :          0 :     checkColumnIndex( columnIndex );
     521                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     522                 :          0 :     float f = 0.;
     523                 :          0 :     convertTo( getValue( columnIndex ), getCppuType( &f )) >>= f;
     524                 :          0 :     return f;
     525                 :            : }
     526                 :            : 
     527                 :          0 : double BaseResultSet::getDouble( sal_Int32 columnIndex )
     528                 :            :         throw (SQLException, RuntimeException)
     529                 :            : {
     530                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     531                 :          0 :     checkClosed();
     532                 :          0 :     checkColumnIndex( columnIndex );
     533                 :          0 :     double d = 0.;
     534                 :          0 :     convertTo( getValue( columnIndex ), getCppuType( &d )) >>= d;
     535                 :          0 :     return d;
     536                 :            : }
     537                 :            : 
     538                 :          0 : Sequence< sal_Int8 > BaseResultSet::getBytes( sal_Int32 columnIndex )
     539                 :            :         throw (SQLException, RuntimeException)
     540                 :            : {
     541                 :          0 :     MutexGuard guard( m_refMutex->mutex );
     542                 :          0 :     checkClosed();
     543                 :          0 :     checkColumnIndex( columnIndex );
     544                 :          0 :     checkRowIndex( sal_True /* must be on row */ );
     545                 :            : 
     546                 :          0 :     Sequence< sal_Int8 > ret;
     547                 :          0 :     OUString ustr;
     548                 :          0 :     if( ! (getValue( columnIndex ) >>= ustr) )
     549                 :          0 :         m_wasNull = true;
     550                 :            :     else
     551                 :            :     {
     552                 :            :         // if this is a binary, it must contain escaped data !
     553                 :          0 :         OString val = rtl::OUStringToOString( ustr, RTL_TEXTENCODING_ASCII_US );
     554                 :            : 
     555                 :            :         size_t length;
     556                 :          0 :         char * res = (char*) PQunescapeBytea( (unsigned char *)val.getStr() , &length);
     557                 :          0 :         ret = Sequence< sal_Int8 > ( (sal_Int8*)res, length );
     558                 :          0 :         if( res )
     559                 :          0 :             free( res );
     560                 :            :     }
     561                 :          0 :     return ret;
     562                 :            : }
     563                 :            : 
     564                 :            : 
     565                 :          0 : ::com::sun::star::util::Date BaseResultSet::getDate( sal_Int32 columnIndex )
     566                 :            :         throw (SQLException, RuntimeException)
     567                 :            : {
     568                 :          0 :     return string2Date( getString( columnIndex ) );
     569                 :            : }
     570                 :            : 
     571                 :          0 : ::com::sun::star::util::Time BaseResultSet::getTime( sal_Int32 columnIndex )
     572                 :            :         throw (SQLException, RuntimeException)
     573                 :            : {
     574                 :          0 :     return string2Time( getString( columnIndex ) );
     575                 :            : }
     576                 :            : 
     577                 :          0 : ::com::sun::star::util::DateTime BaseResultSet::getTimestamp( sal_Int32 columnIndex )
     578                 :            :         throw (SQLException, RuntimeException)
     579                 :            : {
     580                 :          0 :     return string2DateTime( getString( columnIndex ) );
     581                 :            : }
     582                 :            : 
     583                 :            :   // LEM TODO: these look like they are missing an actual implementation
     584                 :          0 : Reference< ::com::sun::star::io::XInputStream > BaseResultSet::getBinaryStream( sal_Int32 /* columnIndex */ )
     585                 :            :         throw (SQLException, RuntimeException)
     586                 :            : {
     587                 :          0 :     return 0;
     588                 :            : }
     589                 :            : 
     590                 :          0 : Reference< ::com::sun::star::io::XInputStream > BaseResultSet::getCharacterStream( sal_Int32 /* columnIndex */ )
     591                 :            :         throw (SQLException, RuntimeException)
     592                 :            : {
     593                 :          0 :     return 0;
     594                 :            : }
     595                 :            : 
     596                 :          0 : Any BaseResultSet::getObject(
     597                 :            :         sal_Int32 /* columnIndex */,
     598                 :            :         const Reference< ::com::sun::star::container::XNameAccess >& /* typeMap */ )
     599                 :            :         throw (SQLException, RuntimeException)
     600                 :            : {
     601                 :          0 :     return Any();
     602                 :            : }
     603                 :            : 
     604                 :          0 : Reference< ::com::sun::star::sdbc::XRef > BaseResultSet::getRef( sal_Int32 /* columnIndex */ )
     605                 :            :         throw (SQLException, RuntimeException)
     606                 :            : {
     607                 :          0 :     return Reference< com::sun::star::sdbc::XRef > ();
     608                 :            : }
     609                 :            : 
     610                 :          0 : Reference< ::com::sun::star::sdbc::XBlob > BaseResultSet::getBlob( sal_Int32 /* columnIndex */ )
     611                 :            :         throw (SQLException, RuntimeException)
     612                 :            : {
     613                 :          0 :     return Reference< com::sun::star::sdbc::XBlob > ();
     614                 :            : }
     615                 :            : 
     616                 :          0 : Reference< ::com::sun::star::sdbc::XClob > BaseResultSet::getClob( sal_Int32 /* columnIndex */ )
     617                 :            :         throw (SQLException, RuntimeException)
     618                 :            : {
     619                 :          0 :     return Reference< com::sun::star::sdbc::XClob > ();
     620                 :            : }
     621                 :            : 
     622                 :          0 : Reference< ::com::sun::star::sdbc::XArray > BaseResultSet::getArray( sal_Int32 columnIndex )
     623                 :            :         throw (SQLException, RuntimeException)
     624                 :            : {
     625                 :          0 :     return new Array( m_refMutex, parseArray( getString( columnIndex ) ), *this, m_tc );
     626                 :            : }
     627                 :            : 
     628                 :          0 : ::cppu::IPropertyArrayHelper & BaseResultSet::getInfoHelper()
     629                 :            : {
     630                 :          0 :     return getResultSetPropertyArrayHelper();
     631                 :            : }
     632                 :            : 
     633                 :          0 : sal_Bool BaseResultSet::convertFastPropertyValue(
     634                 :            :         Any & /* rConvertedValue */, Any & /* rOldValue */, sal_Int32 nHandle, const Any& rValue )
     635                 :            :         throw (IllegalArgumentException)
     636                 :            : {
     637                 :            :     sal_Bool bRet;
     638                 :          0 :     switch( nHandle )
     639                 :            :     {
     640                 :            :     case BASERESULTSET_CURSOR_NAME:
     641                 :            :     {
     642                 :          0 :         OUString val;
     643                 :          0 :         bRet = ( rValue >>= val );
     644                 :          0 :         m_props[nHandle] = makeAny( val );
     645                 :          0 :         break;
     646                 :            :     }
     647                 :            :     case BASERESULTSET_ESCAPE_PROCESSING:
     648                 :            :     case BASERESULTSET_IS_BOOKMARKABLE:
     649                 :            :     {
     650                 :            :         sal_Bool val;
     651                 :          0 :         bRet = ( rValue >>= val );
     652                 :          0 :         m_props[nHandle] = makeAny( val );
     653                 :            :         break;
     654                 :            :     }
     655                 :            :     case BASERESULTSET_FETCH_DIRECTION:
     656                 :            :     case BASERESULTSET_FETCH_SIZE:
     657                 :            :     case BASERESULTSET_RESULT_SET_CONCURRENCY:
     658                 :            :     case BASERESULTSET_RESULT_SET_TYPE:
     659                 :            :     {
     660                 :            :         sal_Int32 val;
     661                 :          0 :         bRet = ( rValue >>= val );
     662                 :          0 :         m_props[nHandle] = makeAny( val );
     663                 :            :         break;
     664                 :            :     }
     665                 :            :     default:
     666                 :            :     {
     667                 :          0 :         OUStringBuffer buf(128);
     668                 :          0 :         buf.appendAscii( "pq_resultset: Invalid property handle (" );
     669                 :          0 :         buf.append( nHandle );
     670                 :          0 :         buf.appendAscii( ")" );
     671                 :          0 :         throw IllegalArgumentException( buf.makeStringAndClear(), *this, 2 );
     672                 :            :     }
     673                 :            :     }
     674                 :          0 :     return bRet;
     675                 :            : }
     676                 :            : 
     677                 :            : 
     678                 :          0 : void BaseResultSet::setFastPropertyValue_NoBroadcast(
     679                 :            :     sal_Int32 nHandle,const Any& rValue ) throw (Exception)
     680                 :            : {
     681                 :          0 :     m_props[nHandle] = rValue;
     682                 :          0 : }
     683                 :            : 
     684                 :          0 : void BaseResultSet::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
     685                 :            : {
     686                 :          0 :     rValue = m_props[nHandle];
     687                 :          0 : }
     688                 :            : 
     689                 :          0 : Reference < XPropertySetInfo >  BaseResultSet::getPropertySetInfo()
     690                 :            :         throw(RuntimeException)
     691                 :            : {
     692                 :          0 :     return OPropertySetHelper::createPropertySetInfo( getResultSetPropertyArrayHelper() );
     693                 :            : }
     694                 :            : 
     695                 :          0 : void BaseResultSet::disposing()
     696                 :            : {
     697                 :          0 :     close();
     698                 :          0 : }
     699                 :            : 
     700                 :          0 : void BaseResultSet::checkColumnIndex(sal_Int32 index ) throw ( SQLException, RuntimeException )
     701                 :            : {
     702                 :          0 :     if( index < 1 || index > m_fieldCount )
     703                 :            :     {
     704                 :          0 :         OUStringBuffer buf(128);
     705                 :          0 :         buf.appendAscii( "pq_resultset: index out of range (" );
     706                 :          0 :         buf.append( index );
     707                 :          0 :         buf.appendAscii( ", allowed range is 1 to " );
     708                 :          0 :         buf.append( m_fieldCount );
     709                 :          0 :         buf.appendAscii( ")" );
     710                 :          0 :         throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any() );
     711                 :            :     }
     712                 :            : 
     713                 :          0 : }
     714                 :            : 
     715                 :          0 : void BaseResultSet::checkRowIndex( sal_Bool mustBeOnValidRow )
     716                 :            : {
     717                 :          0 :     OUStringBuffer buf( 128 );
     718                 :          0 :     buf.appendAscii( "pq_baseresultset: row index out of range, allowed is " );
     719                 :          0 :     if( mustBeOnValidRow )
     720                 :            :     {
     721                 :          0 :         if( m_row < 0 || m_row >= m_rowCount )
     722                 :            :         {
     723                 :          0 :             buf.appendAscii( "0 to " );
     724                 :          0 :             buf.append( ((sal_Int32)(m_rowCount -1)) );
     725                 :          0 :             buf.appendAscii( ", got " );
     726                 :          0 :             buf.append( m_row );
     727                 :          0 :             throw SQLException( buf.makeStringAndClear(), *this, OUString(),1, Any() );
     728                 :            :         }
     729                 :            :     }
     730                 :            :     else
     731                 :            :     {
     732                 :          0 :         if( m_row < -1 || m_row > m_rowCount )
     733                 :            :         {
     734                 :          0 :             buf.appendAscii( "-1 to " );
     735                 :          0 :             buf.append( m_rowCount );
     736                 :          0 :             buf.appendAscii( ", got " );
     737                 :          0 :             buf.append( m_row );
     738                 :          0 :             throw SQLException( buf.makeStringAndClear(), *this, OUString(),1, Any() );
     739                 :            :         }
     740                 :          0 :     }
     741                 :          0 : }
     742                 :            : 
     743                 :            : }

Generated by: LCOV version 1.10