LCOV - code coverage report
Current view: top level - connectivity/source/drivers/odbcbase - OTools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 424 0.0 %
Date: 2012-08-25 Functions: 0 16 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                 :            :  * 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/OTools.hxx"
      21                 :            : #include "odbc/OFunctions.hxx"
      22                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      23                 :            : #include <osl/diagnose.h>
      24                 :            : #include "odbc/OConnection.hxx"
      25                 :            : #include "diagnose_ex.h"
      26                 :            : #include <rtl/logfile.hxx>
      27                 :            : #include <rtl/ustrbuf.hxx>
      28                 :            : 
      29                 :            : 
      30                 :            : #include <string.h>
      31                 :            : #include <string>
      32                 :            : #include <algorithm>
      33                 :            : 
      34                 :            : using namespace connectivity::odbc;
      35                 :            : using namespace com::sun::star::uno;
      36                 :            : using namespace com::sun::star::sdbc;
      37                 :            : using namespace com::sun::star::util;
      38                 :            : 
      39                 :            : namespace {
      40                 :          0 : size_t sqlTypeLen ( SQLSMALLINT _nType )
      41                 :            : {
      42                 :          0 :     switch (_nType)
      43                 :            :     {
      44                 :            :     case SQL_C_CHAR:
      45                 :          0 :         return sizeof(SQLCHAR *);
      46                 :            :     case SQL_C_WCHAR:
      47                 :          0 :         return sizeof(SQLWCHAR *);
      48                 :            :     case SQL_C_SSHORT:
      49                 :            :     case SQL_C_SHORT:
      50                 :          0 :         return sizeof(SQLSMALLINT);
      51                 :            :     case SQL_C_USHORT:
      52                 :          0 :         return sizeof(SQLUSMALLINT);
      53                 :            :     case SQL_C_SLONG:
      54                 :            :     case SQL_C_LONG:
      55                 :          0 :         return sizeof(SQLINTEGER);
      56                 :            :     case SQL_C_ULONG:
      57                 :          0 :         return sizeof(SQLUINTEGER);
      58                 :            :     case SQL_C_FLOAT:
      59                 :          0 :         return sizeof(SQLREAL);
      60                 :            :     case SQL_C_DOUBLE:
      61                 :            :         OSL_ENSURE(sizeof(SQLDOUBLE) == sizeof(SQLFLOAT), "SQLDOUBLE/SQLFLOAT confusion");
      62                 :          0 :         return sizeof(SQLDOUBLE);
      63                 :            :     case SQL_C_BIT:
      64                 :          0 :         return sizeof(SQLCHAR);
      65                 :            :     case SQL_C_STINYINT:
      66                 :            :     case SQL_C_TINYINT:
      67                 :          0 :         return sizeof(SQLSCHAR);
      68                 :            :     case SQL_C_UTINYINT:
      69                 :          0 :         return sizeof(SQLCHAR);
      70                 :            :     case SQL_C_SBIGINT:
      71                 :          0 :         return sizeof(SQLBIGINT);
      72                 :            :     case SQL_C_UBIGINT:
      73                 :          0 :         return sizeof(SQLUBIGINT);
      74                 :            :     /* UnixODBC gives this the same value as SQL_C_UBIGINT
      75                 :            :     case SQL_C_BOOKMARK:
      76                 :            :         return sizeof(BOOKMARK); */
      77                 :            :     case SQL_C_BINARY:
      78                 :            :     // UnixODBC gives these the same value
      79                 :            :     //case SQL_C_VARBOOKMARK:
      80                 :          0 :         return sizeof(SQLCHAR*);
      81                 :            :     case SQL_C_TYPE_DATE:
      82                 :            :     case SQL_C_DATE:
      83                 :          0 :         return sizeof(SQL_DATE_STRUCT);
      84                 :            :     case SQL_C_TYPE_TIME:
      85                 :            :     case SQL_C_TIME:
      86                 :          0 :         return sizeof(SQL_TIME_STRUCT);
      87                 :            :     case SQL_C_TYPE_TIMESTAMP:
      88                 :            :     case SQL_C_TIMESTAMP:
      89                 :          0 :         return sizeof(SQL_TIMESTAMP_STRUCT);
      90                 :            :     case SQL_C_NUMERIC:
      91                 :          0 :         return sizeof(SQL_NUMERIC_STRUCT);
      92                 :            :     case SQL_C_GUID:
      93                 :          0 :         return sizeof(SQLGUID);
      94                 :            :     case SQL_C_INTERVAL_YEAR:
      95                 :            :     case SQL_C_INTERVAL_MONTH:
      96                 :            :     case SQL_C_INTERVAL_DAY:
      97                 :            :     case SQL_C_INTERVAL_HOUR:
      98                 :            :     case SQL_C_INTERVAL_MINUTE:
      99                 :            :     case SQL_C_INTERVAL_SECOND:
     100                 :            :     case SQL_C_INTERVAL_YEAR_TO_MONTH:
     101                 :            :     case SQL_C_INTERVAL_DAY_TO_HOUR:
     102                 :            :     case SQL_C_INTERVAL_DAY_TO_MINUTE:
     103                 :            :     case SQL_C_INTERVAL_DAY_TO_SECOND:
     104                 :            :     case SQL_C_INTERVAL_HOUR_TO_MINUTE:
     105                 :            :     case SQL_C_INTERVAL_HOUR_TO_SECOND:
     106                 :            :     case SQL_C_INTERVAL_MINUTE_TO_SECOND:
     107                 :          0 :         return sizeof(SQL_INTERVAL_STRUCT);
     108                 :            :     default:
     109                 :          0 :         return static_cast<size_t>(-1);
     110                 :            :     }
     111                 :            : }
     112                 :            : }
     113                 :            : 
     114                 :            : 
     115                 :          0 : void OTools::getValue(  OConnection* _pConnection,
     116                 :            :                         SQLHANDLE _aStatementHandle,
     117                 :            :                         sal_Int32 columnIndex,
     118                 :            :                         SQLSMALLINT _nType,
     119                 :            :                         sal_Bool &_bWasNull,
     120                 :            :                         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
     121                 :            :                         void* _pValue,
     122                 :            :                         SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     123                 :            : {
     124                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getValue" );
     125                 :          0 :     const size_t properSize = sqlTypeLen(_nType);
     126                 :          0 :     if ( properSize == static_cast<size_t>(-1) )
     127                 :            :         OSL_FAIL("connectivity::odbc::OTools::getValue: unknown SQL type - cannot check buffer size");
     128                 :            :     else
     129                 :            :     {
     130                 :            :         OSL_ENSURE(static_cast<size_t>(_nSize) == properSize, "connectivity::odbc::OTools::getValue got wrongly sized memory region to write result to");
     131                 :          0 :         if ( static_cast<size_t>(_nSize) > properSize )
     132                 :            :         {
     133                 :            :             OSL_FAIL("memory region is too big - trying to fudge it");
     134                 :          0 :             memset(_pValue, 0, _nSize);
     135                 :            : #ifdef OSL_BIGENDIAN
     136                 :            :             // This is skewed in favour of integer types
     137                 :            :             _pValue += _nSize - properSize;
     138                 :            : #endif
     139                 :            :         }
     140                 :            :     }
     141                 :            :     OSL_ENSURE(static_cast<size_t>(_nSize) >= properSize, "memory region is too small");
     142                 :          0 :     SQLLEN pcbValue = SQL_NULL_DATA;
     143                 :            :     OTools::ThrowException(_pConnection,
     144                 :          0 :                             (*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
     145                 :            :                                         (SQLUSMALLINT)columnIndex,
     146                 :            :                                         _nType,
     147                 :            :                                         _pValue,
     148                 :            :                                         _nSize,
     149                 :          0 :                                         &pcbValue),
     150                 :          0 :                             _aStatementHandle,SQL_HANDLE_STMT,_xInterface,sal_False);
     151                 :          0 :     _bWasNull = pcbValue == SQL_NULL_DATA;
     152                 :          0 : }
     153                 :            : // -----------------------------------------------------------------------------
     154                 :          0 : void OTools::bindParameter( OConnection* _pConnection,
     155                 :            :                             SQLHANDLE _hStmt,
     156                 :            :                             sal_Int32 nPos,
     157                 :            :                             sal_Int8*& pDataBuffer,
     158                 :            :                             sal_Int8* pLenBuffer,
     159                 :            :                             SQLSMALLINT _nODBCtype,
     160                 :            :                             sal_Bool _bUseWChar,
     161                 :            :                             sal_Bool _bUseOldTimeDate,
     162                 :            :                             const void* _pValue,
     163                 :            :                             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
     164                 :            :                             rtl_TextEncoding _nTextEncoding)
     165                 :            :                              throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     166                 :            : {
     167                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindParameter" );
     168                 :            :     SQLRETURN nRetcode;
     169                 :            :     SQLSMALLINT fSqlType;
     170                 :            :     SQLSMALLINT fCType;
     171                 :          0 :     SQLLEN  nMaxLen = 0;
     172                 :          0 :     SQLLEN* pLen    = (SQLLEN*)pLenBuffer;
     173                 :          0 :     SQLULEN nColumnSize=0;
     174                 :          0 :     SQLSMALLINT nDecimalDigits=0;
     175                 :            :     bool atExec;
     176                 :            : 
     177                 :          0 :     OTools::getBindTypes(_bUseWChar,_bUseOldTimeDate,_nODBCtype,fCType,fSqlType);
     178                 :            : 
     179                 :          0 :     OTools::bindData(_nODBCtype,_bUseWChar,pDataBuffer,pLen,_pValue,_nTextEncoding,nColumnSize, atExec);
     180                 :          0 :     if ((nColumnSize == 0) && (fSqlType == SQL_CHAR || fSqlType == SQL_VARCHAR || fSqlType == SQL_LONGVARCHAR))
     181                 :          0 :         nColumnSize = 1;
     182                 :            : 
     183                 :          0 :     if (atExec)
     184                 :          0 :         memcpy(pDataBuffer,&nPos,sizeof(nPos));
     185                 :            : 
     186                 :          0 :     nRetcode = (*(T3SQLBindParameter)_pConnection->getOdbcFunction(ODBC3SQLBindParameter))(_hStmt,
     187                 :            :                   (SQLUSMALLINT)nPos,
     188                 :            :                   SQL_PARAM_INPUT,
     189                 :            :                   fCType,
     190                 :            :                   fSqlType,
     191                 :            :                   nColumnSize,
     192                 :            :                   nDecimalDigits,
     193                 :            :                   pDataBuffer,
     194                 :            :                   nMaxLen,
     195                 :          0 :                   pLen);
     196                 :            : 
     197                 :          0 :     OTools::ThrowException(_pConnection,nRetcode,_hStmt,SQL_HANDLE_STMT,_xInterface);
     198                 :          0 : }
     199                 :            : // -----------------------------------------------------------------------------
     200                 :          0 : void OTools::bindData(  SQLSMALLINT _nOdbcType,
     201                 :            :                         sal_Bool _bUseWChar,
     202                 :            :                         sal_Int8 *&_pData,
     203                 :            :                         SQLLEN*& pLen,
     204                 :            :                         const void* _pValue,
     205                 :            :                         rtl_TextEncoding _nTextEncoding,
     206                 :            :                         SQLULEN& _nColumnSize,
     207                 :            :                         bool &atExec)
     208                 :            : {
     209                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindData" );
     210                 :          0 :     _nColumnSize = 0;
     211                 :          0 :     atExec = false;
     212                 :            : 
     213                 :          0 :     switch (_nOdbcType)
     214                 :            :     {
     215                 :            :         case SQL_CHAR:
     216                 :            :         case SQL_VARCHAR:
     217                 :            :         case SQL_DECIMAL:
     218                 :          0 :             if(_bUseWChar)
     219                 :            :             {
     220                 :          0 :                 *pLen = SQL_NTS;
     221                 :          0 :                 ::rtl::OUString sStr(*(::rtl::OUString*)_pValue);
     222                 :          0 :                 _nColumnSize = sStr.getLength();
     223                 :          0 :                 *((rtl::OUString*)_pData) = sStr;
     224                 :            : 
     225                 :            :                 // Pointer on Char*
     226                 :          0 :                 _pData = (sal_Int8*)((rtl::OUString*)_pData)->getStr();
     227                 :            :             }
     228                 :            :             else
     229                 :            :             {
     230                 :          0 :                 ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding));
     231                 :          0 :                 *pLen = SQL_NTS;
     232                 :          0 :                 _nColumnSize = aString.getLength();
     233                 :          0 :                 memcpy(_pData,aString.getStr(),aString.getLength());
     234                 :          0 :                 ((sal_Int8*)_pData)[aString.getLength()] = '\0';
     235                 :            :             }
     236                 :          0 :             break;
     237                 :            : 
     238                 :            :         case SQL_BIGINT:
     239                 :          0 :             *((sal_Int64*)_pData) = *(sal_Int64*)_pValue;
     240                 :          0 :             *pLen = sizeof(sal_Int64);
     241                 :          0 :             _nColumnSize = *pLen;
     242                 :          0 :             break;
     243                 :            : 
     244                 :            :         case SQL_NUMERIC:
     245                 :          0 :             if(_bUseWChar)
     246                 :            :             {
     247                 :          0 :                 ::rtl::OUString aString = rtl::OUString::valueOf(*(double*)_pValue);
     248                 :          0 :                 _nColumnSize = aString.getLength();
     249                 :          0 :                 *pLen = _nColumnSize;
     250                 :          0 :                 *((rtl::OUString*)_pData) = aString;
     251                 :            :                 // Pointer on Char*
     252                 :          0 :                 _pData = (sal_Int8*)((rtl::OUString*)_pData)->getStr();
     253                 :            :             }
     254                 :            :             else
     255                 :            :             {
     256                 :          0 :                 ::rtl::OString aString = ::rtl::OString::valueOf(*(double*)_pValue);
     257                 :          0 :                 _nColumnSize = aString.getLength();
     258                 :          0 :                 *pLen = _nColumnSize;
     259                 :          0 :                 memcpy(_pData,aString.getStr(),aString.getLength());
     260                 :          0 :                 ((sal_Int8*)_pData)[_nColumnSize] = '\0';
     261                 :          0 :             }   break;
     262                 :            :         case SQL_BIT:
     263                 :            :         case SQL_TINYINT:
     264                 :          0 :             *((sal_Int8*)_pData) = *(sal_Int8*)_pValue;
     265                 :          0 :             *pLen = sizeof(sal_Int8);
     266                 :          0 :             break;
     267                 :            : 
     268                 :            :         case SQL_SMALLINT:
     269                 :          0 :             *((sal_Int16*)_pData) = *(sal_Int16*)_pValue;
     270                 :          0 :             *pLen = sizeof(sal_Int16);
     271                 :          0 :             break;
     272                 :            :         case SQL_INTEGER:
     273                 :          0 :             *((sal_Int32*)_pData) = *(sal_Int32*)_pValue;
     274                 :          0 :             *pLen = sizeof(sal_Int32);
     275                 :          0 :             break;
     276                 :            :         case SQL_FLOAT:
     277                 :          0 :             *((float*)_pData) = *(float*)_pValue;
     278                 :          0 :             *pLen = sizeof(float);
     279                 :          0 :             break;
     280                 :            :         case SQL_REAL:
     281                 :            :         case SQL_DOUBLE:
     282                 :          0 :             *((double*)_pData) = *(double*)_pValue;
     283                 :          0 :             *pLen = sizeof(double);
     284                 :          0 :             break;
     285                 :            :         case SQL_BINARY:
     286                 :            :         case SQL_VARBINARY:
     287                 :            :             {
     288                 :          0 :                 const ::com::sun::star::uno::Sequence< sal_Int8 >* pSeq = static_cast< const ::com::sun::star::uno::Sequence< sal_Int8 >* >(_pValue);
     289                 :            :                 OSL_ENSURE(pSeq,"OTools::bindData: Sequence is null!");
     290                 :            : 
     291                 :          0 :                 if(pSeq)
     292                 :            :                 {
     293                 :          0 :                     _pData = (sal_Int8*)pSeq->getConstArray();
     294                 :          0 :                     *pLen = pSeq->getLength();
     295                 :            :                 }
     296                 :            :             }
     297                 :          0 :             break;
     298                 :            :         case SQL_LONGVARBINARY:
     299                 :            :             {
     300                 :          0 :                 sal_Int32 nLen = 0;
     301                 :          0 :                 nLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
     302                 :          0 :                 *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
     303                 :            :             }
     304                 :          0 :             atExec = true;
     305                 :          0 :             break;
     306                 :            :         case SQL_LONGVARCHAR:
     307                 :            :         {
     308                 :          0 :             sal_Int32 nLen = 0;
     309                 :          0 :             if(_bUseWChar)
     310                 :          0 :                 nLen = sizeof(sal_Unicode) * ((::rtl::OUString*)_pValue)->getLength();
     311                 :            :             else
     312                 :            :             {
     313                 :          0 :                 ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding));
     314                 :          0 :                 nLen = aString.getLength();
     315                 :            :             }
     316                 :          0 :             *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
     317                 :          0 :             atExec = true;
     318                 :          0 :         }   break;
     319                 :            :         case SQL_DATE:
     320                 :          0 :             *(DATE_STRUCT*)_pData = *(DATE_STRUCT*)_pValue;
     321                 :          0 :             *pLen = (SQLLEN)sizeof(DATE_STRUCT);
     322                 :          0 :             _nColumnSize = 10;
     323                 :          0 :             break;
     324                 :            :         case SQL_TIME:
     325                 :          0 :             *(TIME_STRUCT*)_pData = *(TIME_STRUCT*)_pValue;
     326                 :          0 :             *pLen = (SQLLEN)sizeof(TIME_STRUCT);
     327                 :          0 :             _nColumnSize = 8;
     328                 :          0 :             break;
     329                 :            :         case SQL_TIMESTAMP:
     330                 :          0 :             *(TIMESTAMP_STRUCT*)_pData = *(TIMESTAMP_STRUCT*)_pValue;
     331                 :          0 :             *pLen = (SQLLEN)sizeof(TIMESTAMP_STRUCT);
     332                 :            :             // 20+sub-zero precision; we have hundredths of seconds
     333                 :          0 :             _nColumnSize = 22;
     334                 :          0 :             break;
     335                 :            :     }
     336                 :          0 : }
     337                 :            : // -------------------------------------------------------------------------
     338                 :          0 : void OTools::bindValue( OConnection* _pConnection,
     339                 :            :                         SQLHANDLE _aStatementHandle,
     340                 :            :                         sal_Int32 columnIndex,
     341                 :            :                         SQLSMALLINT _nType,
     342                 :            :                         SQLSMALLINT _nMaxLen,
     343                 :            :                         const void* _pValue,
     344                 :            :                         void* _pData,
     345                 :            :                         SQLLEN *pLen,
     346                 :            :                         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
     347                 :            :                         rtl_TextEncoding _nTextEncoding,
     348                 :            :                         sal_Bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     349                 :            : {
     350                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindValue" );
     351                 :            :     SQLRETURN nRetcode;
     352                 :            :     SQLSMALLINT   fSqlType;
     353                 :            :     SQLSMALLINT   fCType;
     354                 :          0 :     SQLLEN nMaxLen = _nMaxLen;
     355                 :            : 
     356                 :            :     OTools::getBindTypes(   sal_False,
     357                 :            :                             _bUseOldTimeDate,
     358                 :            :                             _nType,
     359                 :            :                             fCType,
     360                 :          0 :                             fSqlType);
     361                 :            : 
     362                 :          0 :     if (columnIndex != 0 && !_pValue)
     363                 :            :     {
     364                 :          0 :         *pLen = SQL_NULL_DATA;
     365                 :          0 :         nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle,
     366                 :            :                                 (SQLUSMALLINT)columnIndex,
     367                 :            :                                 fCType,
     368                 :            :                                 _pData,
     369                 :            :                                 nMaxLen,
     370                 :            :                                 pLen
     371                 :          0 :                                 );
     372                 :            :     }
     373                 :            :     else
     374                 :            :     {
     375                 :            :         try
     376                 :            :         {
     377                 :          0 :             switch (_nType)
     378                 :            :             {
     379                 :            :                 case SQL_CHAR:
     380                 :            :                 case SQL_VARCHAR:
     381                 :            :                 {
     382                 :          0 :                     ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding));
     383                 :          0 :                     *pLen = SQL_NTS;
     384                 :          0 :                     *((::rtl::OString*)_pData) = aString;
     385                 :          0 :                     _nMaxLen = (SQLSMALLINT)aString.getLength();
     386                 :            : 
     387                 :            :                     // Pointer on Char*
     388                 :          0 :                     _pData = (void*)aString.getStr();
     389                 :          0 :                 }   break;
     390                 :            :                 case SQL_BIGINT:
     391                 :          0 :                     *((sal_Int64*)_pData) = *(sal_Int64*)_pValue;
     392                 :          0 :                     *pLen = sizeof(sal_Int64);
     393                 :          0 :                     break;
     394                 :            :                 case SQL_DECIMAL:
     395                 :            :                 case SQL_NUMERIC:
     396                 :            :                 {
     397                 :          0 :                     ::rtl::OString aString = ::rtl::OString::valueOf(*(double*)_pValue);
     398                 :          0 :                     _nMaxLen = (SQLSMALLINT)aString.getLength();
     399                 :          0 :                     *pLen = _nMaxLen;
     400                 :          0 :                     *((::rtl::OString*)_pData) = aString;
     401                 :            :                     // Pointer on Char*
     402                 :          0 :                     _pData = (void*)((::rtl::OString*)_pData)->getStr();
     403                 :          0 :                 }   break;
     404                 :            :                 case SQL_BIT:
     405                 :            :                 case SQL_TINYINT:
     406                 :          0 :                     *((sal_Int8*)_pData) = *(sal_Int8*)_pValue;
     407                 :          0 :                     *pLen = sizeof(sal_Int8);
     408                 :          0 :                     break;
     409                 :            : 
     410                 :            :                 case SQL_SMALLINT:
     411                 :          0 :                     *((sal_Int16*)_pData) = *(sal_Int16*)_pValue;
     412                 :          0 :                     *pLen = sizeof(sal_Int16);
     413                 :          0 :                     break;
     414                 :            :                 case SQL_INTEGER:
     415                 :          0 :                     *((sal_Int32*)_pData) = *(sal_Int32*)_pValue;
     416                 :          0 :                     *pLen = sizeof(sal_Int32);
     417                 :          0 :                     break;
     418                 :            :                 case SQL_FLOAT:
     419                 :          0 :                     *((float*)_pData) = *(float*)_pValue;
     420                 :          0 :                     *pLen = sizeof(float);
     421                 :          0 :                     break;
     422                 :            :                 case SQL_REAL:
     423                 :            :                 case SQL_DOUBLE:
     424                 :          0 :                     *((double*)_pData) = *(double*)_pValue;
     425                 :          0 :                     *pLen = sizeof(double);
     426                 :          0 :                     break;
     427                 :            :                 case SQL_BINARY:
     428                 :            :                 case SQL_VARBINARY:
     429                 :            :                     {
     430                 :          0 :                         _pData = (void*)((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getConstArray();
     431                 :          0 :                         *pLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
     432                 :          0 :                     }   break;
     433                 :            :                 case SQL_LONGVARBINARY:
     434                 :            :                 {
     435                 :          0 :                     _pData = (void*)(sal_IntPtr)(columnIndex);
     436                 :          0 :                     sal_Int32 nLen = 0;
     437                 :          0 :                     nLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
     438                 :          0 :                     *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
     439                 :            :                 }
     440                 :          0 :                     break;
     441                 :            :                 case SQL_LONGVARCHAR:
     442                 :            :                 {
     443                 :          0 :                     _pData = (void*)(sal_IntPtr)(columnIndex);
     444                 :          0 :                     sal_Int32 nLen = 0;
     445                 :          0 :                     nLen = ((::rtl::OUString*)_pValue)->getLength();
     446                 :          0 :                     *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
     447                 :          0 :                 }   break;
     448                 :            :                 case SQL_DATE:
     449                 :          0 :                     *pLen = sizeof(DATE_STRUCT);
     450                 :          0 :                     *((DATE_STRUCT*)_pData) = *(DATE_STRUCT*)_pValue;
     451                 :          0 :                     break;
     452                 :            :                 case SQL_TIME:
     453                 :          0 :                     *pLen = sizeof(TIME_STRUCT);
     454                 :          0 :                     *((TIME_STRUCT*)_pData) = *(TIME_STRUCT*)_pValue;
     455                 :          0 :                     break;
     456                 :            :                 case SQL_TIMESTAMP:
     457                 :          0 :                     *pLen = sizeof(TIMESTAMP_STRUCT);
     458                 :          0 :                     *((TIMESTAMP_STRUCT*)_pData) = *(TIMESTAMP_STRUCT*)_pValue;
     459                 :          0 :                     break;
     460                 :            :             }
     461                 :            :         }
     462                 :          0 :         catch ( ... )
     463                 :            :         {
     464                 :            :         }
     465                 :            : 
     466                 :          0 :         nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle,
     467                 :            :                                 (SQLUSMALLINT)columnIndex,
     468                 :            :                                 fCType,
     469                 :            :                                 _pData,
     470                 :            :                                 nMaxLen,
     471                 :            :                                 pLen
     472                 :          0 :                                 );
     473                 :            :     }
     474                 :            : 
     475                 :          0 :     OTools::ThrowException(_pConnection,nRetcode,_aStatementHandle,SQL_HANDLE_STMT,_xInterface);
     476                 :          0 : }
     477                 :            : // -----------------------------------------------------------------------------
     478                 :          0 : void OTools::ThrowException(OConnection* _pConnection,
     479                 :            :                             SQLRETURN _rRetCode,
     480                 :            :                             SQLHANDLE _pContext,
     481                 :            :                             SQLSMALLINT _nHandleType,
     482                 :            :                             const Reference< XInterface >& _xInterface,
     483                 :            :                             sal_Bool _bNoFound,
     484                 :            :                             rtl_TextEncoding _nTextEncoding) throw(SQLException)
     485                 :            : {
     486                 :          0 :     switch(_rRetCode)
     487                 :            :     {
     488                 :            :         case SQL_NEED_DATA:
     489                 :            :         case SQL_STILL_EXECUTING:
     490                 :            :         case SQL_SUCCESS:
     491                 :            : 
     492                 :            :         case SQL_SUCCESS_WITH_INFO:
     493                 :            :                         return;
     494                 :            :         case SQL_NO_DATA_FOUND:
     495                 :          0 :                                 if(_bNoFound)
     496                 :            :                                     return; // no need to throw a exception
     497                 :          0 :         case SQL_ERROR:             break;
     498                 :            : 
     499                 :            : 
     500                 :            :         case SQL_INVALID_HANDLE:    OSL_FAIL("SdbODBC3_SetStatus: SQL_INVALID_HANDLE");
     501                 :          0 :                                     throw SQLException();
     502                 :            :     }
     503                 :            : 
     504                 :            :     // Additional Information on the latest ODBC-functioncall available
     505                 :            :     // SQLError provides this Information.
     506                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::ThrowException" );
     507                 :            : 
     508                 :            :     SDB_ODBC_CHAR szSqlState[5];
     509                 :            :     SQLINTEGER pfNativeError;
     510                 :            :     SDB_ODBC_CHAR szErrorMessage[SQL_MAX_MESSAGE_LENGTH];
     511                 :          0 :     szErrorMessage[0] = '\0';
     512                 :          0 :     SQLSMALLINT pcbErrorMsg = 0;
     513                 :            : 
     514                 :            :     // Information for latest operation:
     515                 :            :     // when hstmt != SQL_NULL_HSTMT is (Used from SetStatus in SdbCursor, SdbTable, ...),
     516                 :            :     // then the status of the latest statments will be fetched, without the Status of the last
     517                 :            :     // Statments of this connection [what in this case will probably be the same, but the Reference
     518                 :            :     // Manual isn't totally clear in this...].
     519                 :            :     // corresponding for hdbc.
     520                 :          0 :     SQLRETURN n = (*(T3SQLGetDiagRec)_pConnection->getOdbcFunction(ODBC3SQLGetDiagRec))(_nHandleType,_pContext,1,
     521                 :            :                          szSqlState,
     522                 :            :                          &pfNativeError,
     523                 :          0 :                          szErrorMessage,sizeof szErrorMessage - 1,&pcbErrorMsg);
     524                 :            :     OSL_UNUSED( n );
     525                 :            :     OSL_ENSURE(n != SQL_INVALID_HANDLE,"SdbODBC3_SetStatus: SQLError returned SQL_INVALID_HANDLE");
     526                 :            :     OSL_ENSURE(n == SQL_SUCCESS || n == SQL_SUCCESS_WITH_INFO || n == SQL_NO_DATA_FOUND || n == SQL_ERROR,"SdbODBC3_SetStatus: SQLError failed");
     527                 :            : 
     528                 :            :     // For the Return Code of SQLError see ODBC 2.0 Programmer's Reference Page 287ff
     529                 :            :     throw SQLException( ::rtl::OUString((char *)szErrorMessage,pcbErrorMsg,_nTextEncoding),
     530                 :            :                                     _xInterface,
     531                 :            :                                     ::rtl::OUString((char *)szSqlState,5,_nTextEncoding),
     532                 :            :                                     pfNativeError,
     533                 :            :                                     Any()
     534                 :          0 :                                 );
     535                 :            : 
     536                 :            : }
     537                 :            : // -------------------------------------------------------------------------
     538                 :          0 : Sequence<sal_Int8> OTools::getBytesValue(OConnection* _pConnection,
     539                 :            :                                          SQLHANDLE _aStatementHandle,
     540                 :            :                                          sal_Int32 columnIndex,
     541                 :            :                                          SQLSMALLINT _fSqlType,
     542                 :            :                                          sal_Bool &_bWasNull,
     543                 :            :                                          const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
     544                 :            : {
     545                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getBytesValue" );
     546                 :            :     char aCharArray[2048];
     547                 :            :     // First try to fetch the data with the little Buffer:
     548                 :          0 :     SQLLEN nMaxLen = sizeof aCharArray - 1;
     549                 :            :     //  GETDATA(SQL_C_CHAR,aCharArray,nMaxLen);
     550                 :          0 :     SQLLEN pcbValue = 0;
     551                 :          0 :     OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
     552                 :            :                                         (SQLUSMALLINT)columnIndex,
     553                 :            :                                         _fSqlType,
     554                 :            :                                         (SQLPOINTER)aCharArray,
     555                 :            :                                         nMaxLen,
     556                 :          0 :                                         &pcbValue),
     557                 :          0 :                             _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
     558                 :            : 
     559                 :          0 :     _bWasNull = pcbValue == SQL_NULL_DATA;
     560                 :          0 :     if(_bWasNull)
     561                 :          0 :         return Sequence<sal_Int8>();
     562                 :            : 
     563                 :          0 :     SQLINTEGER nBytes = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : nMaxLen;
     564                 :          0 :     if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nBytes-1] == 0  && nBytes > 0 )
     565                 :          0 :         --nBytes;
     566                 :          0 :     Sequence<sal_Int8> aData((sal_Int8*)aCharArray, nBytes);
     567                 :            : 
     568                 :            :     // It is about Binariy Data, a String, that for StarView is to long or
     569                 :            :     // the driver kan't predict the length of the data - as well as save the
     570                 :            :     // MemoryStream.
     571                 :          0 :     while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen)
     572                 :            :     {
     573                 :            :         // At Strings the Buffer won't be completly used
     574                 :            :         // (The last Byte is always a NULL-Byte, however it won't be counted with pcbValue)
     575                 :          0 :         if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen)
     576                 :          0 :             nBytes = pcbValue - nMaxLen;
     577                 :            :         else
     578                 :          0 :             nBytes = nMaxLen;
     579                 :            : 
     580                 :            :         // While there is a "truncation"-Warning, proceed with fetching Data.
     581                 :          0 :         OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
     582                 :            :                                         (SQLUSMALLINT)columnIndex,
     583                 :            :                                         SQL_C_BINARY,
     584                 :            :                                         &aCharArray,
     585                 :            :                                         (SQLINTEGER)nBytes,
     586                 :          0 :                                         &pcbValue),
     587                 :          0 :                             _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
     588                 :          0 :         sal_Int32 nLen = aData.getLength();
     589                 :          0 :         aData.realloc(nLen + nBytes);
     590                 :          0 :         memcpy(aData.getArray() + nLen, aCharArray, nBytes);
     591                 :            :     }
     592                 :          0 :     return aData;
     593                 :            : }
     594                 :            : // -------------------------------------------------------------------------
     595                 :          0 : ::rtl::OUString OTools::getStringValue(OConnection* _pConnection,
     596                 :            :                                        SQLHANDLE _aStatementHandle,
     597                 :            :                                        sal_Int32 columnIndex,
     598                 :            :                                        SQLSMALLINT _fSqlType,
     599                 :            :                                        sal_Bool &_bWasNull,
     600                 :            :                                        const Reference< XInterface >& _xInterface,
     601                 :            :                                        rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
     602                 :            : {
     603                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getStringValue" );
     604                 :          0 :     ::rtl::OUStringBuffer aData;
     605                 :          0 :     switch(_fSqlType)
     606                 :            :     {
     607                 :            :     case SQL_WVARCHAR:
     608                 :            :     case SQL_WCHAR:
     609                 :            :     case SQL_WLONGVARCHAR:
     610                 :            :         {
     611                 :            :             sal_Unicode waCharArray[2048];
     612                 :            :             // read the unicode data
     613                 :          0 :             SQLLEN nMaxLen = (sizeof(waCharArray) / sizeof(sal_Unicode)) - 1;
     614                 :            : 
     615                 :          0 :             SQLLEN pcbValue=0;
     616                 :          0 :             OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
     617                 :            :                                                 (SQLUSMALLINT)columnIndex,
     618                 :            :                                                 SQL_C_WCHAR,
     619                 :            :                                                 &waCharArray,
     620                 :            :                                                 (SQLLEN)nMaxLen*sizeof(sal_Unicode),
     621                 :          0 :                                                 &pcbValue),
     622                 :          0 :                                     _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
     623                 :          0 :             _bWasNull = pcbValue == SQL_NULL_DATA;
     624                 :          0 :             if(_bWasNull)
     625                 :          0 :                 return ::rtl::OUString();
     626                 :            :             // at failure the GETDATA-Makro will stop with returning,
     627                 :            :             // at NULL with break!
     628                 :          0 :             SQLLEN nRealSize = 0;
     629                 :          0 :             if ( pcbValue > -1 )
     630                 :          0 :                 nRealSize = pcbValue / sizeof(sal_Unicode);
     631                 :          0 :             SQLLEN nLen = pcbValue != SQL_NO_TOTAL ? std::min(nRealSize, nMaxLen) : (nMaxLen-1);
     632                 :          0 :             waCharArray[nLen] = 0;
     633                 :          0 :             aData.append(waCharArray,nLen);
     634                 :            : 
     635                 :            :             // It is about Binariy Data, a String, that for StarView is to long or
     636                 :            :             // the driver kan't predict the length of the data - as well as save the
     637                 :            :             // MemoryStream.
     638                 :          0 :             while ((pcbValue == SQL_NO_TOTAL ) || nLen > nMaxLen)
     639                 :            :             {
     640                 :            :                 // At Strings the Buffer won't be completly used
     641                 :            :                 // (The last Byte is always a NULL-Byte, however it won't be counted with pcbValue)
     642                 :          0 :                 if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen)
     643                 :          0 :                     nLen = pcbValue - nMaxLen;
     644                 :            :                 else
     645                 :          0 :                     nLen = nMaxLen;
     646                 :            : 
     647                 :            :                 // While there is a "truncation"-Warning, proceed with fetching Data.
     648                 :          0 :                 OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
     649                 :            :                                                 (SQLUSMALLINT)columnIndex,
     650                 :            :                                                 SQL_C_WCHAR,
     651                 :            :                                                 &waCharArray,
     652                 :            :                                                 (SQLLEN)nLen+1,
     653                 :          0 :                                                 &pcbValue),
     654                 :          0 :                                     _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
     655                 :          0 :                 nRealSize = 0;
     656                 :          0 :                 if ( pcbValue > -1 )
     657                 :          0 :                     nRealSize = pcbValue / sizeof(sal_Unicode);
     658                 :          0 :                 nLen = pcbValue != SQL_NO_TOTAL ? std::min(nRealSize, nMaxLen) : (nMaxLen-1);
     659                 :          0 :                 waCharArray[nLen] = 0;
     660                 :            : 
     661                 :          0 :                 aData.append(::rtl::OUString(waCharArray));
     662                 :            :             }
     663                 :            :         }
     664                 :          0 :         break;
     665                 :            :         default:
     666                 :            :         {
     667                 :            :             char aCharArray[2048];
     668                 :            :             // First try to fetch the data with the little Buffer:
     669                 :          0 :             SQLLEN nMaxLen = sizeof aCharArray - 1;
     670                 :          0 :             SQLLEN pcbValue = 0;
     671                 :          0 :             OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
     672                 :            :                                                 (SQLUSMALLINT)columnIndex,
     673                 :            :                                                 SQL_C_CHAR,
     674                 :            :                                                 &aCharArray,
     675                 :            :                                                 nMaxLen,
     676                 :          0 :                                                 &pcbValue),
     677                 :          0 :                                     _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
     678                 :          0 :             _bWasNull = pcbValue == SQL_NULL_DATA;
     679                 :          0 :             if(_bWasNull)
     680                 :          0 :                 return ::rtl::OUString();
     681                 :            : 
     682                 :          0 :             SQLLEN nLen = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : (nMaxLen-1);
     683                 :          0 :             aCharArray[nLen] = 0;
     684                 :          0 :             if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nLen-1] == 0 && nLen > 0 )
     685                 :          0 :                 --nLen;
     686                 :          0 :             aData.append(::rtl::OUString((const sal_Char*)aCharArray,nLen, _nTextEncoding));
     687                 :            : 
     688                 :            :             // It is about Binary Data, a String, that for StarView is too long or
     689                 :            :             // the driver can't predict the length of the data - as well as save the
     690                 :            :             // MemoryStream.
     691                 :          0 :             while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen)
     692                 :            :             {
     693                 :            :                 // While there is a "truncation"-Warning, proceed with fetching Data.
     694                 :          0 :                 OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
     695                 :            :                                                 (SQLUSMALLINT)columnIndex,
     696                 :            :                                                 SQL_C_CHAR,
     697                 :            :                                                 &aCharArray,
     698                 :            :                                                 (SQLINTEGER)nMaxLen,
     699                 :          0 :                                                 &pcbValue),
     700                 :          0 :                                     _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
     701                 :          0 :                 nLen = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : (nMaxLen-1);
     702                 :          0 :                 if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nLen-1] == 0 && nLen > 0 )
     703                 :          0 :                     --nLen;
     704                 :          0 :                 aCharArray[nLen] = 0;
     705                 :            : 
     706                 :          0 :                 aData.append(::rtl::OUString((const sal_Char*)aCharArray,nLen,_nTextEncoding));
     707                 :            :             }
     708                 :            : 
     709                 :            :         }
     710                 :            :     }
     711                 :            : 
     712                 :          0 :     return aData.makeStringAndClear();
     713                 :            : }
     714                 :            : // -------------------------------------------------------------------------
     715                 :          0 : void OTools::GetInfo(OConnection* _pConnection,
     716                 :            :                      SQLHANDLE _aConnectionHandle,
     717                 :            :                      SQLUSMALLINT _nInfo,
     718                 :            :                      ::rtl::OUString &_rValue,
     719                 :            :                      const Reference< XInterface >& _xInterface,
     720                 :            :                      rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
     721                 :            : {
     722                 :            :     char aValue[512];
     723                 :          0 :     SQLSMALLINT nValueLen=0;
     724                 :            :     OTools::ThrowException(_pConnection,
     725                 :          0 :         (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,aValue,(sizeof aValue)-1,&nValueLen),
     726                 :          0 :         _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
     727                 :            : 
     728                 :          0 :     _rValue = ::rtl::OUString(aValue,nValueLen,_nTextEncoding);
     729                 :          0 : }
     730                 :            : // -------------------------------------------------------------------------
     731                 :          0 : void OTools::GetInfo(OConnection* _pConnection,
     732                 :            :                      SQLHANDLE _aConnectionHandle,
     733                 :            :                      SQLUSMALLINT _nInfo,
     734                 :            :                      sal_Int32 &_rValue,
     735                 :            :                      const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
     736                 :            : {
     737                 :            :     SQLSMALLINT nValueLen;
     738                 :          0 :     _rValue = 0;    // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
     739                 :            :     OTools::ThrowException(_pConnection,
     740                 :          0 :         (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
     741                 :          0 :         _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
     742                 :          0 : }
     743                 :            : // -------------------------------------------------------------------------
     744                 :          0 : void OTools::GetInfo(OConnection* _pConnection,
     745                 :            :                      SQLHANDLE _aConnectionHandle,
     746                 :            :                      SQLUSMALLINT _nInfo,
     747                 :            :                      SQLUINTEGER &_rValue,
     748                 :            :                      const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
     749                 :            : {
     750                 :            :     SQLSMALLINT nValueLen;
     751                 :          0 :     _rValue = 0;    // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
     752                 :            :     OTools::ThrowException(_pConnection,
     753                 :          0 :         (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
     754                 :          0 :         _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
     755                 :          0 : }
     756                 :            : // -------------------------------------------------------------------------
     757                 :          0 : void OTools::GetInfo(OConnection* _pConnection,
     758                 :            :                      SQLHANDLE _aConnectionHandle,
     759                 :            :                      SQLUSMALLINT _nInfo,
     760                 :            :                      SQLUSMALLINT &_rValue,
     761                 :            :                      const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
     762                 :            : {
     763                 :            :     SQLSMALLINT nValueLen;
     764                 :          0 :     _rValue = 0;    // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
     765                 :            :     OTools::ThrowException(_pConnection,
     766                 :          0 :         (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
     767                 :          0 :         _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
     768                 :          0 : }
     769                 :            : // -------------------------------------------------------------------------
     770                 :          0 : void OTools::GetInfo(OConnection* _pConnection,
     771                 :            :                      SQLHANDLE _aConnectionHandle,
     772                 :            :                      SQLUSMALLINT _nInfo,
     773                 :            :                      sal_Bool &_rValue,
     774                 :            :                      const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
     775                 :            : {
     776                 :            :     SQLSMALLINT nValueLen;
     777                 :            :     OTools::ThrowException(_pConnection,
     778                 :          0 :                             (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
     779                 :          0 :                             _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
     780                 :          0 : }
     781                 :            : // -------------------------------------------------------------------------
     782                 :          0 : sal_Int32 OTools::MapOdbcType2Jdbc(sal_Int32 _nType)
     783                 :            : {
     784                 :          0 :     sal_Int32 nValue = DataType::VARCHAR;
     785                 :          0 :     switch(_nType)
     786                 :            :     {
     787                 :            :         case SQL_BIT:
     788                 :          0 :             nValue = DataType::BIT;
     789                 :          0 :             break;
     790                 :            :         case SQL_TINYINT:
     791                 :          0 :             nValue = DataType::TINYINT;
     792                 :          0 :             break;
     793                 :            :         case SQL_SMALLINT:
     794                 :          0 :             nValue = DataType::SMALLINT;
     795                 :          0 :             break;
     796                 :            :         case SQL_INTEGER:
     797                 :          0 :             nValue = DataType::INTEGER;
     798                 :          0 :             break;
     799                 :            :         case SQL_BIGINT:
     800                 :          0 :             nValue = DataType::BIGINT;
     801                 :          0 :             break;
     802                 :            :         case SQL_FLOAT:
     803                 :          0 :             nValue = DataType::FLOAT;
     804                 :          0 :             break;
     805                 :            :         case SQL_REAL:
     806                 :          0 :             nValue = DataType::REAL;
     807                 :          0 :             break;
     808                 :            :         case SQL_DOUBLE:
     809                 :          0 :             nValue = DataType::DOUBLE;
     810                 :          0 :             break;
     811                 :            :         case SQL_NUMERIC:
     812                 :          0 :             nValue = DataType::NUMERIC;
     813                 :          0 :             break;
     814                 :            :         case SQL_DECIMAL:
     815                 :          0 :             nValue = DataType::DECIMAL;
     816                 :          0 :             break;
     817                 :            :         case SQL_WCHAR:
     818                 :            :         case SQL_CHAR:
     819                 :          0 :             nValue = DataType::CHAR;
     820                 :          0 :             break;
     821                 :            :         case SQL_WVARCHAR:
     822                 :            :         case SQL_VARCHAR:
     823                 :          0 :             nValue = DataType::VARCHAR;
     824                 :          0 :             break;
     825                 :            :         case SQL_WLONGVARCHAR:
     826                 :            :         case SQL_LONGVARCHAR:
     827                 :          0 :             nValue = DataType::LONGVARCHAR;
     828                 :          0 :             break;
     829                 :            :         case SQL_TYPE_DATE:
     830                 :            :         case SQL_DATE:
     831                 :          0 :             nValue = DataType::DATE;
     832                 :          0 :             break;
     833                 :            :         case SQL_TYPE_TIME:
     834                 :            :         case SQL_TIME:
     835                 :          0 :             nValue = DataType::TIME;
     836                 :          0 :             break;
     837                 :            :         case SQL_TYPE_TIMESTAMP:
     838                 :            :         case SQL_TIMESTAMP:
     839                 :          0 :             nValue = DataType::TIMESTAMP;
     840                 :          0 :             break;
     841                 :            :         case SQL_BINARY:
     842                 :          0 :             nValue = DataType::BINARY;
     843                 :          0 :             break;
     844                 :            :         case SQL_VARBINARY:
     845                 :            :         case SQL_GUID:
     846                 :          0 :             nValue = DataType::VARBINARY;
     847                 :          0 :             break;
     848                 :            :         case SQL_LONGVARBINARY:
     849                 :          0 :             nValue = DataType::LONGVARBINARY;
     850                 :          0 :             break;
     851                 :            :         default:
     852                 :            :             OSL_ASSERT(!"Invalid type");
     853                 :            :     }
     854                 :          0 :     return nValue;
     855                 :            : }
     856                 :            : //--------------------------------------------------------------------
     857                 :            : // jdbcTypeToOdbc
     858                 :            : // Convert the JDBC SQL type to the correct ODBC type
     859                 :            : //--------------------------------------------------------------------
     860                 :          0 : sal_Int32 OTools::jdbcTypeToOdbc(sal_Int32 jdbcType)
     861                 :            : {
     862                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::jdbcTypeToOdbc" );
     863                 :            :     // For the most part, JDBC types match ODBC types.  We'll
     864                 :            :     // just convert the ones that we know are different
     865                 :            : 
     866                 :          0 :     sal_Int32 odbcType = jdbcType;
     867                 :            : 
     868                 :          0 :     switch (jdbcType)
     869                 :            :     {
     870                 :            :     case DataType::DATE:
     871                 :          0 :         odbcType = SQL_DATE;
     872                 :          0 :         break;
     873                 :            :     case DataType::TIME:
     874                 :          0 :         odbcType = SQL_TIME;
     875                 :          0 :         break;
     876                 :            :     case DataType::TIMESTAMP:
     877                 :          0 :         odbcType = SQL_TIMESTAMP;
     878                 :          0 :         break;
     879                 :            :     }
     880                 :            : 
     881                 :          0 :     return odbcType;
     882                 :            : }
     883                 :            : //-----------------------------------------------------------------------------
     884                 :          0 : void OTools::getBindTypes(sal_Bool _bUseWChar,
     885                 :            :                           sal_Bool _bUseOldTimeDate,
     886                 :            :                           SQLSMALLINT _nOdbcType,
     887                 :            :                           SQLSMALLINT& fCType,
     888                 :            :                           SQLSMALLINT& fSqlType
     889                 :            :                           )
     890                 :            : {
     891                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getBindTypes" );
     892                 :          0 :     switch(_nOdbcType)
     893                 :            :     {
     894                 :          0 :         case SQL_CHAR:              if(_bUseWChar)
     895                 :            :                                     {
     896                 :          0 :                                         fCType   = SQL_C_WCHAR;
     897                 :          0 :                                         fSqlType = SQL_WCHAR;
     898                 :            :                                     }
     899                 :            :                                     else
     900                 :            :                                     {
     901                 :          0 :                                         fCType   = SQL_C_CHAR;
     902                 :          0 :                                         fSqlType = SQL_CHAR;
     903                 :            :                                     }
     904                 :          0 :                                     break;
     905                 :          0 :         case SQL_VARCHAR:           if(_bUseWChar)
     906                 :            :                                     {
     907                 :          0 :                                         fCType   = SQL_C_WCHAR;
     908                 :          0 :                                         fSqlType = SQL_WVARCHAR;
     909                 :            :                                     }
     910                 :            :                                     else
     911                 :            :                                     {
     912                 :          0 :                                         fCType   = SQL_C_CHAR;
     913                 :          0 :                                         fSqlType = SQL_VARCHAR;
     914                 :            :                                     }
     915                 :          0 :                                     break;
     916                 :          0 :         case SQL_LONGVARCHAR:       if(_bUseWChar)
     917                 :            :                                     {
     918                 :          0 :                                         fCType   = SQL_C_WCHAR;
     919                 :          0 :                                         fSqlType = SQL_WLONGVARCHAR;
     920                 :            :                                     }
     921                 :            :                                     else
     922                 :            :                                     {
     923                 :          0 :                                         fCType   = SQL_C_CHAR;
     924                 :          0 :                                         fSqlType = SQL_LONGVARCHAR;
     925                 :            :                                     }
     926                 :          0 :                                     break;
     927                 :          0 :         case SQL_DECIMAL:           fCType      = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR;
     928                 :          0 :                                     fSqlType    = SQL_DECIMAL; break;
     929                 :          0 :         case SQL_NUMERIC:           fCType      = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR;
     930                 :          0 :                                     fSqlType    = SQL_NUMERIC; break;
     931                 :          0 :         case SQL_BIT:               fCType      = SQL_C_TINYINT;
     932                 :          0 :                                     fSqlType    = SQL_INTEGER; break;
     933                 :          0 :         case SQL_TINYINT:           fCType      = SQL_C_TINYINT;
     934                 :          0 :                                     fSqlType    = SQL_TINYINT; break;
     935                 :          0 :         case SQL_SMALLINT:          fCType      = SQL_C_SHORT;
     936                 :          0 :                                     fSqlType    = SQL_SMALLINT; break;
     937                 :          0 :         case SQL_INTEGER:           fCType      = SQL_C_LONG;
     938                 :          0 :                                     fSqlType    = SQL_INTEGER; break;
     939                 :          0 :         case SQL_BIGINT:            fCType      = SQL_C_SBIGINT;
     940                 :          0 :                                     fSqlType    = SQL_BIGINT; break;
     941                 :          0 :         case SQL_FLOAT:             fCType      = SQL_C_FLOAT;
     942                 :          0 :                                     fSqlType    = SQL_FLOAT; break;
     943                 :          0 :         case SQL_REAL:              fCType      = SQL_C_DOUBLE;
     944                 :          0 :                                     fSqlType    = SQL_REAL; break;
     945                 :          0 :         case SQL_DOUBLE:            fCType      = SQL_C_DOUBLE;
     946                 :          0 :                                     fSqlType    = SQL_DOUBLE; break;
     947                 :          0 :         case SQL_BINARY:            fCType      = SQL_C_BINARY;
     948                 :          0 :                                     fSqlType    = SQL_BINARY; break;
     949                 :            :         case SQL_VARBINARY:
     950                 :          0 :                                     fCType      = SQL_C_BINARY;
     951                 :          0 :                                     fSqlType    = SQL_VARBINARY; break;
     952                 :          0 :         case SQL_LONGVARBINARY:     fCType      = SQL_C_BINARY;
     953                 :          0 :                                     fSqlType    = SQL_LONGVARBINARY; break;
     954                 :            :         case SQL_DATE:
     955                 :          0 :                                     if(_bUseOldTimeDate)
     956                 :            :                                     {
     957                 :          0 :                                         fCType      = SQL_C_DATE;
     958                 :          0 :                                         fSqlType    = SQL_DATE;
     959                 :            :                                     }
     960                 :            :                                     else
     961                 :            :                                     {
     962                 :          0 :                                         fCType      = SQL_C_TYPE_DATE;
     963                 :          0 :                                         fSqlType    = SQL_TYPE_DATE;
     964                 :            :                                     }
     965                 :          0 :                                     break;
     966                 :            :         case SQL_TIME:
     967                 :          0 :                                     if(_bUseOldTimeDate)
     968                 :            :                                     {
     969                 :          0 :                                         fCType      = SQL_C_TIME;
     970                 :          0 :                                         fSqlType    = SQL_TIME;
     971                 :            :                                     }
     972                 :            :                                     else
     973                 :            :                                     {
     974                 :          0 :                                         fCType      = SQL_C_TYPE_TIME;
     975                 :          0 :                                         fSqlType    = SQL_TYPE_TIME;
     976                 :            :                                     }
     977                 :          0 :                                     break;
     978                 :            :         case SQL_TIMESTAMP:
     979                 :          0 :                                     if(_bUseOldTimeDate)
     980                 :            :                                     {
     981                 :          0 :                                         fCType      = SQL_C_TIMESTAMP;
     982                 :          0 :                                         fSqlType    = SQL_TIMESTAMP;
     983                 :            :                                     }
     984                 :            :                                     else
     985                 :            :                                     {
     986                 :          0 :                                         fCType      = SQL_C_TYPE_TIMESTAMP;
     987                 :          0 :                                         fSqlType    = SQL_TYPE_TIMESTAMP;
     988                 :            :                                     }
     989                 :          0 :                                     break;
     990                 :          0 :         default:                        fCType      = SQL_C_BINARY;
     991                 :          0 :                                         fSqlType    = SQL_LONGVARBINARY; break;
     992                 :            :     }
     993                 :          0 : }
     994                 :            : 
     995                 :            : 
     996                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10