1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "odbc/OTools.hxx"
27cdf0e10cSrcweir #include "odbc/OFunctions.hxx"
28cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
29cdf0e10cSrcweir #include <osl/diagnose.h>
30cdf0e10cSrcweir #include "odbc/OConnection.hxx"
31cdf0e10cSrcweir #include "diagnose_ex.h"
32cdf0e10cSrcweir #include <rtl/logfile.hxx>
33cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <string.h>
37cdf0e10cSrcweir #include <string>
38cdf0e10cSrcweir #include <algorithm>
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace connectivity::odbc;
41cdf0e10cSrcweir using namespace com::sun::star::uno;
42cdf0e10cSrcweir using namespace com::sun::star::sdbc;
43cdf0e10cSrcweir using namespace com::sun::star::util;
44cdf0e10cSrcweir
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,SQLLEN _nSize)45cdf0e10cSrcweir void OTools::getValue( OConnection* _pConnection,
46cdf0e10cSrcweir SQLHANDLE _aStatementHandle,
47cdf0e10cSrcweir sal_Int32 columnIndex,
48cdf0e10cSrcweir SQLSMALLINT _nType,
49cdf0e10cSrcweir sal_Bool &_bWasNull,
50cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
51cdf0e10cSrcweir void* _pValue,
52cdf0e10cSrcweir SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getValue" );
55cdf0e10cSrcweir SQLLEN pcbValue = SQL_NULL_DATA;
56cdf0e10cSrcweir OTools::ThrowException(_pConnection,
57cdf0e10cSrcweir (*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
58cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
59cdf0e10cSrcweir _nType,
60cdf0e10cSrcweir _pValue,
61cdf0e10cSrcweir _nSize,
62cdf0e10cSrcweir &pcbValue),
63cdf0e10cSrcweir _aStatementHandle,SQL_HANDLE_STMT,_xInterface,sal_False);
64cdf0e10cSrcweir _bWasNull = pcbValue == SQL_NULL_DATA;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir // -----------------------------------------------------------------------------
bindParameter(OConnection * _pConnection,SQLHANDLE _hStmt,sal_Int32 nPos,sal_Int8 * & pDataBuffer,sal_Int8 * pLenBuffer,SQLSMALLINT _nODBCtype,sal_Bool _bUseWChar,sal_Bool _bUseOldTimeDate,const void * _pValue,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & _xInterface,rtl_TextEncoding _nTextEncoding)67cdf0e10cSrcweir void OTools::bindParameter( OConnection* _pConnection,
68cdf0e10cSrcweir SQLHANDLE _hStmt,
69cdf0e10cSrcweir sal_Int32 nPos,
70cdf0e10cSrcweir sal_Int8*& pDataBuffer,
71cdf0e10cSrcweir sal_Int8* pLenBuffer,
72cdf0e10cSrcweir SQLSMALLINT _nODBCtype,
73cdf0e10cSrcweir sal_Bool _bUseWChar,
74cdf0e10cSrcweir sal_Bool _bUseOldTimeDate,
75cdf0e10cSrcweir const void* _pValue,
76cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
77cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding)
78cdf0e10cSrcweir throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindParameter" );
81cdf0e10cSrcweir SQLRETURN nRetcode;
82cdf0e10cSrcweir SQLSMALLINT fSqlType;
83cdf0e10cSrcweir SQLSMALLINT fCType;
84cdf0e10cSrcweir SQLLEN nMaxLen = 0;
85cdf0e10cSrcweir // void*& pData = pDataBuffer;
86cdf0e10cSrcweir SQLLEN* pLen = (SQLLEN*)pLenBuffer;
87cdf0e10cSrcweir SQLULEN nColumnSize=0;
88cdf0e10cSrcweir SQLSMALLINT nDecimalDigits=0;
89cdf0e10cSrcweir
90cdf0e10cSrcweir OTools::getBindTypes(_bUseWChar,_bUseOldTimeDate,_nODBCtype,fCType,fSqlType);
91cdf0e10cSrcweir
92cdf0e10cSrcweir OTools::bindData(_nODBCtype,_bUseWChar,pDataBuffer,pLen,_pValue,_nTextEncoding,nColumnSize);
93cdf0e10cSrcweir if ((nColumnSize == 0) && (fSqlType == SQL_CHAR || fSqlType == SQL_VARCHAR || fSqlType == SQL_LONGVARCHAR))
94cdf0e10cSrcweir nColumnSize = 1;
95cdf0e10cSrcweir
96cdf0e10cSrcweir if(fSqlType == SQL_LONGVARCHAR || fSqlType == SQL_LONGVARBINARY)
97cdf0e10cSrcweir memcpy(pDataBuffer,&nPos,sizeof(nPos));
98cdf0e10cSrcweir
99cdf0e10cSrcweir // 20.09.2001 OJ: Problems with mysql. mysql returns only CHAR as parameter type
100cdf0e10cSrcweir // nRetcode = (*(T3SQLDescribeParam)_pConnection->getOdbcFunction(ODBC3SQLDescribeParam))(_hStmt,(SQLUSMALLINT)nPos,&fSqlType,&nColumnSize,&nDecimalDigits,&nNullable);
101cdf0e10cSrcweir
102cdf0e10cSrcweir nRetcode = (*(T3SQLBindParameter)_pConnection->getOdbcFunction(ODBC3SQLBindParameter))(_hStmt,
103cdf0e10cSrcweir (SQLUSMALLINT)nPos,
104cdf0e10cSrcweir SQL_PARAM_INPUT,
105cdf0e10cSrcweir fCType,
106cdf0e10cSrcweir fSqlType,
107cdf0e10cSrcweir nColumnSize,
108cdf0e10cSrcweir nDecimalDigits,
109cdf0e10cSrcweir pDataBuffer,
110cdf0e10cSrcweir nMaxLen,
111cdf0e10cSrcweir pLen);
112cdf0e10cSrcweir
113cdf0e10cSrcweir OTools::ThrowException(_pConnection,nRetcode,_hStmt,SQL_HANDLE_STMT,_xInterface);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir // -----------------------------------------------------------------------------
bindData(SQLSMALLINT _nOdbcType,sal_Bool _bUseWChar,sal_Int8 * & _pData,SQLLEN * & pLen,const void * _pValue,rtl_TextEncoding _nTextEncoding,SQLULEN & _nColumnSize)116cdf0e10cSrcweir void OTools::bindData( SQLSMALLINT _nOdbcType,
117cdf0e10cSrcweir sal_Bool _bUseWChar,
118cdf0e10cSrcweir sal_Int8 *&_pData,
119cdf0e10cSrcweir SQLLEN*& pLen,
120cdf0e10cSrcweir const void* _pValue,
121cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding,
122cdf0e10cSrcweir SQLULEN& _nColumnSize)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindData" );
125cdf0e10cSrcweir _nColumnSize = 0;
126cdf0e10cSrcweir
127cdf0e10cSrcweir switch (_nOdbcType)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir case SQL_CHAR:
130cdf0e10cSrcweir case SQL_VARCHAR:
131cdf0e10cSrcweir case SQL_DECIMAL:
132cdf0e10cSrcweir if(_bUseWChar)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir *pLen = SQL_NTS;
135cdf0e10cSrcweir ::rtl::OUString sStr(*(::rtl::OUString*)_pValue);
136cdf0e10cSrcweir _nColumnSize = sStr.getLength();
137cdf0e10cSrcweir *((rtl::OUString*)_pData) = sStr;
138cdf0e10cSrcweir
139cdf0e10cSrcweir // Zeiger auf Char*
140cdf0e10cSrcweir _pData = (sal_Int8*)((rtl::OUString*)_pData)->getStr();
141cdf0e10cSrcweir }
142cdf0e10cSrcweir else
143cdf0e10cSrcweir {
144cdf0e10cSrcweir ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding));
145cdf0e10cSrcweir *pLen = SQL_NTS;
146cdf0e10cSrcweir _nColumnSize = aString.getLength();
147cdf0e10cSrcweir memcpy(_pData,aString.getStr(),aString.getLength());
148cdf0e10cSrcweir ((sal_Int8*)_pData)[aString.getLength()] = '\0';
149cdf0e10cSrcweir }
150cdf0e10cSrcweir break;
151cdf0e10cSrcweir
152cdf0e10cSrcweir case SQL_BIGINT:
153cdf0e10cSrcweir *((sal_Int64*)_pData) = *(sal_Int64*)_pValue;
154cdf0e10cSrcweir *pLen = sizeof(sal_Int64);
155cdf0e10cSrcweir _nColumnSize = *pLen;
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir
158cdf0e10cSrcweir case SQL_NUMERIC:
159cdf0e10cSrcweir if(_bUseWChar)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir ::rtl::OUString aString = rtl::OUString::valueOf(*(double*)_pValue);
162cdf0e10cSrcweir _nColumnSize = aString.getLength();
163cdf0e10cSrcweir *pLen = _nColumnSize;
164cdf0e10cSrcweir *((rtl::OUString*)_pData) = aString;
165cdf0e10cSrcweir // Zeiger auf Char*
166cdf0e10cSrcweir _pData = (sal_Int8*)((rtl::OUString*)_pData)->getStr();
167cdf0e10cSrcweir }
168cdf0e10cSrcweir else
169cdf0e10cSrcweir {
170cdf0e10cSrcweir ::rtl::OString aString = ::rtl::OString::valueOf(*(double*)_pValue);
171cdf0e10cSrcweir _nColumnSize = aString.getLength();
172cdf0e10cSrcweir *pLen = _nColumnSize;
173cdf0e10cSrcweir memcpy(_pData,aString.getStr(),aString.getLength());
174cdf0e10cSrcweir ((sal_Int8*)_pData)[_nColumnSize] = '\0';
175cdf0e10cSrcweir } break;
176cdf0e10cSrcweir case SQL_BIT:
177cdf0e10cSrcweir case SQL_TINYINT:
178cdf0e10cSrcweir *((sal_Int8*)_pData) = *(sal_Int8*)_pValue;
179cdf0e10cSrcweir *pLen = sizeof(sal_Int8);
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir
182cdf0e10cSrcweir case SQL_SMALLINT:
183cdf0e10cSrcweir *((sal_Int16*)_pData) = *(sal_Int16*)_pValue;
184cdf0e10cSrcweir *pLen = sizeof(sal_Int16);
185cdf0e10cSrcweir break;
186cdf0e10cSrcweir case SQL_INTEGER:
187cdf0e10cSrcweir *((sal_Int32*)_pData) = *(sal_Int32*)_pValue;
188cdf0e10cSrcweir *pLen = sizeof(sal_Int32);
189cdf0e10cSrcweir break;
190cdf0e10cSrcweir case SQL_FLOAT:
191cdf0e10cSrcweir *((float*)_pData) = *(float*)_pValue;
192cdf0e10cSrcweir *pLen = sizeof(float);
193cdf0e10cSrcweir break;
194cdf0e10cSrcweir case SQL_REAL:
195cdf0e10cSrcweir case SQL_DOUBLE:
196cdf0e10cSrcweir *((double*)_pData) = *(double*)_pValue;
197cdf0e10cSrcweir *pLen = sizeof(double);
198cdf0e10cSrcweir break;
199cdf0e10cSrcweir case SQL_BINARY:
200cdf0e10cSrcweir case SQL_VARBINARY:
201cdf0e10cSrcweir {
202cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< sal_Int8 >* pSeq = static_cast< const ::com::sun::star::uno::Sequence< sal_Int8 >* >(_pValue);
203cdf0e10cSrcweir OSL_ENSURE(pSeq,"OTools::bindData: Sequence is null!");
204cdf0e10cSrcweir
205cdf0e10cSrcweir if(pSeq)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir _pData = (sal_Int8*)pSeq->getConstArray();
208cdf0e10cSrcweir *pLen = pSeq->getLength();
209cdf0e10cSrcweir }
210cdf0e10cSrcweir }
211cdf0e10cSrcweir break;
212cdf0e10cSrcweir case SQL_LONGVARBINARY:
213cdf0e10cSrcweir {
214cdf0e10cSrcweir sal_Int32 nLen = 0;
215cdf0e10cSrcweir nLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
216cdf0e10cSrcweir *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
217cdf0e10cSrcweir }
218cdf0e10cSrcweir break;
219cdf0e10cSrcweir case SQL_LONGVARCHAR:
220cdf0e10cSrcweir {
221cdf0e10cSrcweir sal_Int32 nLen = 0;
222cdf0e10cSrcweir if(_bUseWChar)
223cdf0e10cSrcweir nLen = sizeof(sal_Unicode) * ((::rtl::OUString*)_pValue)->getLength();
224cdf0e10cSrcweir else
225cdf0e10cSrcweir {
226cdf0e10cSrcweir ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding));
227cdf0e10cSrcweir nLen = aString.getLength();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
230cdf0e10cSrcweir } break;
231cdf0e10cSrcweir case SQL_DATE:
232cdf0e10cSrcweir *(DATE_STRUCT*)_pData = *(DATE_STRUCT*)_pValue;
233cdf0e10cSrcweir *pLen = (SQLLEN)sizeof(DATE_STRUCT);
234cdf0e10cSrcweir _nColumnSize = 10;
235cdf0e10cSrcweir break;
236cdf0e10cSrcweir case SQL_TIME:
237cdf0e10cSrcweir *(TIME_STRUCT*)_pData = *(TIME_STRUCT*)_pValue;
238cdf0e10cSrcweir *pLen = (SQLLEN)sizeof(TIME_STRUCT);
239cdf0e10cSrcweir _nColumnSize = 8;
240cdf0e10cSrcweir break;
241cdf0e10cSrcweir case SQL_TIMESTAMP:
242cdf0e10cSrcweir *(TIMESTAMP_STRUCT*)_pData = *(TIMESTAMP_STRUCT*)_pValue;
243cdf0e10cSrcweir *pLen = (SQLLEN)sizeof(TIMESTAMP_STRUCT);
244cdf0e10cSrcweir _nColumnSize = 19;
245cdf0e10cSrcweir break;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir // -------------------------------------------------------------------------
bindValue(OConnection * _pConnection,SQLHANDLE _aStatementHandle,sal_Int32 columnIndex,SQLSMALLINT _nType,SQLSMALLINT _nMaxLen,const void * _pValue,void * _pData,SQLLEN * pLen,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & _xInterface,rtl_TextEncoding _nTextEncoding,sal_Bool _bUseOldTimeDate)249cdf0e10cSrcweir void OTools::bindValue( OConnection* _pConnection,
250cdf0e10cSrcweir SQLHANDLE _aStatementHandle,
251cdf0e10cSrcweir sal_Int32 columnIndex,
252cdf0e10cSrcweir SQLSMALLINT _nType,
253cdf0e10cSrcweir SQLSMALLINT _nMaxLen,
254cdf0e10cSrcweir const void* _pValue,
255cdf0e10cSrcweir void* _pData,
256cdf0e10cSrcweir SQLLEN *pLen,
257cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
258cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding,
259cdf0e10cSrcweir sal_Bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::bindValue" );
262cdf0e10cSrcweir SQLRETURN nRetcode;
263cdf0e10cSrcweir SQLSMALLINT fSqlType;
264cdf0e10cSrcweir SQLSMALLINT fCType;
265cdf0e10cSrcweir SQLLEN nMaxLen = _nMaxLen;
266cdf0e10cSrcweir
267cdf0e10cSrcweir OTools::getBindTypes( sal_False,
268cdf0e10cSrcweir _bUseOldTimeDate,
269cdf0e10cSrcweir _nType,
270cdf0e10cSrcweir fCType,
271cdf0e10cSrcweir fSqlType);
272cdf0e10cSrcweir
273cdf0e10cSrcweir if (columnIndex != 0 && !_pValue)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir *pLen = SQL_NULL_DATA;
276cdf0e10cSrcweir nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle,
277cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
278cdf0e10cSrcweir fCType,
279cdf0e10cSrcweir _pData,
280cdf0e10cSrcweir nMaxLen,
281cdf0e10cSrcweir pLen
282cdf0e10cSrcweir );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir else
285cdf0e10cSrcweir {
286cdf0e10cSrcweir try
287cdf0e10cSrcweir {
288cdf0e10cSrcweir switch (_nType)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir case SQL_CHAR:
291cdf0e10cSrcweir case SQL_VARCHAR:
292cdf0e10cSrcweir //if(GetODBCConnection()->m_bUserWChar)
293cdf0e10cSrcweir // {
294cdf0e10cSrcweir // _nMaxLen = rCol.GetPrecision();
295cdf0e10cSrcweir // *pLen = SQL_NTS;
296cdf0e10cSrcweir // *((rtl::OUString*)pData) = (rtl::OUString)_aValue;
297cdf0e10cSrcweir //
298cdf0e10cSrcweir // // Zeiger auf Char*
299cdf0e10cSrcweir // pData = (void*)((rtl::OUString*)pData)->getStr();
300cdf0e10cSrcweir // }
301cdf0e10cSrcweir // else
302cdf0e10cSrcweir {
303cdf0e10cSrcweir ::rtl::OString aString(::rtl::OUStringToOString(*(::rtl::OUString*)_pValue,_nTextEncoding));
304cdf0e10cSrcweir *pLen = SQL_NTS;
305cdf0e10cSrcweir *((::rtl::OString*)_pData) = aString;
306cdf0e10cSrcweir _nMaxLen = (SQLSMALLINT)aString.getLength();
307cdf0e10cSrcweir
308cdf0e10cSrcweir // Zeiger auf Char*
309cdf0e10cSrcweir _pData = (void*)aString.getStr();
310cdf0e10cSrcweir } break;
311cdf0e10cSrcweir case SQL_BIGINT:
312cdf0e10cSrcweir *((sal_Int64*)_pData) = *(sal_Int64*)_pValue;
313cdf0e10cSrcweir *pLen = sizeof(sal_Int64);
314cdf0e10cSrcweir break;
315cdf0e10cSrcweir case SQL_DECIMAL:
316cdf0e10cSrcweir case SQL_NUMERIC:
317cdf0e10cSrcweir //if(GetODBCConnection()->m_bUserWChar)
318cdf0e10cSrcweir // {
319cdf0e10cSrcweir // rtl::OUString aString(rtl::OUString(SdbTools::ToString(ODbTypeConversion::toDouble(*pVariable),rCol.GetScale())));
320cdf0e10cSrcweir // *pLen = _nMaxLen;
321cdf0e10cSrcweir // *((rtl::OUString*)_pData) = aString;
322cdf0e10cSrcweir // // Zeiger auf Char*
323cdf0e10cSrcweir // _pData = (void*)((rtl::OUString*)_pData)->getStr();
324cdf0e10cSrcweir // }
325cdf0e10cSrcweir // else
326cdf0e10cSrcweir {
327cdf0e10cSrcweir ::rtl::OString aString = ::rtl::OString::valueOf(*(double*)_pValue);
328cdf0e10cSrcweir _nMaxLen = (SQLSMALLINT)aString.getLength();
329cdf0e10cSrcweir *pLen = _nMaxLen;
330cdf0e10cSrcweir *((::rtl::OString*)_pData) = aString;
331cdf0e10cSrcweir // Zeiger auf Char*
332cdf0e10cSrcweir _pData = (void*)((::rtl::OString*)_pData)->getStr();
333cdf0e10cSrcweir } break;
334cdf0e10cSrcweir case SQL_BIT:
335cdf0e10cSrcweir case SQL_TINYINT:
336cdf0e10cSrcweir *((sal_Int8*)_pData) = *(sal_Int8*)_pValue;
337cdf0e10cSrcweir *pLen = sizeof(sal_Int8);
338cdf0e10cSrcweir break;
339cdf0e10cSrcweir
340cdf0e10cSrcweir case SQL_SMALLINT:
341cdf0e10cSrcweir *((sal_Int16*)_pData) = *(sal_Int16*)_pValue;
342cdf0e10cSrcweir *pLen = sizeof(sal_Int16);
343cdf0e10cSrcweir break;
344cdf0e10cSrcweir case SQL_INTEGER:
345cdf0e10cSrcweir *((sal_Int32*)_pData) = *(sal_Int32*)_pValue;
346cdf0e10cSrcweir *pLen = sizeof(sal_Int32);
347cdf0e10cSrcweir break;
348cdf0e10cSrcweir case SQL_FLOAT:
349cdf0e10cSrcweir *((float*)_pData) = *(float*)_pValue;
350cdf0e10cSrcweir *pLen = sizeof(float);
351cdf0e10cSrcweir break;
352cdf0e10cSrcweir case SQL_REAL:
353cdf0e10cSrcweir case SQL_DOUBLE:
354cdf0e10cSrcweir *((double*)_pData) = *(double*)_pValue;
355cdf0e10cSrcweir *pLen = sizeof(double);
356cdf0e10cSrcweir break;
357cdf0e10cSrcweir case SQL_BINARY:
358cdf0e10cSrcweir case SQL_VARBINARY:
359cdf0e10cSrcweir // if (_pValue == ::getCppuType((const ::com::sun::star::uno::Sequence< sal_Int8 > *)0))
360cdf0e10cSrcweir {
361cdf0e10cSrcweir _pData = (void*)((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getConstArray();
362cdf0e10cSrcweir *pLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
363cdf0e10cSrcweir } break;
364cdf0e10cSrcweir case SQL_LONGVARBINARY:
365cdf0e10cSrcweir {
366cdf0e10cSrcweir _pData = (void*)(columnIndex);
367cdf0e10cSrcweir sal_Int32 nLen = 0;
368cdf0e10cSrcweir nLen = ((const ::com::sun::star::uno::Sequence< sal_Int8 > *)_pValue)->getLength();
369cdf0e10cSrcweir *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
370cdf0e10cSrcweir }
371cdf0e10cSrcweir break;
372cdf0e10cSrcweir case SQL_LONGVARCHAR:
373cdf0e10cSrcweir {
374cdf0e10cSrcweir _pData = (void*)(columnIndex);
375cdf0e10cSrcweir sal_Int32 nLen = 0;
376cdf0e10cSrcweir nLen = ((::rtl::OUString*)_pValue)->getLength();
377cdf0e10cSrcweir *pLen = (SQLLEN)SQL_LEN_DATA_AT_EXEC(nLen);
378cdf0e10cSrcweir } break;
379cdf0e10cSrcweir case SQL_DATE:
380cdf0e10cSrcweir *pLen = sizeof(DATE_STRUCT);
381cdf0e10cSrcweir *((DATE_STRUCT*)_pData) = *(DATE_STRUCT*)_pValue;
382cdf0e10cSrcweir break;
383cdf0e10cSrcweir case SQL_TIME:
384cdf0e10cSrcweir *pLen = sizeof(TIME_STRUCT);
385cdf0e10cSrcweir *((TIME_STRUCT*)_pData) = *(TIME_STRUCT*)_pValue;
386cdf0e10cSrcweir break;
387cdf0e10cSrcweir case SQL_TIMESTAMP:
388cdf0e10cSrcweir *pLen = sizeof(TIMESTAMP_STRUCT);
389cdf0e10cSrcweir *((TIMESTAMP_STRUCT*)_pData) = *(TIMESTAMP_STRUCT*)_pValue;
390cdf0e10cSrcweir break;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir }
393cdf0e10cSrcweir catch ( ... )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
397cdf0e10cSrcweir nRetcode = (*(T3SQLBindCol)_pConnection->getOdbcFunction(ODBC3SQLBindCol))(_aStatementHandle,
398cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
399cdf0e10cSrcweir fCType,
400cdf0e10cSrcweir _pData,
401cdf0e10cSrcweir nMaxLen,
402cdf0e10cSrcweir pLen
403cdf0e10cSrcweir );
404cdf0e10cSrcweir }
405cdf0e10cSrcweir
406cdf0e10cSrcweir OTools::ThrowException(_pConnection,nRetcode,_aStatementHandle,SQL_HANDLE_STMT,_xInterface);
407cdf0e10cSrcweir }
408cdf0e10cSrcweir // -----------------------------------------------------------------------------
ThrowException(OConnection * _pConnection,SQLRETURN _rRetCode,SQLHANDLE _pContext,SQLSMALLINT _nHandleType,const Reference<XInterface> & _xInterface,sal_Bool _bNoFound,rtl_TextEncoding _nTextEncoding)409cdf0e10cSrcweir void OTools::ThrowException(OConnection* _pConnection,
410cdf0e10cSrcweir SQLRETURN _rRetCode,
411cdf0e10cSrcweir SQLHANDLE _pContext,
412cdf0e10cSrcweir SQLSMALLINT _nHandleType,
413cdf0e10cSrcweir const Reference< XInterface >& _xInterface,
414cdf0e10cSrcweir sal_Bool _bNoFound,
415cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding) throw(SQLException)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir switch(_rRetCode)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir case SQL_NEED_DATA:
420cdf0e10cSrcweir case SQL_STILL_EXECUTING:
421cdf0e10cSrcweir case SQL_SUCCESS:
422cdf0e10cSrcweir
423cdf0e10cSrcweir case SQL_SUCCESS_WITH_INFO:
424cdf0e10cSrcweir return;
425cdf0e10cSrcweir case SQL_NO_DATA_FOUND:
426cdf0e10cSrcweir if(_bNoFound)
427cdf0e10cSrcweir return; // no need to throw a exception
428cdf0e10cSrcweir case SQL_ERROR: break;
429cdf0e10cSrcweir
430cdf0e10cSrcweir
431cdf0e10cSrcweir case SQL_INVALID_HANDLE: OSL_ENSURE(0,"SdbODBC3_SetStatus: SQL_INVALID_HANDLE");
432cdf0e10cSrcweir throw SQLException();
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
435cdf0e10cSrcweir
436cdf0e10cSrcweir // Zusaetliche Informationen zum letzten ODBC-Funktionsaufruf vorhanden.
437cdf0e10cSrcweir // SQLError liefert diese Informationen.
438cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::ThrowException" );
439cdf0e10cSrcweir
440cdf0e10cSrcweir SDB_ODBC_CHAR szSqlState[5];
441cdf0e10cSrcweir SQLINTEGER pfNativeError;
442cdf0e10cSrcweir SDB_ODBC_CHAR szErrorMessage[SQL_MAX_MESSAGE_LENGTH];
443cdf0e10cSrcweir szErrorMessage[0] = '\0';
444cdf0e10cSrcweir SQLSMALLINT pcbErrorMsg = 0;
445cdf0e10cSrcweir
446cdf0e10cSrcweir // Informationen zur letzten Operation:
447cdf0e10cSrcweir // wenn hstmt != SQL_NULL_HSTMT ist (Benutzung von SetStatus in SdbCursor, SdbTable, ...),
448cdf0e10cSrcweir // dann wird der Status des letzten Statements erfragt, sonst der Status des letzten
449cdf0e10cSrcweir // Statements zu dieser Verbindung [was in unserem Fall wahrscheinlich gleichbedeutend ist,
450cdf0e10cSrcweir // aber das Reference Manual drueckt sich da nicht so klar aus ...].
451cdf0e10cSrcweir // Entsprechend bei hdbc.
452cdf0e10cSrcweir SQLRETURN n = (*(T3SQLGetDiagRec)_pConnection->getOdbcFunction(ODBC3SQLGetDiagRec))(_nHandleType,_pContext,1,
453cdf0e10cSrcweir szSqlState,
454cdf0e10cSrcweir &pfNativeError,
455cdf0e10cSrcweir szErrorMessage,sizeof szErrorMessage - 1,&pcbErrorMsg);
456cdf0e10cSrcweir OSL_UNUSED( n );
457cdf0e10cSrcweir OSL_ENSURE(n != SQL_INVALID_HANDLE,"SdbODBC3_SetStatus: SQLError returned SQL_INVALID_HANDLE");
458cdf0e10cSrcweir OSL_ENSURE(n == SQL_SUCCESS || n == SQL_SUCCESS_WITH_INFO || n == SQL_NO_DATA_FOUND || n == SQL_ERROR,"SdbODBC3_SetStatus: SQLError failed");
459cdf0e10cSrcweir
460cdf0e10cSrcweir // Zum Return Code von SQLError siehe ODBC 2.0 Programmer's Reference Seite 287ff
461cdf0e10cSrcweir throw SQLException( ::rtl::OUString((char *)szErrorMessage,pcbErrorMsg,_nTextEncoding),
462cdf0e10cSrcweir _xInterface,
463cdf0e10cSrcweir ::rtl::OUString((char *)szSqlState,5,_nTextEncoding),
464cdf0e10cSrcweir pfNativeError,
465cdf0e10cSrcweir Any()
466cdf0e10cSrcweir );
467cdf0e10cSrcweir
468cdf0e10cSrcweir }
469cdf0e10cSrcweir // -------------------------------------------------------------------------
getBytesValue(OConnection * _pConnection,SQLHANDLE _aStatementHandle,sal_Int32 columnIndex,SQLSMALLINT _fSqlType,sal_Bool & _bWasNull,const Reference<XInterface> & _xInterface)470cdf0e10cSrcweir Sequence<sal_Int8> OTools::getBytesValue(OConnection* _pConnection,
471cdf0e10cSrcweir SQLHANDLE _aStatementHandle,
472cdf0e10cSrcweir sal_Int32 columnIndex,
473cdf0e10cSrcweir SQLSMALLINT _fSqlType,
474cdf0e10cSrcweir sal_Bool &_bWasNull,
475cdf0e10cSrcweir const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
476cdf0e10cSrcweir {
477cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getBytesValue" );
478cdf0e10cSrcweir char aCharArray[2048];
479cdf0e10cSrcweir // Erstmal versuchen, die Daten mit dem kleinen Puffer
480cdf0e10cSrcweir // abzuholen:
481cdf0e10cSrcweir SQLLEN nMaxLen = sizeof aCharArray - 1;
482cdf0e10cSrcweir // GETDATA(SQL_C_CHAR,aCharArray,nMaxLen);
483cdf0e10cSrcweir SQLLEN pcbValue = 0;
484cdf0e10cSrcweir OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
485cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
486cdf0e10cSrcweir _fSqlType,
487cdf0e10cSrcweir (SQLPOINTER)aCharArray,
488cdf0e10cSrcweir nMaxLen,
489cdf0e10cSrcweir &pcbValue),
490cdf0e10cSrcweir _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
491cdf0e10cSrcweir
492cdf0e10cSrcweir _bWasNull = pcbValue == SQL_NULL_DATA;
493cdf0e10cSrcweir if(_bWasNull)
494cdf0e10cSrcweir return Sequence<sal_Int8>();
495cdf0e10cSrcweir
496cdf0e10cSrcweir SQLINTEGER nBytes = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : nMaxLen;
497cdf0e10cSrcweir if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nBytes-1] == 0 && nBytes > 0 )
498cdf0e10cSrcweir --nBytes;
499cdf0e10cSrcweir Sequence<sal_Int8> aData((sal_Int8*)aCharArray, nBytes);
500cdf0e10cSrcweir
501cdf0e10cSrcweir
502cdf0e10cSrcweir // Es handelt sich um Binaerdaten, um einen String, der fuer
503cdf0e10cSrcweir // StarView zu lang ist oder der Treiber kann die Laenge der
504cdf0e10cSrcweir // Daten nicht im voraus bestimmen - also als MemoryStream
505cdf0e10cSrcweir // speichern.
506cdf0e10cSrcweir while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir // Bei Strings wird der Puffer nie ganz ausgenutzt
509cdf0e10cSrcweir // (das letzte Byte ist immer ein NULL-Byte, das
510cdf0e10cSrcweir // aber bei pcbValue nicht mitgezaehlt wird)
511cdf0e10cSrcweir if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen)
512cdf0e10cSrcweir nBytes = pcbValue - nMaxLen;
513cdf0e10cSrcweir else
514cdf0e10cSrcweir nBytes = nMaxLen;
515cdf0e10cSrcweir
516cdf0e10cSrcweir // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen
517cdf0e10cSrcweir // GETDATA(SQL_C_CHAR,aCharArray, nLen + 1);
518cdf0e10cSrcweir OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
519cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
520cdf0e10cSrcweir SQL_C_BINARY,
521cdf0e10cSrcweir &aCharArray,
522cdf0e10cSrcweir (SQLINTEGER)nBytes,
523cdf0e10cSrcweir &pcbValue),
524cdf0e10cSrcweir _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
525cdf0e10cSrcweir sal_Int32 nLen = aData.getLength();
526cdf0e10cSrcweir aData.realloc(nLen + nBytes);
527cdf0e10cSrcweir memcpy(aData.getArray() + nLen, aCharArray, nBytes);
528cdf0e10cSrcweir }
529cdf0e10cSrcweir return aData;
530cdf0e10cSrcweir }
531cdf0e10cSrcweir // -------------------------------------------------------------------------
getStringValue(OConnection * _pConnection,SQLHANDLE _aStatementHandle,sal_Int32 columnIndex,SQLSMALLINT _fSqlType,sal_Bool & _bWasNull,const Reference<XInterface> & _xInterface,rtl_TextEncoding _nTextEncoding)532cdf0e10cSrcweir ::rtl::OUString OTools::getStringValue(OConnection* _pConnection,
533cdf0e10cSrcweir SQLHANDLE _aStatementHandle,
534cdf0e10cSrcweir sal_Int32 columnIndex,
535cdf0e10cSrcweir SQLSMALLINT _fSqlType,
536cdf0e10cSrcweir sal_Bool &_bWasNull,
537cdf0e10cSrcweir const Reference< XInterface >& _xInterface,
538cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
539cdf0e10cSrcweir {
540cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getStringValue" );
541cdf0e10cSrcweir ::rtl::OUStringBuffer aData;
542cdf0e10cSrcweir switch(_fSqlType)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir case SQL_WVARCHAR:
545cdf0e10cSrcweir case SQL_WCHAR:
546cdf0e10cSrcweir case SQL_WLONGVARCHAR:
547cdf0e10cSrcweir {
548cdf0e10cSrcweir sal_Unicode waCharArray[2048];
549cdf0e10cSrcweir // read the unicode data
550cdf0e10cSrcweir SQLLEN nMaxLen = (sizeof(waCharArray) / sizeof(sal_Unicode)) - 1;
551cdf0e10cSrcweir // GETDATA(SQL_C_WCHAR, waCharArray, nMaxLen + sizeof(sal_Unicode));
552cdf0e10cSrcweir
553cdf0e10cSrcweir SQLLEN pcbValue=0;
554cdf0e10cSrcweir OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
555cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
556cdf0e10cSrcweir SQL_C_WCHAR,
557cdf0e10cSrcweir &waCharArray,
558cdf0e10cSrcweir (SQLLEN)nMaxLen*sizeof(sal_Unicode),
559cdf0e10cSrcweir &pcbValue),
560cdf0e10cSrcweir _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
561cdf0e10cSrcweir _bWasNull = pcbValue == SQL_NULL_DATA;
562cdf0e10cSrcweir if(_bWasNull)
563cdf0e10cSrcweir return ::rtl::OUString();
564cdf0e10cSrcweir // Bei Fehler bricht der GETDATA-Makro mit return ab,
565cdf0e10cSrcweir // bei NULL mit break!
566cdf0e10cSrcweir SQLLEN nRealSize = 0;
567cdf0e10cSrcweir if ( pcbValue > -1 )
568cdf0e10cSrcweir nRealSize = pcbValue / sizeof(sal_Unicode);
569cdf0e10cSrcweir SQLLEN nLen = pcbValue != SQL_NO_TOTAL ? std::min(nRealSize, nMaxLen) : (nMaxLen-1);
570cdf0e10cSrcweir waCharArray[nLen] = 0;
571cdf0e10cSrcweir aData.append(waCharArray,nLen);
572cdf0e10cSrcweir
573cdf0e10cSrcweir // Es handelt sich um Binaerdaten, um einen String, der fuer
574cdf0e10cSrcweir // StarView zu lang ist oder der Treiber kann die Laenge der
575cdf0e10cSrcweir // Daten nicht im voraus bestimmen - also als MemoryStream
576cdf0e10cSrcweir // speichern.
577cdf0e10cSrcweir while ((pcbValue == SQL_NO_TOTAL ) || nLen > nMaxLen)
578cdf0e10cSrcweir {
579cdf0e10cSrcweir // Bei Strings wird der Puffer nie ganz ausgenutzt
580cdf0e10cSrcweir // (das letzte Byte ist immer ein NULL-Byte, das
581cdf0e10cSrcweir // aber bei pcbValue nicht mitgezaehlt wird)
582cdf0e10cSrcweir if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen)
583cdf0e10cSrcweir nLen = pcbValue - nMaxLen;
584cdf0e10cSrcweir else
585cdf0e10cSrcweir nLen = nMaxLen;
586cdf0e10cSrcweir
587cdf0e10cSrcweir // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen
588cdf0e10cSrcweir // GETDATA(SQL_C_CHAR,waCharArray, nLen + 1);
589cdf0e10cSrcweir OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
590cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
591cdf0e10cSrcweir SQL_C_WCHAR,
592cdf0e10cSrcweir &waCharArray,
593cdf0e10cSrcweir (SQLLEN)nLen+1,
594cdf0e10cSrcweir &pcbValue),
595cdf0e10cSrcweir _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
596cdf0e10cSrcweir nRealSize = 0;
597cdf0e10cSrcweir if ( pcbValue > -1 )
598cdf0e10cSrcweir nRealSize = pcbValue / sizeof(sal_Unicode);
599cdf0e10cSrcweir nLen = pcbValue != SQL_NO_TOTAL ? std::min(nRealSize, nMaxLen) : (nMaxLen-1);
600cdf0e10cSrcweir waCharArray[nLen] = 0;
601cdf0e10cSrcweir
602cdf0e10cSrcweir aData.append(::rtl::OUString(waCharArray));
603cdf0e10cSrcweir }
604cdf0e10cSrcweir }
605cdf0e10cSrcweir break;
606cdf0e10cSrcweir default:
607cdf0e10cSrcweir {
608cdf0e10cSrcweir char aCharArray[2048];
609cdf0e10cSrcweir // Erstmal versuchen, die Daten mit dem kleinen Puffer
610cdf0e10cSrcweir // abzuholen:
611cdf0e10cSrcweir SQLLEN nMaxLen = sizeof aCharArray - 1;
612cdf0e10cSrcweir // GETDATA(SQL_C_CHAR,aCharArray,nMaxLen);
613cdf0e10cSrcweir SQLLEN pcbValue = 0;
614cdf0e10cSrcweir OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
615cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
616cdf0e10cSrcweir SQL_C_CHAR,
617cdf0e10cSrcweir &aCharArray,
618cdf0e10cSrcweir nMaxLen,
619cdf0e10cSrcweir &pcbValue),
620cdf0e10cSrcweir _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
621cdf0e10cSrcweir _bWasNull = pcbValue == SQL_NULL_DATA;
622cdf0e10cSrcweir if(_bWasNull)
623cdf0e10cSrcweir return ::rtl::OUString();
624cdf0e10cSrcweir
625cdf0e10cSrcweir SQLLEN nLen = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : (nMaxLen-1);
626cdf0e10cSrcweir aCharArray[nLen] = 0;
627cdf0e10cSrcweir if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nLen-1] == 0 && nLen > 0 )
628cdf0e10cSrcweir --nLen;
629cdf0e10cSrcweir aData.append(::rtl::OUString((const sal_Char*)aCharArray,nLen, _nTextEncoding));
630cdf0e10cSrcweir
631cdf0e10cSrcweir // Es handelt sich um Binaerdaten, um einen String, der fuer
632cdf0e10cSrcweir // StarView zu lang ist oder der Treiber kann die Laenge der
633cdf0e10cSrcweir // Daten nicht im voraus bestimmen - also als MemoryStream
634cdf0e10cSrcweir // speichern.
635cdf0e10cSrcweir while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen)
636cdf0e10cSrcweir {
637cdf0e10cSrcweir // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen
638cdf0e10cSrcweir // GETDATA(SQL_C_CHAR,aCharArray, nLen + 1);
639cdf0e10cSrcweir OTools::ThrowException(_pConnection,(*(T3SQLGetData)_pConnection->getOdbcFunction(ODBC3SQLGetData))(_aStatementHandle,
640cdf0e10cSrcweir (SQLUSMALLINT)columnIndex,
641cdf0e10cSrcweir SQL_C_CHAR,
642cdf0e10cSrcweir &aCharArray,
643cdf0e10cSrcweir (SQLINTEGER)nMaxLen,
644cdf0e10cSrcweir &pcbValue),
645cdf0e10cSrcweir _aStatementHandle,SQL_HANDLE_STMT,_xInterface);
646cdf0e10cSrcweir nLen = pcbValue != SQL_NO_TOTAL ? std::min(pcbValue, nMaxLen) : (nMaxLen-1);
647cdf0e10cSrcweir if ( ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) && aCharArray[nLen-1] == 0 && nLen > 0 )
648cdf0e10cSrcweir --nLen;
649cdf0e10cSrcweir aCharArray[nLen] = 0;
650cdf0e10cSrcweir
651cdf0e10cSrcweir aData.append(::rtl::OUString((const sal_Char*)aCharArray,nLen,_nTextEncoding));
652cdf0e10cSrcweir }
653cdf0e10cSrcweir
654cdf0e10cSrcweir // delete all blanks
655cdf0e10cSrcweir // aData.EraseTrailingChars();
656cdf0e10cSrcweir }
657cdf0e10cSrcweir }
658cdf0e10cSrcweir
659cdf0e10cSrcweir return aData.makeStringAndClear();
660cdf0e10cSrcweir }
661cdf0e10cSrcweir // -------------------------------------------------------------------------
GetInfo(OConnection * _pConnection,SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,::rtl::OUString & _rValue,const Reference<XInterface> & _xInterface,rtl_TextEncoding _nTextEncoding)662cdf0e10cSrcweir void OTools::GetInfo(OConnection* _pConnection,
663cdf0e10cSrcweir SQLHANDLE _aConnectionHandle,
664cdf0e10cSrcweir SQLUSMALLINT _nInfo,
665cdf0e10cSrcweir ::rtl::OUString &_rValue,
666cdf0e10cSrcweir const Reference< XInterface >& _xInterface,
667cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
668cdf0e10cSrcweir {
669cdf0e10cSrcweir char aValue[512];
670cdf0e10cSrcweir SQLSMALLINT nValueLen=0;
671cdf0e10cSrcweir OTools::ThrowException(_pConnection,
672cdf0e10cSrcweir (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,aValue,(sizeof aValue)-1,&nValueLen),
673cdf0e10cSrcweir _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
674cdf0e10cSrcweir
675cdf0e10cSrcweir _rValue = ::rtl::OUString(aValue,nValueLen,_nTextEncoding);
676cdf0e10cSrcweir }
677cdf0e10cSrcweir // -------------------------------------------------------------------------
GetInfo(OConnection * _pConnection,SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,sal_Int32 & _rValue,const Reference<XInterface> & _xInterface)678cdf0e10cSrcweir void OTools::GetInfo(OConnection* _pConnection,
679cdf0e10cSrcweir SQLHANDLE _aConnectionHandle,
680cdf0e10cSrcweir SQLUSMALLINT _nInfo,
681cdf0e10cSrcweir sal_Int32 &_rValue,
682cdf0e10cSrcweir const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir SQLSMALLINT nValueLen;
685cdf0e10cSrcweir _rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
686cdf0e10cSrcweir OTools::ThrowException(_pConnection,
687cdf0e10cSrcweir (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
688cdf0e10cSrcweir _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
689cdf0e10cSrcweir }
690cdf0e10cSrcweir // -------------------------------------------------------------------------
GetInfo(OConnection * _pConnection,SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,SQLUINTEGER & _rValue,const Reference<XInterface> & _xInterface)691cdf0e10cSrcweir void OTools::GetInfo(OConnection* _pConnection,
692cdf0e10cSrcweir SQLHANDLE _aConnectionHandle,
693cdf0e10cSrcweir SQLUSMALLINT _nInfo,
694cdf0e10cSrcweir SQLUINTEGER &_rValue,
695cdf0e10cSrcweir const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
696cdf0e10cSrcweir {
697cdf0e10cSrcweir SQLSMALLINT nValueLen;
698cdf0e10cSrcweir _rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
699cdf0e10cSrcweir OTools::ThrowException(_pConnection,
700cdf0e10cSrcweir (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
701cdf0e10cSrcweir _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
702cdf0e10cSrcweir }
703cdf0e10cSrcweir // -------------------------------------------------------------------------
GetInfo(OConnection * _pConnection,SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,SQLUSMALLINT & _rValue,const Reference<XInterface> & _xInterface)704cdf0e10cSrcweir void OTools::GetInfo(OConnection* _pConnection,
705cdf0e10cSrcweir SQLHANDLE _aConnectionHandle,
706cdf0e10cSrcweir SQLUSMALLINT _nInfo,
707cdf0e10cSrcweir SQLUSMALLINT &_rValue,
708cdf0e10cSrcweir const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
709cdf0e10cSrcweir {
710cdf0e10cSrcweir SQLSMALLINT nValueLen;
711cdf0e10cSrcweir _rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION)
712cdf0e10cSrcweir OTools::ThrowException(_pConnection,
713cdf0e10cSrcweir (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
714cdf0e10cSrcweir _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
715cdf0e10cSrcweir }
716cdf0e10cSrcweir // -------------------------------------------------------------------------
GetInfo(OConnection * _pConnection,SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,sal_Bool & _rValue,const Reference<XInterface> & _xInterface)717cdf0e10cSrcweir void OTools::GetInfo(OConnection* _pConnection,
718cdf0e10cSrcweir SQLHANDLE _aConnectionHandle,
719cdf0e10cSrcweir SQLUSMALLINT _nInfo,
720cdf0e10cSrcweir sal_Bool &_rValue,
721cdf0e10cSrcweir const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException)
722cdf0e10cSrcweir {
723cdf0e10cSrcweir SQLSMALLINT nValueLen;
724cdf0e10cSrcweir OTools::ThrowException(_pConnection,
725cdf0e10cSrcweir (*(T3SQLGetInfo)_pConnection->getOdbcFunction(ODBC3SQLGetInfo))(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen),
726cdf0e10cSrcweir _aConnectionHandle,SQL_HANDLE_DBC,_xInterface);
727cdf0e10cSrcweir }
728cdf0e10cSrcweir // -------------------------------------------------------------------------
MapOdbcType2Jdbc(sal_Int32 _nType)729cdf0e10cSrcweir sal_Int32 OTools::MapOdbcType2Jdbc(sal_Int32 _nType)
730cdf0e10cSrcweir {
731cdf0e10cSrcweir sal_Int32 nValue = DataType::VARCHAR;
732cdf0e10cSrcweir switch(_nType)
733cdf0e10cSrcweir {
734cdf0e10cSrcweir case SQL_BIT:
735cdf0e10cSrcweir nValue = DataType::BIT;
736cdf0e10cSrcweir break;
737cdf0e10cSrcweir case SQL_TINYINT:
738cdf0e10cSrcweir nValue = DataType::TINYINT;
739cdf0e10cSrcweir break;
740cdf0e10cSrcweir case SQL_SMALLINT:
741cdf0e10cSrcweir nValue = DataType::SMALLINT;
742cdf0e10cSrcweir break;
743cdf0e10cSrcweir case SQL_INTEGER:
744cdf0e10cSrcweir nValue = DataType::INTEGER;
745cdf0e10cSrcweir break;
746cdf0e10cSrcweir case SQL_BIGINT:
747cdf0e10cSrcweir nValue = DataType::BIGINT;
748cdf0e10cSrcweir break;
749cdf0e10cSrcweir case SQL_FLOAT:
750cdf0e10cSrcweir nValue = DataType::FLOAT;
751cdf0e10cSrcweir break;
752cdf0e10cSrcweir case SQL_REAL:
753cdf0e10cSrcweir nValue = DataType::REAL;
754cdf0e10cSrcweir break;
755cdf0e10cSrcweir case SQL_DOUBLE:
756cdf0e10cSrcweir nValue = DataType::DOUBLE;
757cdf0e10cSrcweir break;
758cdf0e10cSrcweir case SQL_NUMERIC:
759cdf0e10cSrcweir nValue = DataType::NUMERIC;
760cdf0e10cSrcweir break;
761cdf0e10cSrcweir case SQL_DECIMAL:
762cdf0e10cSrcweir nValue = DataType::DECIMAL;
763cdf0e10cSrcweir break;
764cdf0e10cSrcweir case SQL_WCHAR:
765cdf0e10cSrcweir case SQL_CHAR:
766cdf0e10cSrcweir nValue = DataType::CHAR;
767cdf0e10cSrcweir break;
768cdf0e10cSrcweir case SQL_WVARCHAR:
769cdf0e10cSrcweir case SQL_VARCHAR:
770cdf0e10cSrcweir nValue = DataType::VARCHAR;
771cdf0e10cSrcweir break;
772cdf0e10cSrcweir case SQL_WLONGVARCHAR:
773cdf0e10cSrcweir case SQL_LONGVARCHAR:
774cdf0e10cSrcweir nValue = DataType::LONGVARCHAR;
775cdf0e10cSrcweir break;
776cdf0e10cSrcweir case SQL_TYPE_DATE:
777cdf0e10cSrcweir case SQL_DATE:
778cdf0e10cSrcweir nValue = DataType::DATE;
779cdf0e10cSrcweir break;
780cdf0e10cSrcweir case SQL_TYPE_TIME:
781cdf0e10cSrcweir case SQL_TIME:
782cdf0e10cSrcweir nValue = DataType::TIME;
783cdf0e10cSrcweir break;
784cdf0e10cSrcweir case SQL_TYPE_TIMESTAMP:
785cdf0e10cSrcweir case SQL_TIMESTAMP:
786cdf0e10cSrcweir nValue = DataType::TIMESTAMP;
787cdf0e10cSrcweir break;
788cdf0e10cSrcweir case SQL_BINARY:
789cdf0e10cSrcweir nValue = DataType::BINARY;
790cdf0e10cSrcweir break;
791cdf0e10cSrcweir case SQL_VARBINARY:
792cdf0e10cSrcweir case SQL_GUID:
793cdf0e10cSrcweir nValue = DataType::VARBINARY;
794cdf0e10cSrcweir break;
795cdf0e10cSrcweir case SQL_LONGVARBINARY:
796cdf0e10cSrcweir nValue = DataType::LONGVARBINARY;
797cdf0e10cSrcweir break;
798cdf0e10cSrcweir default:
799cdf0e10cSrcweir OSL_ASSERT(!"Invalid type");
800cdf0e10cSrcweir }
801cdf0e10cSrcweir return nValue;
802cdf0e10cSrcweir }
803cdf0e10cSrcweir //--------------------------------------------------------------------
804cdf0e10cSrcweir // jdbcTypeToOdbc
805cdf0e10cSrcweir // Convert the JDBC SQL type to the correct ODBC type
806cdf0e10cSrcweir //--------------------------------------------------------------------
jdbcTypeToOdbc(sal_Int32 jdbcType)807cdf0e10cSrcweir sal_Int32 OTools::jdbcTypeToOdbc(sal_Int32 jdbcType)
808cdf0e10cSrcweir {
809cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::jdbcTypeToOdbc" );
810cdf0e10cSrcweir // For the most part, JDBC types match ODBC types. We'll
811cdf0e10cSrcweir // just convert the ones that we know are different
812cdf0e10cSrcweir
813cdf0e10cSrcweir sal_Int32 odbcType = jdbcType;
814cdf0e10cSrcweir
815cdf0e10cSrcweir switch (jdbcType)
816cdf0e10cSrcweir {
817cdf0e10cSrcweir case DataType::DATE:
818cdf0e10cSrcweir odbcType = SQL_DATE;
819cdf0e10cSrcweir break;
820cdf0e10cSrcweir case DataType::TIME:
821cdf0e10cSrcweir odbcType = SQL_TIME;
822cdf0e10cSrcweir break;
823cdf0e10cSrcweir case DataType::TIMESTAMP:
824cdf0e10cSrcweir odbcType = SQL_TIMESTAMP;
825cdf0e10cSrcweir break;
826cdf0e10cSrcweir }
827cdf0e10cSrcweir
828cdf0e10cSrcweir return odbcType;
829cdf0e10cSrcweir }
830cdf0e10cSrcweir //-----------------------------------------------------------------------------
getBindTypes(sal_Bool _bUseWChar,sal_Bool _bUseOldTimeDate,SQLSMALLINT _nOdbcType,SQLSMALLINT & fCType,SQLSMALLINT & fSqlType)831cdf0e10cSrcweir void OTools::getBindTypes(sal_Bool _bUseWChar,
832cdf0e10cSrcweir sal_Bool _bUseOldTimeDate,
833cdf0e10cSrcweir SQLSMALLINT _nOdbcType,
834cdf0e10cSrcweir SQLSMALLINT& fCType,
835cdf0e10cSrcweir SQLSMALLINT& fSqlType
836cdf0e10cSrcweir )
837cdf0e10cSrcweir {
838cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OTools::getBindTypes" );
839cdf0e10cSrcweir switch(_nOdbcType)
840cdf0e10cSrcweir {
841cdf0e10cSrcweir case SQL_CHAR: if(_bUseWChar)
842cdf0e10cSrcweir {
843cdf0e10cSrcweir fCType = SQL_C_WCHAR;
844cdf0e10cSrcweir fSqlType = SQL_WCHAR;
845cdf0e10cSrcweir }
846cdf0e10cSrcweir else
847cdf0e10cSrcweir {
848cdf0e10cSrcweir fCType = SQL_C_CHAR;
849cdf0e10cSrcweir fSqlType = SQL_CHAR;
850cdf0e10cSrcweir }
851cdf0e10cSrcweir break;
852cdf0e10cSrcweir case SQL_VARCHAR: if(_bUseWChar)
853cdf0e10cSrcweir {
854cdf0e10cSrcweir fCType = SQL_C_WCHAR;
855cdf0e10cSrcweir fSqlType = SQL_WVARCHAR;
856cdf0e10cSrcweir }
857cdf0e10cSrcweir else
858cdf0e10cSrcweir {
859cdf0e10cSrcweir fCType = SQL_C_CHAR;
860cdf0e10cSrcweir fSqlType = SQL_VARCHAR;
861cdf0e10cSrcweir }
862cdf0e10cSrcweir break;
863cdf0e10cSrcweir case SQL_LONGVARCHAR: if(_bUseWChar)
864cdf0e10cSrcweir {
865cdf0e10cSrcweir fCType = SQL_C_WCHAR;
866cdf0e10cSrcweir fSqlType = SQL_WLONGVARCHAR;
867cdf0e10cSrcweir }
868cdf0e10cSrcweir else
869cdf0e10cSrcweir {
870cdf0e10cSrcweir fCType = SQL_C_CHAR;
871cdf0e10cSrcweir fSqlType = SQL_LONGVARCHAR;
872cdf0e10cSrcweir }
873cdf0e10cSrcweir break;
874cdf0e10cSrcweir case SQL_DECIMAL: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR;
875cdf0e10cSrcweir fSqlType = SQL_DECIMAL; break;
876cdf0e10cSrcweir case SQL_NUMERIC: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR;
877cdf0e10cSrcweir fSqlType = SQL_NUMERIC; break;
878cdf0e10cSrcweir case SQL_BIT: fCType = SQL_C_TINYINT;
879cdf0e10cSrcweir fSqlType = SQL_INTEGER; break;
880cdf0e10cSrcweir case SQL_TINYINT: fCType = SQL_C_TINYINT;
881cdf0e10cSrcweir fSqlType = SQL_TINYINT; break;
882cdf0e10cSrcweir case SQL_SMALLINT: fCType = SQL_C_SHORT;
883cdf0e10cSrcweir fSqlType = SQL_SMALLINT; break;
884cdf0e10cSrcweir case SQL_INTEGER: fCType = SQL_C_LONG;
885cdf0e10cSrcweir fSqlType = SQL_INTEGER; break;
886cdf0e10cSrcweir case SQL_BIGINT: fCType = SQL_C_SBIGINT;
887cdf0e10cSrcweir fSqlType = SQL_BIGINT; break;
888cdf0e10cSrcweir case SQL_FLOAT: fCType = SQL_C_FLOAT;
889cdf0e10cSrcweir fSqlType = SQL_FLOAT; break;
890cdf0e10cSrcweir case SQL_REAL: fCType = SQL_C_DOUBLE;
891cdf0e10cSrcweir fSqlType = SQL_REAL; break;
892cdf0e10cSrcweir case SQL_DOUBLE: fCType = SQL_C_DOUBLE;
893cdf0e10cSrcweir fSqlType = SQL_DOUBLE; break;
894cdf0e10cSrcweir case SQL_BINARY: fCType = SQL_C_BINARY;
895cdf0e10cSrcweir fSqlType = SQL_BINARY; break;
896cdf0e10cSrcweir case SQL_VARBINARY:
897cdf0e10cSrcweir fCType = SQL_C_BINARY;
898cdf0e10cSrcweir fSqlType = SQL_VARBINARY; break;
899cdf0e10cSrcweir case SQL_LONGVARBINARY: fCType = SQL_C_BINARY;
900cdf0e10cSrcweir fSqlType = SQL_LONGVARBINARY; break;
901cdf0e10cSrcweir case SQL_DATE:
902cdf0e10cSrcweir if(_bUseOldTimeDate)
903cdf0e10cSrcweir {
904cdf0e10cSrcweir fCType = SQL_C_DATE;
905cdf0e10cSrcweir fSqlType = SQL_DATE;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir else
908cdf0e10cSrcweir {
909cdf0e10cSrcweir fCType = SQL_C_TYPE_DATE;
910cdf0e10cSrcweir fSqlType = SQL_TYPE_DATE;
911cdf0e10cSrcweir }
912cdf0e10cSrcweir break;
913cdf0e10cSrcweir case SQL_TIME:
914cdf0e10cSrcweir if(_bUseOldTimeDate)
915cdf0e10cSrcweir {
916cdf0e10cSrcweir fCType = SQL_C_TIME;
917cdf0e10cSrcweir fSqlType = SQL_TIME;
918cdf0e10cSrcweir }
919cdf0e10cSrcweir else
920cdf0e10cSrcweir {
921cdf0e10cSrcweir fCType = SQL_C_TYPE_TIME;
922cdf0e10cSrcweir fSqlType = SQL_TYPE_TIME;
923cdf0e10cSrcweir }
924cdf0e10cSrcweir break;
925cdf0e10cSrcweir case SQL_TIMESTAMP:
926cdf0e10cSrcweir if(_bUseOldTimeDate)
927cdf0e10cSrcweir {
928cdf0e10cSrcweir fCType = SQL_C_TIMESTAMP;
929cdf0e10cSrcweir fSqlType = SQL_TIMESTAMP;
930cdf0e10cSrcweir }
931cdf0e10cSrcweir else
932cdf0e10cSrcweir {
933cdf0e10cSrcweir fCType = SQL_C_TYPE_TIMESTAMP;
934cdf0e10cSrcweir fSqlType = SQL_TYPE_TIMESTAMP;
935cdf0e10cSrcweir }
936cdf0e10cSrcweir break;
937cdf0e10cSrcweir default: fCType = SQL_C_BINARY;
938cdf0e10cSrcweir fSqlType = SQL_LONGVARBINARY; break;
939cdf0e10cSrcweir }
940cdf0e10cSrcweir }
941cdf0e10cSrcweir
942cdf0e10cSrcweir
943