LCOV - code coverage report
Current view: top level - connectivity/source/drivers/odbc - OResultSetMetaData.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 113 0.0 %
Date: 2014-04-14 Functions: 0 27 0.0 %
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 "odbc/OResultSetMetaData.hxx"
      21             : #include "odbc/OTools.hxx"
      22             : 
      23             : using namespace connectivity::odbc;
      24             : using namespace com::sun::star::uno;
      25             : using namespace com::sun::star::lang;
      26             : using namespace com::sun::star::sdbc;
      27             : 
      28             : 
      29           0 : OResultSetMetaData::~OResultSetMetaData()
      30             : {
      31           0 : }
      32             : 
      33           0 : OUString OResultSetMetaData::getCharColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException)
      34             : {
      35           0 :     sal_Int32 column = _column;
      36           0 :     if(_column <(sal_Int32) m_vMapping.size()) // use mapping
      37           0 :         column = m_vMapping[_column];
      38             : 
      39           0 :     SQLSMALLINT BUFFER_LEN = 128;
      40           0 :     char *pName = new char[BUFFER_LEN+1];
      41           0 :     SQLSMALLINT nRealLen=0;
      42           0 :     SQLRETURN nRet = N3SQLColAttribute(m_aStatementHandle,
      43             :                                     (SQLUSMALLINT)column,
      44             :                                     (SQLUSMALLINT)ident,
      45             :                                     (SQLPOINTER)pName,
      46             :                                     BUFFER_LEN,
      47             :                                     &nRealLen,
      48             :                                     NULL
      49             :                                     );
      50           0 :     OUString sValue;
      51           0 :     if ( nRet == SQL_SUCCESS )
      52             :     {
      53           0 :         if ( nRealLen < 0 )
      54           0 :             nRealLen = BUFFER_LEN;
      55           0 :         sValue = OUString(pName,nRealLen,m_pConnection->getTextEncoding());
      56             :     }
      57           0 :     delete [] pName;
      58           0 :     OTools::ThrowException(m_pConnection,nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
      59           0 :     if(nRealLen > BUFFER_LEN)
      60             :     {
      61           0 :         pName = new char[nRealLen+1];
      62           0 :         nRet = N3SQLColAttribute(m_aStatementHandle,
      63             :                                     (SQLUSMALLINT)column,
      64             :                                     (SQLUSMALLINT)ident,
      65             :                                     (SQLPOINTER)pName,
      66             :                                     nRealLen,
      67             :                                     &nRealLen,
      68             :                                     NULL
      69           0 :                                     );
      70           0 :         if ( nRet == SQL_SUCCESS && nRealLen > 0)
      71           0 :             sValue = OUString(pName,nRealLen,m_pConnection->getTextEncoding());
      72           0 :         delete [] pName;
      73           0 :         OTools::ThrowException(m_pConnection,nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
      74             :     }
      75             : 
      76           0 :     return  sValue;
      77             : }
      78             : 
      79           0 : SQLLEN OResultSetMetaData::getNumColAttrib(OConnection* _pConnection
      80             :                                               ,SQLHANDLE _aStatementHandle
      81             :                                               ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface
      82             :                                               ,sal_Int32 _column
      83             :                                               ,sal_Int32 _ident) throw(SQLException, RuntimeException)
      84             : {
      85           0 :     SQLLEN nValue=0;
      86           0 :     OTools::ThrowException(_pConnection,(*(T3SQLColAttribute)_pConnection->getOdbcFunction(ODBC3SQLColAttribute))(_aStatementHandle,
      87             :                                          (SQLUSMALLINT)_column,
      88             :                                          (SQLUSMALLINT)_ident,
      89             :                                          NULL,
      90             :                                          0,
      91             :                                          NULL,
      92           0 :                                          &nValue),_aStatementHandle,SQL_HANDLE_STMT,_xInterface);
      93           0 :     return nValue;
      94             : }
      95             : 
      96           0 : sal_Int32 OResultSetMetaData::getNumColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException)
      97             : {
      98           0 :     sal_Int32 column = _column;
      99           0 :     if(_column < (sal_Int32)m_vMapping.size()) // use mapping
     100           0 :         column = m_vMapping[_column];
     101             : 
     102           0 :     return getNumColAttrib(m_pConnection,m_aStatementHandle,*this,column,ident);
     103             : }
     104             : 
     105           0 : sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     106             : {
     107           0 :     return getNumColAttrib(column,SQL_DESC_DISPLAY_SIZE);
     108             : }
     109             : 
     110           0 : SQLSMALLINT OResultSetMetaData::getColumnODBCType(OConnection* _pConnection
     111             :                                               ,SQLHANDLE _aStatementHandle
     112             :                                               ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface
     113             :                                               ,sal_Int32 column)
     114             :                                                throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     115             : {
     116           0 :     SQLSMALLINT nType = 0;
     117             :     try
     118             :     {
     119           0 :         nType = (SQLSMALLINT)getNumColAttrib(_pConnection,_aStatementHandle,_xInterface,column,SQL_DESC_CONCISE_TYPE);
     120           0 :         if(nType == SQL_UNKNOWN_TYPE)
     121           0 :             nType = (SQLSMALLINT)getNumColAttrib(_pConnection,_aStatementHandle,_xInterface,column, SQL_DESC_TYPE);
     122             :     }
     123           0 :     catch(SQLException& ) // in this case we have an odbc 2.0 driver
     124             :     {
     125           0 :         nType = (SQLSMALLINT)getNumColAttrib(_pConnection,_aStatementHandle,_xInterface,column,SQL_DESC_CONCISE_TYPE );
     126             :     }
     127             : 
     128           0 :     return nType;
     129             : }
     130             : 
     131           0 : sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     132             : {
     133           0 :     ::std::map<sal_Int32,sal_Int32>::iterator aFind = m_aColumnTypes.find(column);
     134           0 :     if ( aFind == m_aColumnTypes.end() )
     135             :     {
     136           0 :         sal_Int32 nType = 0;
     137           0 :         if(!m_bUseODBC2Types)
     138             :         {
     139             :             try
     140             :             {
     141           0 :                 nType = getNumColAttrib(column,SQL_DESC_CONCISE_TYPE);
     142           0 :                 if(nType == SQL_UNKNOWN_TYPE)
     143           0 :                     nType = getNumColAttrib(column, SQL_DESC_TYPE);
     144           0 :                 nType = OTools::MapOdbcType2Jdbc(nType);
     145             :             }
     146           0 :             catch(SQLException& ) // in this case we have an odbc 2.0 driver
     147             :             {
     148           0 :                 m_bUseODBC2Types = sal_True;
     149           0 :                 nType = OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_CONCISE_TYPE ));
     150             :             }
     151             :         }
     152             :         else
     153           0 :             nType = OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_CONCISE_TYPE ));
     154           0 :         aFind = m_aColumnTypes.insert(::std::map<sal_Int32,sal_Int32>::value_type(column,nType)).first;
     155             :     }
     156             : 
     157             : 
     158           0 :     return aFind->second;
     159             : }
     160             : 
     161             : 
     162           0 : sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount(  ) throw(SQLException, RuntimeException, std::exception)
     163             : {
     164           0 :     if(m_nColCount != -1)
     165           0 :         return m_nColCount;
     166             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::getColumnCount" );
     167           0 :     sal_Int16 nNumResultCols=0;
     168           0 :     OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this);
     169           0 :     return m_nColCount = nNumResultCols;
     170             : }
     171             : 
     172             : 
     173           0 : sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     174             : {
     175           0 :     return getNumColAttrib(column,SQL_DESC_CASE_SENSITIVE) == SQL_TRUE;
     176             : }
     177             : 
     178             : 
     179           0 : OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     180             : {
     181           0 :     return getCharColAttrib(column,SQL_DESC_SCHEMA_NAME);
     182             : }
     183             : 
     184             : 
     185           0 : OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     186             : {
     187           0 :     return getCharColAttrib(column,SQL_DESC_NAME);
     188             : }
     189             : 
     190           0 : OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     191             : {
     192           0 :     return getCharColAttrib(column,SQL_DESC_TABLE_NAME);
     193             : }
     194             : 
     195           0 : OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     196             : {
     197           0 :     return getCharColAttrib(column,SQL_DESC_CATALOG_NAME);
     198             : }
     199             : 
     200           0 : OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     201             : {
     202             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::getColumnTypeName" );
     203           0 :     return getCharColAttrib(column,SQL_DESC_TYPE_NAME);
     204             : }
     205             : 
     206           0 : OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     207             : {
     208             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::getColumnLabel" );
     209           0 :     return getCharColAttrib(column,SQL_DESC_LABEL);
     210             : }
     211             : 
     212           0 : OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException, std::exception)
     213             : {
     214             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::getColumnServiceName" );
     215           0 :     return OUString();
     216             : }
     217             : 
     218             : 
     219           0 : sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     220             : {
     221           0 :     return getNumColAttrib(column,SQL_DESC_FIXED_PREC_SCALE) == SQL_TRUE;
     222             : }
     223             : 
     224             : 
     225           0 : sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     226             : {
     227           0 :     return getNumColAttrib(column,SQL_DESC_AUTO_UNIQUE_VALUE) == SQL_TRUE;
     228             : }
     229             : 
     230             : 
     231             : 
     232           0 : sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     233             : {
     234             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::isSigned" );
     235           0 :     return getNumColAttrib(column,SQL_DESC_UNSIGNED) == SQL_FALSE;
     236             : }
     237             : 
     238           0 : sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     239             : {
     240             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::getPrecision" );
     241           0 :     sal_Int32 nType = 0;
     242             :     try
     243             :     {
     244           0 :         nType = getNumColAttrib(column,SQL_DESC_PRECISION);
     245             :     }
     246           0 :     catch(const SQLException& ) // in this case we have an odbc 2.0 driver
     247             :     {
     248           0 :         m_bUseODBC2Types = sal_True;
     249           0 :         nType = getNumColAttrib(column,SQL_COLUMN_PRECISION );
     250             :     }
     251           0 :     return nType;
     252             : }
     253             : 
     254           0 : sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
     255             : {
     256             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::getScale" );
     257           0 :     sal_Int32 nType = 0;
     258             :     try
     259             :     {
     260           0 :         nType = getNumColAttrib(column,SQL_DESC_SCALE);
     261             :     }
     262           0 :     catch(const SQLException& ) // in this case we have an odbc 2.0 driver
     263             :     {
     264           0 :         m_bUseODBC2Types = sal_True;
     265           0 :         nType = getNumColAttrib(column,SQL_COLUMN_SCALE );
     266             :     }
     267           0 :     return nType;
     268             : }
     269             : 
     270             : 
     271           0 : sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     272             : {
     273             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::isNullable" );
     274           0 :     return getNumColAttrib(column,SQL_DESC_NULLABLE);
     275             : }
     276             : 
     277             : 
     278           0 : sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     279             : {
     280             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::isSearchable" );
     281           0 :     return getNumColAttrib(column,SQL_DESC_SEARCHABLE) != SQL_PRED_NONE;
     282             : }
     283             : 
     284             : 
     285           0 : sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     286             : {
     287             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::isReadOnly" );
     288           0 :     return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_READONLY;
     289             : }
     290             : 
     291             : 
     292           0 : sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     293             : {
     294             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::isDefinitelyWritable" );
     295           0 :     return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE;
     296             : ;
     297             : }
     298             : 
     299           0 : sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     300             : {
     301             :     SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OResultSetMetaData::isWritable" );
     302           0 :     return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE;
     303             : }
     304             : 
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10