2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-12 22:04:38 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
#include "odbc/OTools.hxx"
|
|
|
|
#include "odbc/OFunctions.hxx"
|
|
|
|
#include <com/sun/star/sdbc/DataType.hpp>
|
|
|
|
#include <osl/diagnose.h>
|
2001-05-15 07:18:32 +00:00
|
|
|
#include "odbc/OConnection.hxx"
|
2006-06-20 00:56:53 +00:00
|
|
|
#include "diagnose_ex.h"
|
2009-07-03 12:24:35 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2012-12-05 06:07:11 +01:00
|
|
|
#include <boost/static_assert.hpp>
|
2009-07-03 12:24:35 +00:00
|
|
|
|
2006-06-20 00:56:53 +00:00
|
|
|
|
2008-08-27 12:35:52 +00:00
|
|
|
#include <string.h>
|
2006-06-20 00:56:53 +00:00
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
using namespace connectivity::odbc;
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::sdbc;
|
|
|
|
using namespace com::sun::star::util;
|
2000-11-06 16:26:32 +00:00
|
|
|
|
2012-01-24 22:20:31 +01:00
|
|
|
namespace {
|
|
|
|
size_t sqlTypeLen ( SQLSMALLINT _nType )
|
|
|
|
{
|
|
|
|
switch (_nType)
|
|
|
|
{
|
|
|
|
case SQL_C_SSHORT:
|
|
|
|
case SQL_C_SHORT:
|
|
|
|
return sizeof(SQLSMALLINT);
|
|
|
|
case SQL_C_USHORT:
|
|
|
|
return sizeof(SQLUSMALLINT);
|
|
|
|
case SQL_C_SLONG:
|
|
|
|
case SQL_C_LONG:
|
|
|
|
return sizeof(SQLINTEGER);
|
|
|
|
case SQL_C_ULONG:
|
|
|
|
return sizeof(SQLUINTEGER);
|
|
|
|
case SQL_C_FLOAT:
|
|
|
|
return sizeof(SQLREAL);
|
|
|
|
case SQL_C_DOUBLE:
|
|
|
|
OSL_ENSURE(sizeof(SQLDOUBLE) == sizeof(SQLFLOAT), "SQLDOUBLE/SQLFLOAT confusion");
|
|
|
|
return sizeof(SQLDOUBLE);
|
|
|
|
case SQL_C_BIT:
|
|
|
|
return sizeof(SQLCHAR);
|
|
|
|
case SQL_C_STINYINT:
|
|
|
|
case SQL_C_TINYINT:
|
|
|
|
return sizeof(SQLSCHAR);
|
|
|
|
case SQL_C_UTINYINT:
|
|
|
|
return sizeof(SQLCHAR);
|
|
|
|
case SQL_C_SBIGINT:
|
|
|
|
return sizeof(SQLBIGINT);
|
|
|
|
case SQL_C_UBIGINT:
|
|
|
|
return sizeof(SQLUBIGINT);
|
|
|
|
/* UnixODBC gives this the same value as SQL_C_UBIGINT
|
|
|
|
case SQL_C_BOOKMARK:
|
|
|
|
return sizeof(BOOKMARK); */
|
|
|
|
case SQL_C_TYPE_DATE:
|
|
|
|
case SQL_C_DATE:
|
|
|
|
return sizeof(SQL_DATE_STRUCT);
|
|
|
|
case SQL_C_TYPE_TIME:
|
|
|
|
case SQL_C_TIME:
|
|
|
|
return sizeof(SQL_TIME_STRUCT);
|
|
|
|
case SQL_C_TYPE_TIMESTAMP:
|
|
|
|
case SQL_C_TIMESTAMP:
|
|
|
|
return sizeof(SQL_TIMESTAMP_STRUCT);
|
|
|
|
case SQL_C_NUMERIC:
|
|
|
|
return sizeof(SQL_NUMERIC_STRUCT);
|
|
|
|
case SQL_C_GUID:
|
|
|
|
return sizeof(SQLGUID);
|
|
|
|
case SQL_C_INTERVAL_YEAR:
|
|
|
|
case SQL_C_INTERVAL_MONTH:
|
|
|
|
case SQL_C_INTERVAL_DAY:
|
|
|
|
case SQL_C_INTERVAL_HOUR:
|
|
|
|
case SQL_C_INTERVAL_MINUTE:
|
|
|
|
case SQL_C_INTERVAL_SECOND:
|
|
|
|
case SQL_C_INTERVAL_YEAR_TO_MONTH:
|
|
|
|
case SQL_C_INTERVAL_DAY_TO_HOUR:
|
|
|
|
case SQL_C_INTERVAL_DAY_TO_MINUTE:
|
|
|
|
case SQL_C_INTERVAL_DAY_TO_SECOND:
|
|
|
|
case SQL_C_INTERVAL_HOUR_TO_MINUTE:
|
|
|
|
case SQL_C_INTERVAL_HOUR_TO_SECOND:
|
|
|
|
case SQL_C_INTERVAL_MINUTE_TO_SECOND:
|
|
|
|
return sizeof(SQL_INTERVAL_STRUCT);
|
2012-12-05 06:00:52 +01:00
|
|
|
// ** Variable-sized datatypes -> cannot predict length
|
|
|
|
case SQL_C_CHAR:
|
|
|
|
case SQL_C_WCHAR:
|
|
|
|
case SQL_C_BINARY:
|
|
|
|
// UnixODBC gives this the same value as SQL_C_BINARY
|
|
|
|
//case SQL_C_VARBOOKMARK:
|
|
|
|
// Unknown datatype -> cannot predict length
|
2012-01-24 22:20:31 +01:00
|
|
|
default:
|
|
|
|
return static_cast<size_t>(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-15 07:18:32 +00:00
|
|
|
void OTools::getValue( OConnection* _pConnection,
|
|
|
|
SQLHANDLE _aStatementHandle,
|
|
|
|
sal_Int32 columnIndex,
|
|
|
|
SQLSMALLINT _nType,
|
|
|
|
sal_Bool &_bWasNull,
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
|
|
|
|
void* _pValue,
|
2009-10-01 09:16:17 +00:00
|
|
|
SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
|
2001-05-14 10:42:44 +00:00
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OTools::getValue" );
|
2012-01-24 22:20:31 +01:00
|
|
|
const size_t properSize = sqlTypeLen(_nType);
|
|
|
|
if ( properSize == static_cast<size_t>(-1) )
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_WARN( "connectivity.drivers", "connectivity::odbc::OTools::getValue: unknown SQL type - cannot check buffer size");
|
2012-01-24 22:20:31 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ENSURE(static_cast<size_t>(_nSize) == properSize, "connectivity::odbc::OTools::getValue got wrongly sized memory region to write result to");
|
|
|
|
if ( static_cast<size_t>(_nSize) > properSize )
|
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_WARN( "connectivity.drivers", "memory region is too big - trying to fudge it");
|
2012-01-24 22:20:31 +01:00
|
|
|
memset(_pValue, 0, _nSize);
|
|
|
|
#ifdef OSL_BIGENDIAN
|
|
|
|
// This is skewed in favour of integer types
|
|
|
|
_pValue += _nSize - properSize;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OSL_ENSURE(static_cast<size_t>(_nSize) >= properSize, "memory region is too small");
|
2009-10-01 09:16:17 +00:00
|
|
|
SQLLEN pcbValue = SQL_NULL_DATA;
|
2001-05-15 07:18:32 +00:00
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
|
2001-05-14 10:42:44 +00:00
|
|
|
(SQLUSMALLINT)columnIndex,
|
|
|
|
_nType,
|
|
|
|
_pValue,
|
2009-10-01 09:16:17 +00:00
|
|
|
_nSize,
|
2001-05-14 10:42:44 +00:00
|
|
|
&pcbValue),
|
|
|
|
_aStatementHandle,SQL_HANDLE_STMT,_xInterface,sal_False);
|
|
|
|
_bWasNull = pcbValue == SQL_NULL_DATA;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
// -------------------------------------------------------------------------
|
2001-05-15 07:18:32 +00:00
|
|
|
void OTools::bindValue( OConnection* _pConnection,
|
|
|
|
SQLHANDLE _aStatementHandle,
|
|
|
|
sal_Int32 columnIndex,
|
|
|
|
SQLSMALLINT _nType,
|
|
|
|
SQLSMALLINT _nMaxLen,
|
|
|
|
const void* _pValue,
|
|
|
|
void* _pData,
|
2012-10-26 18:57:34 +02:00
|
|
|
SQLLEN * const pLen,
|
2001-05-15 07:18:32 +00:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
|
2001-05-21 13:30:34 +00:00
|
|
|
rtl_TextEncoding _nTextEncoding,
|
|
|
|
sal_Bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
|
2001-05-14 10:42:44 +00:00
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OTools::bindValue" );
|
2001-05-14 10:42:44 +00:00
|
|
|
SQLRETURN nRetcode;
|
2001-11-30 13:09:45 +00:00
|
|
|
SQLSMALLINT fSqlType;
|
|
|
|
SQLSMALLINT fCType;
|
2009-10-01 09:16:17 +00:00
|
|
|
SQLLEN nMaxLen = _nMaxLen;
|
2001-05-14 10:42:44 +00:00
|
|
|
|
2001-11-30 13:09:45 +00:00
|
|
|
OTools::getBindTypes( sal_False,
|
|
|
|
_bUseOldTimeDate,
|
|
|
|
_nType,
|
|
|
|
fCType,
|
|
|
|
fSqlType);
|
2001-05-14 10:42:44 +00:00
|
|
|
|
|
|
|
if (columnIndex != 0 && !_pValue)
|
|
|
|
{
|
|
|
|
*pLen = SQL_NULL_DATA;
|
2001-05-15 07:18:32 +00:00
|
|
|
nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle,
|
2006-06-20 00:56:53 +00:00
|
|
|
(SQLUSMALLINT)columnIndex,
|
2001-05-14 10:42:44 +00:00
|
|
|
fCType,
|
|
|
|
_pData,
|
2001-11-30 13:09:45 +00:00
|
|
|
nMaxLen,
|
2001-05-14 10:42:44 +00:00
|
|
|
pLen
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
switch (_nType)
|
|
|
|
{
|
|
|
|
case SQL_CHAR:
|
|
|
|
case SQL_VARCHAR:
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aString(OUStringToOString(*(OUString*)_pValue,_nTextEncoding));
|
2001-05-14 10:42:44 +00:00
|
|
|
*pLen = SQL_NTS;
|
2013-04-07 12:06:47 +02:00
|
|
|
*((OString*)_pData) = aString;
|
2006-06-20 00:56:53 +00:00
|
|
|
_nMaxLen = (SQLSMALLINT)aString.getLength();
|
2001-05-14 10:42:44 +00:00
|
|
|
|
2011-03-23 23:16:24 +01:00
|
|
|
// Pointer on Char*
|
2001-05-14 10:42:44 +00:00
|
|
|
_pData = (void*)aString.getStr();
|
|
|
|
} break;
|
|
|
|
case SQL_BIGINT:
|
2001-09-20 11:51:56 +00:00
|
|
|
*((sal_Int64*)_pData) = *(sal_Int64*)_pValue;
|
|
|
|
*pLen = sizeof(sal_Int64);
|
|
|
|
break;
|
2001-05-14 10:42:44 +00:00
|
|
|
case SQL_DECIMAL:
|
|
|
|
case SQL_NUMERIC:
|
|
|
|
{
|
2013-08-21 15:07:31 +02:00
|
|
|
OString aString = OString::number(*(double*)_pValue);
|
2006-06-20 00:56:53 +00:00
|
|
|
_nMaxLen = (SQLSMALLINT)aString.getLength();
|
2001-05-14 10:42:44 +00:00
|
|
|
*pLen = _nMaxLen;
|
2013-04-07 12:06:47 +02:00
|
|
|
*((OString*)_pData) = aString;
|
2011-03-23 23:16:24 +01:00
|
|
|
// Pointer on Char*
|
2013-04-07 12:06:47 +02:00
|
|
|
_pData = (void*)((OString*)_pData)->getStr();
|
2001-05-14 10:42:44 +00:00
|
|
|
} break;
|
|
|
|
case SQL_BIT:
|
2003-09-04 07:27:21 +00:00
|
|
|
case SQL_TINYINT:
|
2001-05-14 10:42:44 +00:00
|
|
|
*((sal_Int8*)_pData) = *(sal_Int8*)_pValue;
|
|
|
|
*pLen = sizeof(sal_Int8);
|
|
|
|
break;
|
2003-09-04 07:27:21 +00:00
|
|
|
|
2001-05-14 10:42:44 +00:00
|
|
|
case SQL_SMALLINT:
|
|
|
|
*((sal_Int16*)_pData) = *(sal_Int16*)_pValue;
|
|
|
|
*pLen = sizeof(sal_Int16);
|
|
|
|
break;
|
|
|
|
case SQL_INTEGER:
|
|
|
|
*((sal_Int32*)_pData) = *(sal_Int32*)_pValue;
|
|
|
|
*pLen = sizeof(sal_Int32);
|
|
|
|
break;
|
2002-07-01 06:03:25 +00:00
|
|
|
case SQL_FLOAT:
|
2001-05-14 10:42:44 +00:00
|
|
|
*((float*)_pData) = *(float*)_pValue;
|
|
|
|
*pLen = sizeof(float);
|
|
|
|
break;
|
2006-01-03 15:04:35 +00:00
|
|
|
case SQL_REAL:
|
2001-05-14 10:42:44 +00:00
|
|
|
case SQL_DOUBLE:
|
|
|
|
*((double*)_pData) = *(double*)_pValue;
|
|
|
|
*pLen = sizeof(double);
|
|
|
|
break;
|
|
|
|
case SQL_BINARY:
|
|
|
|
case SQL_VARBINARY:
|
|
|
|
{
|
|
|
|
_pData = (void*)((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getConstArray();
|
|
|
|
*pLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
|
|
|
|
} break;
|
|
|
|
case SQL_LONGVARBINARY:
|
|
|
|
{
|
2011-01-28 09:17:16 +00:00
|
|
|
_pData = (void*)(sal_IntPtr)(columnIndex);
|
2001-05-14 10:42:44 +00:00
|
|
|
sal_Int32 nLen = 0;
|
|
|
|
nLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
|
2009-10-01 09:16:17 +00:00
|
|
|
*pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
|
2001-05-14 10:42:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQL_LONGVARCHAR:
|
|
|
|
{
|
2011-01-28 09:17:16 +00:00
|
|
|
_pData = (void*)(sal_IntPtr)(columnIndex);
|
2001-05-14 10:42:44 +00:00
|
|
|
sal_Int32 nLen = 0;
|
2013-04-07 12:06:47 +02:00
|
|
|
nLen = ((OUString*)_pValue)->getLength();
|
2009-10-01 09:16:17 +00:00
|
|
|
*pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
|
2001-05-14 10:42:44 +00:00
|
|
|
} break;
|
|
|
|
case SQL_DATE:
|
|
|
|
*pLen = sizeof(DATE_STRUCT);
|
|
|
|
*((DATE_STRUCT*)_pData) = *(DATE_STRUCT*)_pValue;
|
|
|
|
break;
|
|
|
|
case SQL_TIME:
|
|
|
|
*pLen = sizeof(TIME_STRUCT);
|
|
|
|
*((TIME_STRUCT*)_pData) = *(TIME_STRUCT*)_pValue;
|
|
|
|
break;
|
|
|
|
case SQL_TIMESTAMP:
|
|
|
|
*pLen = sizeof(TIMESTAMP_STRUCT);
|
|
|
|
*((TIMESTAMP_STRUCT*)_pData) = *(TIMESTAMP_STRUCT*)_pValue;
|
2010-03-29 21:56:25 +02:00
|
|
|
break;
|
2001-05-14 10:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-15 07:18:32 +00:00
|
|
|
nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle,
|
2006-06-20 00:56:53 +00:00
|
|
|
(SQLUSMALLINT)columnIndex,
|
2001-05-14 10:42:44 +00:00
|
|
|
fCType,
|
|
|
|
_pData,
|
2001-11-30 13:09:45 +00:00
|
|
|
nMaxLen,
|
2001-05-14 10:42:44 +00:00
|
|
|
pLen
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2001-05-15 07:18:32 +00:00
|
|
|
OTools::ThrowException(_pConnection,nRetcode,_aStatementHandle,SQL_HANDLE_STMT,_xInterface);
|
2001-05-14 10:42:44 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2012-12-05 06:04:22 +01:00
|
|
|
void OTools::ThrowException(const OConnection* _pConnection,
|
|
|
|
const SQLRETURN _rRetCode,
|
|
|
|
const SQLHANDLE _pContext,
|
|
|
|
const SQLSMALLINT _nHandleType,
|
2001-05-15 07:18:32 +00:00
|
|
|
const Reference< XInterface >& _xInterface,
|
2012-12-05 06:04:22 +01:00
|
|
|
const sal_Bool _bNoFound,
|
|
|
|
const rtl_TextEncoding _nTextEncoding) throw(SQLException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
switch(_rRetCode)
|
|
|
|
{
|
|
|
|
case SQL_NEED_DATA:
|
|
|
|
case SQL_STILL_EXECUTING:
|
|
|
|
case SQL_SUCCESS:
|
|
|
|
|
|
|
|
case SQL_SUCCESS_WITH_INFO:
|
|
|
|
return;
|
|
|
|
case SQL_NO_DATA_FOUND:
|
|
|
|
if(_bNoFound)
|
|
|
|
return; // no need to throw a exception
|
|
|
|
case SQL_ERROR: break;
|
|
|
|
|
|
|
|
|
2013-06-15 01:56:13 +03:00
|
|
|
case SQL_INVALID_HANDLE: SAL_WARN( "connectivity.drivers", "SdbODBC3_SetStatus: SQL_INVALID_HANDLE");
|
2001-10-08 06:20:00 +00:00
|
|
|
throw SQLException();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 23:16:24 +01:00
|
|
|
// Additional Information on the latest ODBC-functioncall available
|
|
|
|
// SQLError provides this Information.
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OTools::ThrowException" );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
SDB_ODBC_CHAR szSqlState[5];
|
2009-10-01 09:16:17 +00:00
|
|
|
SQLINTEGER pfNativeError;
|
2000-09-18 15:18:56 +00:00
|
|
|
SDB_ODBC_CHAR szErrorMessage[SQL_MAX_MESSAGE_LENGTH];
|
2004-08-02 16:10:31 +00:00
|
|
|
szErrorMessage[0] = '\0';
|
2009-10-01 09:16:17 +00:00
|
|
|
SQLSMALLINT pcbErrorMsg = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2011-03-23 23:16:24 +01:00
|
|
|
// Information for latest operation:
|
|
|
|
// when hstmt != SQL_NULL_HSTMT is (Used from SetStatus in SdbCursor, SdbTable, ...),
|
2013-03-03 17:11:39 +01:00
|
|
|
// then the status of the latest statements will be fetched, without the Status of the last
|
|
|
|
// statements of this connection [what in this case will probably be the same, but the Reference
|
2011-03-23 23:16:24 +01:00
|
|
|
// Manual isn't totally clear in this...].
|
|
|
|
// corresponding for hdbc.
|
2001-05-15 07:18:32 +00:00
|
|
|
SQLRETURN n = (*(T3SQLGetDiagRec)_pConnection->getOdbcFunction(ODBC3SQLGetDiagRec))(_nHandleType,_pContext,1,
|
2000-09-18 15:18:56 +00:00
|
|
|
szSqlState,
|
|
|
|
&pfNativeError,
|
|
|
|
szErrorMessage,sizeof szErrorMessage - 1,&pcbErrorMsg);
|
2006-06-20 00:56:53 +00:00
|
|
|
OSL_UNUSED( n );
|
2001-03-20 15:54:34 +00:00
|
|
|
OSL_ENSURE(n != SQL_INVALID_HANDLE,"SdbODBC3_SetStatus: SQLError returned SQL_INVALID_HANDLE");
|
|
|
|
OSL_ENSURE(n == SQL_SUCCESS || n == SQL_SUCCESS_WITH_INFO || n == SQL_NO_DATA_FOUND || n == SQL_ERROR,"SdbODBC3_SetStatus: SQLError failed");
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2011-03-23 23:16:24 +01:00
|
|
|
// For the Return Code of SQLError see ODBC 2.0 Programmer's Reference Page 287ff
|
2013-04-07 12:06:47 +02:00
|
|
|
throw SQLException( OUString((char *)szErrorMessage,pcbErrorMsg,_nTextEncoding),
|
2000-09-18 15:18:56 +00:00
|
|
|
_xInterface,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString((char *)szSqlState,5,_nTextEncoding),
|
2000-09-18 15:18:56 +00:00
|
|
|
pfNativeError,
|
|
|
|
Any()
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2012-12-05 06:04:22 +01:00
|
|
|
Sequence<sal_Int8> OTools::getBytesValue(const OConnection* _pConnection,
|
|
|
|
const SQLHANDLE _aStatementHandle,
|
|
|
|
const sal_Int32 columnIndex,
|
|
|
|
const SQLSMALLINT _fSqlType,
|
2001-05-15 07:18:32 +00:00
|
|
|
sal_Bool &_bWasNull,
|
|
|
|
const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OTools::getBytesValue" );
|
2012-12-05 06:05:58 +01:00
|
|
|
sal_Int8 aCharArray[2048];
|
2011-03-23 23:16:24 +01:00
|
|
|
// First try to fetch the data with the little Buffer:
|
2012-12-05 06:07:11 +01:00
|
|
|
const SQLLEN nMaxLen = sizeof aCharArray;
|
|
|
|
SQLLEN pcbValue = SQL_NO_TOTAL;
|
|
|
|
Sequence<sal_Int8> aData;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2012-12-25 12:55:59 +01:00
|
|
|
OSL_ENSURE( _fSqlType != SQL_CHAR && _fSqlType != SQL_VARCHAR && _fSqlType != SQL_LONGVARCHAR &&
|
|
|
|
_fSqlType != SQL_WCHAR && _fSqlType != SQL_WVARCHAR && _fSqlType != SQL_WLONGVARCHAR,
|
|
|
|
"connectivity::odbc::OTools::getBytesValue called with character _fSqlType");
|
|
|
|
|
|
|
|
while (pcbValue == SQL_NO_TOTAL || pcbValue > nMaxLen)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-12-05 06:07:11 +01:00
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(
|
|
|
|
_aStatementHandle,
|
|
|
|
(SQLUSMALLINT)columnIndex,
|
|
|
|
_fSqlType,
|
|
|
|
(SQLPOINTER)aCharArray,
|
|
|
|
nMaxLen,
|
|
|
|
&pcbValue),
|
|
|
|
_aStatementHandle,SQL_HANDLE_STMT,_xInterface);
|
|
|
|
|
|
|
|
_bWasNull = pcbValue == SQL_NULL_DATA;
|
|
|
|
if(_bWasNull)
|
|
|
|
return Sequence<sal_Int8>();
|
|
|
|
|
|
|
|
SQLLEN nReadBytes;
|
|
|
|
// After the SQLGetData that wrote out to aCharArray the last byte of the data,
|
|
|
|
// pcbValue will not be SQL_NO_TOTAL -> we have a reliable count
|
|
|
|
if ( (pcbValue == SQL_NO_TOTAL) || (pcbValue >= nMaxLen) )
|
|
|
|
{
|
2012-12-25 12:55:59 +01:00
|
|
|
// we filled the buffer
|
|
|
|
nReadBytes = nMaxLen;
|
2012-12-05 06:07:11 +01:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
else
|
2012-12-05 06:07:11 +01:00
|
|
|
{
|
|
|
|
nReadBytes = pcbValue;
|
|
|
|
}
|
|
|
|
const sal_Int32 nLen = aData.getLength();
|
|
|
|
aData.realloc(nLen + nReadBytes);
|
|
|
|
memcpy(aData.getArray() + nLen, aCharArray, nReadBytes);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return aData;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString OTools::getStringValue(OConnection* _pConnection,
|
2001-05-15 07:18:32 +00:00
|
|
|
SQLHANDLE _aStatementHandle,
|
|
|
|
sal_Int32 columnIndex,
|
2009-10-01 09:16:17 +00:00
|
|
|
SQLSMALLINT _fSqlType,
|
2001-05-15 07:18:32 +00:00
|
|
|
sal_Bool &_bWasNull,
|
|
|
|
const Reference< XInterface >& _xInterface,
|
|
|
|
rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OTools::getStringValue" );
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer aData;
|
2000-09-18 15:18:56 +00:00
|
|
|
switch(_fSqlType)
|
|
|
|
{
|
|
|
|
case SQL_WVARCHAR:
|
|
|
|
case SQL_WCHAR:
|
|
|
|
case SQL_WLONGVARCHAR:
|
2012-12-05 06:07:11 +01:00
|
|
|
{
|
|
|
|
sal_Unicode waCharArray[2048];
|
|
|
|
// we assume everyone (LibO & ODBC) uses UTF-16; see OPreparedStatement::setParameter
|
|
|
|
BOOST_STATIC_ASSERT(sizeof(sal_Unicode) == 2);
|
|
|
|
BOOST_STATIC_ASSERT(sizeof(SQLWCHAR) == 2);
|
2013-04-15 01:27:39 +02:00
|
|
|
BOOST_STATIC_ASSERT(sizeof(waCharArray) % 2 == 0);
|
|
|
|
// Size == number of bytes, Len == number of UTF-16 code units
|
|
|
|
const SQLLEN nMaxSize = sizeof(waCharArray);
|
|
|
|
const SQLLEN nMaxLen = sizeof(waCharArray) / sizeof(sal_Unicode);
|
|
|
|
BOOST_STATIC_ASSERT(nMaxLen * sizeof(sal_Unicode) == nMaxSize);
|
|
|
|
|
2012-12-05 06:07:11 +01:00
|
|
|
// read the unicode data
|
|
|
|
SQLLEN pcbValue = SQL_NO_TOTAL;
|
2013-04-15 01:27:39 +02:00
|
|
|
while ((pcbValue == SQL_NO_TOTAL ) || (pcbValue >= nMaxSize) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-12-05 06:07:11 +01:00
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(
|
|
|
|
_aStatementHandle,
|
|
|
|
(SQLUSMALLINT)columnIndex,
|
|
|
|
SQL_C_WCHAR,
|
|
|
|
&waCharArray,
|
|
|
|
(SQLLEN)nMaxLen*sizeof(sal_Unicode),
|
|
|
|
&pcbValue),
|
|
|
|
_aStatementHandle,SQL_HANDLE_STMT,_xInterface);
|
2000-09-18 15:18:56 +00:00
|
|
|
_bWasNull = pcbValue == SQL_NULL_DATA;
|
|
|
|
if(_bWasNull)
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString();
|
2012-12-05 06:07:11 +01:00
|
|
|
|
|
|
|
SQLLEN nReadChars;
|
2012-12-25 13:04:44 +01:00
|
|
|
OSL_ENSURE( (pcbValue < 0) || (pcbValue % 2 == 0),
|
|
|
|
"ODBC: SQLGetData of SQL_C_WCHAR returned odd number of bytes");
|
2013-04-15 01:27:39 +02:00
|
|
|
if ( (pcbValue == SQL_NO_TOTAL) || (pcbValue >= nMaxSize) )
|
2012-12-05 06:07:11 +01:00
|
|
|
{
|
|
|
|
// we filled the buffer; remove the terminating null character
|
|
|
|
nReadChars = nMaxLen-1;
|
|
|
|
if ( waCharArray[nReadChars] != 0)
|
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_WARN( "connectivity.drivers", "Buggy ODBC driver? Did not null-terminate (variable length) data!");
|
2012-12-05 06:07:11 +01:00
|
|
|
++nReadChars;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-12-25 13:04:44 +01:00
|
|
|
nReadChars = pcbValue/sizeof(sal_Unicode);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2012-12-05 06:07:11 +01:00
|
|
|
|
|
|
|
aData.append(waCharArray, nReadChars);
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-12-05 06:07:11 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
char aCharArray[2048];
|
|
|
|
// read the unicode data
|
|
|
|
const SQLLEN nMaxLen = sizeof(aCharArray);
|
|
|
|
SQLLEN pcbValue = SQL_NO_TOTAL;
|
|
|
|
|
|
|
|
while ((pcbValue == SQL_NO_TOTAL ) || (pcbValue >= nMaxLen) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-12-05 06:07:11 +01:00
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(
|
|
|
|
_aStatementHandle,
|
|
|
|
(SQLUSMALLINT)columnIndex,
|
|
|
|
SQL_C_CHAR,
|
|
|
|
&aCharArray,
|
|
|
|
nMaxLen,
|
|
|
|
&pcbValue),
|
|
|
|
_aStatementHandle,SQL_HANDLE_STMT,_xInterface);
|
2000-09-18 15:18:56 +00:00
|
|
|
_bWasNull = pcbValue == SQL_NULL_DATA;
|
|
|
|
if(_bWasNull)
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2012-12-05 06:07:11 +01:00
|
|
|
SQLLEN nReadChars;
|
|
|
|
if ( (pcbValue == SQL_NO_TOTAL) || (pcbValue >= nMaxLen) )
|
|
|
|
{
|
|
|
|
// we filled the buffer; remove the terminating null character
|
|
|
|
nReadChars = nMaxLen-1;
|
|
|
|
if ( aCharArray[nReadChars] != 0)
|
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_WARN( "connectivity.drivers", "Buggy ODBC driver? Did not null-terminate (variable length) data!");
|
2012-12-05 06:07:11 +01:00
|
|
|
++nReadChars;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-12-05 06:07:11 +01:00
|
|
|
nReadChars = pcbValue;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
aData.append(OUString(aCharArray, nReadChars, _nTextEncoding));
|
2012-12-05 06:07:11 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2012-12-05 06:07:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 12:24:35 +00:00
|
|
|
return aData.makeStringAndClear();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-05-15 07:18:32 +00:00
|
|
|
void OTools::GetInfo(OConnection* _pConnection,
|
|
|
|
SQLHANDLE _aConnectionHandle,
|
|
|
|
SQLUSMALLINT _nInfo,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString &_rValue,
|
2001-05-15 07:18:32 +00:00
|
|
|
const Reference< XInterface >& _xInterface,
|
|
|
|
rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
char aValue[512];
|
2001-05-04 08:58:45 +00:00
|
|
|
SQLSMALLINT nValueLen=0;
|
2001-05-15 07:18:32 +00:00
|
|
|
OTools::ThrowException(_pConnection,
|
2005-01-21 15:43:13 +00:00
|
|
|
(*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,aValue,(sizeof aValue)-1,&nValueLen),
|
2000-09-18 15:18:56 +00:00
|
|
|
_aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
_rValue = OUString(aValue,nValueLen,_nTextEncoding);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-05-15 07:18:32 +00:00
|
|
|
void OTools::GetInfo(OConnection* _pConnection,
|
|
|
|
SQLHANDLE _aConnectionHandle,
|
|
|
|
SQLUSMALLINT _nInfo,
|
|
|
|
sal_Int32 &_rValue,
|
|
|
|
const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
|
2001-09-18 10:22:34 +00:00
|
|
|
{
|
|
|
|
SQLSMALLINT nValueLen;
|
|
|
|
_rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
|
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
|
|
|
|
_aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void OTools::GetInfo(OConnection* _pConnection,
|
|
|
|
SQLHANDLE _aConnectionHandle,
|
|
|
|
SQLUSMALLINT _nInfo,
|
|
|
|
SQLUINTEGER &_rValue,
|
|
|
|
const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
SQLSMALLINT nValueLen;
|
|
|
|
_rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
|
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
|
|
|
|
_aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void OTools::GetInfo(OConnection* _pConnection,
|
|
|
|
SQLHANDLE _aConnectionHandle,
|
|
|
|
SQLUSMALLINT _nInfo,
|
|
|
|
SQLUSMALLINT &_rValue,
|
|
|
|
const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
SQLSMALLINT nValueLen;
|
|
|
|
_rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
|
2001-05-15 07:18:32 +00:00
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
|
2000-09-18 15:18:56 +00:00
|
|
|
_aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-05-15 07:18:32 +00:00
|
|
|
void OTools::GetInfo(OConnection* _pConnection,
|
|
|
|
SQLHANDLE _aConnectionHandle,
|
|
|
|
SQLUSMALLINT _nInfo,
|
|
|
|
sal_Bool &_rValue,
|
|
|
|
const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
SQLSMALLINT nValueLen;
|
2001-05-15 07:18:32 +00:00
|
|
|
OTools::ThrowException(_pConnection,
|
|
|
|
(*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
|
|
|
|
_aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2012-10-26 18:57:34 +02:00
|
|
|
sal_Int32 OTools::MapOdbcType2Jdbc(SQLSMALLINT _nType)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-11-20 13:14:27 +00:00
|
|
|
sal_Int32 nValue = DataType::VARCHAR;
|
2000-09-18 15:18:56 +00:00
|
|
|
switch(_nType)
|
|
|
|
{
|
|
|
|
case SQL_BIT:
|
|
|
|
nValue = DataType::BIT;
|
|
|
|
break;
|
|
|
|
case SQL_TINYINT:
|
|
|
|
nValue = DataType::TINYINT;
|
|
|
|
break;
|
|
|
|
case SQL_SMALLINT:
|
|
|
|
nValue = DataType::SMALLINT;
|
|
|
|
break;
|
|
|
|
case SQL_INTEGER:
|
|
|
|
nValue = DataType::INTEGER;
|
|
|
|
break;
|
|
|
|
case SQL_BIGINT:
|
|
|
|
nValue = DataType::BIGINT;
|
|
|
|
break;
|
|
|
|
case SQL_FLOAT:
|
|
|
|
nValue = DataType::FLOAT;
|
|
|
|
break;
|
|
|
|
case SQL_REAL:
|
|
|
|
nValue = DataType::REAL;
|
|
|
|
break;
|
|
|
|
case SQL_DOUBLE:
|
|
|
|
nValue = DataType::DOUBLE;
|
|
|
|
break;
|
|
|
|
case SQL_NUMERIC:
|
|
|
|
nValue = DataType::NUMERIC;
|
|
|
|
break;
|
|
|
|
case SQL_DECIMAL:
|
|
|
|
nValue = DataType::DECIMAL;
|
|
|
|
break;
|
|
|
|
case SQL_WCHAR:
|
|
|
|
case SQL_CHAR:
|
|
|
|
nValue = DataType::CHAR;
|
|
|
|
break;
|
|
|
|
case SQL_WVARCHAR:
|
|
|
|
case SQL_VARCHAR:
|
|
|
|
nValue = DataType::VARCHAR;
|
|
|
|
break;
|
2001-11-20 13:14:27 +00:00
|
|
|
case SQL_WLONGVARCHAR:
|
2000-09-18 15:18:56 +00:00
|
|
|
case SQL_LONGVARCHAR:
|
|
|
|
nValue = DataType::LONGVARCHAR;
|
|
|
|
break;
|
|
|
|
case SQL_TYPE_DATE:
|
|
|
|
case SQL_DATE:
|
|
|
|
nValue = DataType::DATE;
|
|
|
|
break;
|
|
|
|
case SQL_TYPE_TIME:
|
|
|
|
case SQL_TIME:
|
|
|
|
nValue = DataType::TIME;
|
|
|
|
break;
|
|
|
|
case SQL_TYPE_TIMESTAMP:
|
|
|
|
case SQL_TIMESTAMP:
|
|
|
|
nValue = DataType::TIMESTAMP;
|
|
|
|
break;
|
|
|
|
case SQL_BINARY:
|
|
|
|
nValue = DataType::BINARY;
|
|
|
|
break;
|
|
|
|
case SQL_VARBINARY:
|
2001-11-20 13:14:27 +00:00
|
|
|
case SQL_GUID:
|
2000-09-18 15:18:56 +00:00
|
|
|
nValue = DataType::VARBINARY;
|
|
|
|
break;
|
|
|
|
case SQL_LONGVARBINARY:
|
|
|
|
nValue = DataType::LONGVARBINARY;
|
|
|
|
break;
|
2001-11-20 13:14:27 +00:00
|
|
|
default:
|
2014-01-29 11:00:45 +01:00
|
|
|
OSL_FAIL("Invalid type");
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return nValue;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// jdbcTypeToOdbc
|
|
|
|
// Convert the JDBC SQL type to the correct ODBC type
|
|
|
|
//--------------------------------------------------------------------
|
2012-10-26 18:57:34 +02:00
|
|
|
SQLSMALLINT OTools::jdbcTypeToOdbc(sal_Int32 jdbcType)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OTools::jdbcTypeToOdbc" );
|
2000-09-18 15:18:56 +00:00
|
|
|
// For the most part, JDBC types match ODBC types. We'll
|
|
|
|
// just convert the ones that we know are different
|
|
|
|
|
|
|
|
sal_Int32 odbcType = jdbcType;
|
|
|
|
|
|
|
|
switch (jdbcType)
|
|
|
|
{
|
|
|
|
case DataType::DATE:
|
|
|
|
odbcType = SQL_DATE;
|
|
|
|
break;
|
|
|
|
case DataType::TIME:
|
|
|
|
odbcType = SQL_TIME;
|
|
|
|
break;
|
|
|
|
case DataType::TIMESTAMP:
|
|
|
|
odbcType = SQL_TIMESTAMP;
|
|
|
|
break;
|
2012-10-26 18:57:34 +02:00
|
|
|
// ODBC doesn't have any notion of CLOB or BLOB
|
|
|
|
case DataType::CLOB:
|
|
|
|
odbcType = SQL_LONGVARCHAR;
|
2012-12-08 23:43:19 +01:00
|
|
|
break;
|
2012-10-26 18:57:34 +02:00
|
|
|
case DataType::BLOB:
|
|
|
|
odbcType = SQL_LONGVARBINARY;
|
2012-12-08 23:43:19 +01:00
|
|
|
break;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return odbcType;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-11-30 13:09:45 +00:00
|
|
|
void OTools::getBindTypes(sal_Bool _bUseWChar,
|
|
|
|
sal_Bool _bUseOldTimeDate,
|
|
|
|
SQLSMALLINT _nOdbcType,
|
|
|
|
SQLSMALLINT& fCType,
|
|
|
|
SQLSMALLINT& fSqlType
|
|
|
|
)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2013-06-15 01:56:13 +03:00
|
|
|
SAL_INFO( "connectivity.drivers", "odbc Ocke.Janssen@sun.com OTools::getBindTypes" );
|
2001-11-30 13:09:45 +00:00
|
|
|
switch(_nOdbcType)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
case SQL_CHAR: if(_bUseWChar)
|
|
|
|
{
|
|
|
|
fCType = SQL_C_WCHAR;
|
|
|
|
fSqlType = SQL_WCHAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fCType = SQL_C_CHAR;
|
|
|
|
fSqlType = SQL_CHAR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQL_VARCHAR: if(_bUseWChar)
|
|
|
|
{
|
|
|
|
fCType = SQL_C_WCHAR;
|
|
|
|
fSqlType = SQL_WVARCHAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fCType = SQL_C_CHAR;
|
|
|
|
fSqlType = SQL_VARCHAR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQL_LONGVARCHAR: if(_bUseWChar)
|
|
|
|
{
|
|
|
|
fCType = SQL_C_WCHAR;
|
|
|
|
fSqlType = SQL_WLONGVARCHAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fCType = SQL_C_CHAR;
|
|
|
|
fSqlType = SQL_LONGVARCHAR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQL_DECIMAL: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR;
|
|
|
|
fSqlType = SQL_DECIMAL; break;
|
|
|
|
case SQL_NUMERIC: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR;
|
|
|
|
fSqlType = SQL_NUMERIC; break;
|
|
|
|
case SQL_BIT: fCType = SQL_C_TINYINT;
|
|
|
|
fSqlType = SQL_INTEGER; break;
|
2003-09-04 07:27:21 +00:00
|
|
|
case SQL_TINYINT: fCType = SQL_C_TINYINT;
|
2000-09-18 15:18:56 +00:00
|
|
|
fSqlType = SQL_TINYINT; break;
|
|
|
|
case SQL_SMALLINT: fCType = SQL_C_SHORT;
|
|
|
|
fSqlType = SQL_SMALLINT; break;
|
|
|
|
case SQL_INTEGER: fCType = SQL_C_LONG;
|
|
|
|
fSqlType = SQL_INTEGER; break;
|
2001-09-20 11:51:56 +00:00
|
|
|
case SQL_BIGINT: fCType = SQL_C_SBIGINT;
|
2000-09-18 15:18:56 +00:00
|
|
|
fSqlType = SQL_BIGINT; break;
|
2000-11-30 14:21:36 +00:00
|
|
|
case SQL_FLOAT: fCType = SQL_C_FLOAT;
|
|
|
|
fSqlType = SQL_FLOAT; break;
|
2006-01-03 15:04:35 +00:00
|
|
|
case SQL_REAL: fCType = SQL_C_DOUBLE;
|
2000-09-18 15:18:56 +00:00
|
|
|
fSqlType = SQL_REAL; break;
|
|
|
|
case SQL_DOUBLE: fCType = SQL_C_DOUBLE;
|
|
|
|
fSqlType = SQL_DOUBLE; break;
|
|
|
|
case SQL_BINARY: fCType = SQL_C_BINARY;
|
|
|
|
fSqlType = SQL_BINARY; break;
|
|
|
|
case SQL_VARBINARY:
|
|
|
|
fCType = SQL_C_BINARY;
|
|
|
|
fSqlType = SQL_VARBINARY; break;
|
|
|
|
case SQL_LONGVARBINARY: fCType = SQL_C_BINARY;
|
|
|
|
fSqlType = SQL_LONGVARBINARY; break;
|
|
|
|
case SQL_DATE:
|
|
|
|
if(_bUseOldTimeDate)
|
|
|
|
{
|
|
|
|
fCType = SQL_C_DATE;
|
|
|
|
fSqlType = SQL_DATE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fCType = SQL_C_TYPE_DATE;
|
|
|
|
fSqlType = SQL_TYPE_DATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQL_TIME:
|
|
|
|
if(_bUseOldTimeDate)
|
|
|
|
{
|
|
|
|
fCType = SQL_C_TIME;
|
|
|
|
fSqlType = SQL_TIME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fCType = SQL_C_TYPE_TIME;
|
|
|
|
fSqlType = SQL_TYPE_TIME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQL_TIMESTAMP:
|
|
|
|
if(_bUseOldTimeDate)
|
|
|
|
{
|
|
|
|
fCType = SQL_C_TIMESTAMP;
|
|
|
|
fSqlType = SQL_TIMESTAMP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fCType = SQL_C_TYPE_TIMESTAMP;
|
|
|
|
fSqlType = SQL_TYPE_TIMESTAMP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: fCType = SQL_C_BINARY;
|
|
|
|
fSqlType = SQL_LONGVARBINARY; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|