LCOV - code coverage report
Current view: top level - connectivity/source/drivers/odbc - OResultSetMetaData.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 113 0.0 %
Date: 2015-06-13 12:38:46 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             :                                     static_cast<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             :                                     static_cast<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,(*reinterpret_cast<T3SQLColAttribute>(_pConnection->getOdbcFunction(ODBC3SQLFunctionId::ColAttribute)))(_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 = 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           0 :     sal_Int16 nNumResultCols=0;
     167           0 :     OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this);
     168           0 :     return m_nColCount = nNumResultCols;
     169             : }
     170             : 
     171             : 
     172           0 : sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     173             : {
     174           0 :     return getNumColAttrib(column,SQL_DESC_CASE_SENSITIVE) == SQL_TRUE;
     175             : }
     176             : 
     177             : 
     178           0 : OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     179             : {
     180           0 :     return getCharColAttrib(column,SQL_DESC_SCHEMA_NAME);
     181             : }
     182             : 
     183             : 
     184           0 : OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     185             : {
     186           0 :     return getCharColAttrib(column,SQL_DESC_NAME);
     187             : }
     188             : 
     189           0 : OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     190             : {
     191           0 :     return getCharColAttrib(column,SQL_DESC_TABLE_NAME);
     192             : }
     193             : 
     194           0 : OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     195             : {
     196           0 :     return getCharColAttrib(column,SQL_DESC_CATALOG_NAME);
     197             : }
     198             : 
     199           0 : OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     200             : {
     201           0 :     return getCharColAttrib(column,SQL_DESC_TYPE_NAME);
     202             : }
     203             : 
     204           0 : OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     205             : {
     206           0 :     return getCharColAttrib(column,SQL_DESC_LABEL);
     207             : }
     208             : 
     209           0 : OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException, std::exception)
     210             : {
     211           0 :     return OUString();
     212             : }
     213             : 
     214             : 
     215           0 : sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     216             : {
     217           0 :     return getNumColAttrib(column,SQL_DESC_FIXED_PREC_SCALE) == SQL_TRUE;
     218             : }
     219             : 
     220             : 
     221           0 : sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     222             : {
     223           0 :     return getNumColAttrib(column,SQL_DESC_AUTO_UNIQUE_VALUE) == SQL_TRUE;
     224             : }
     225             : 
     226             : 
     227             : 
     228           0 : sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     229             : {
     230           0 :     return getNumColAttrib(column,SQL_DESC_UNSIGNED) == SQL_FALSE;
     231             : }
     232             : 
     233           0 : sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     234             : {
     235           0 :     sal_Int32 nType = 0;
     236             :     try
     237             :     {
     238           0 :         nType = getNumColAttrib(column,SQL_DESC_PRECISION);
     239             :     }
     240           0 :     catch(const SQLException& ) // in this case we have an odbc 2.0 driver
     241             :     {
     242           0 :         m_bUseODBC2Types = true;
     243           0 :         nType = getNumColAttrib(column,SQL_COLUMN_PRECISION );
     244             :     }
     245           0 :     return nType;
     246             : }
     247             : 
     248           0 : sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
     249             : {
     250           0 :     sal_Int32 nType = 0;
     251             :     try
     252             :     {
     253           0 :         nType = getNumColAttrib(column,SQL_DESC_SCALE);
     254             :     }
     255           0 :     catch(const SQLException& ) // in this case we have an odbc 2.0 driver
     256             :     {
     257           0 :         m_bUseODBC2Types = true;
     258           0 :         nType = getNumColAttrib(column,SQL_COLUMN_SCALE );
     259             :     }
     260           0 :     return nType;
     261             : }
     262             : 
     263             : 
     264           0 : sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     265             : {
     266           0 :     return getNumColAttrib(column,SQL_DESC_NULLABLE);
     267             : }
     268             : 
     269             : 
     270           0 : sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     271             : {
     272           0 :     return getNumColAttrib(column,SQL_DESC_SEARCHABLE) != SQL_PRED_NONE;
     273             : }
     274             : 
     275             : 
     276           0 : sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     277             : {
     278           0 :     return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_READONLY;
     279             : }
     280             : 
     281             : 
     282           0 : sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     283             : {
     284           0 :     return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE;
     285             : }
     286             : 
     287           0 : sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
     288             : {
     289           0 :     return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE;
     290             : }
     291             : 
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11