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

Generated by: LCOV version 1.10