update dev300-m58
[ooovba.git] / connectivity / source / inc / odbc / OTools.hxx
blobe8f11c780981cbd5d718092632a00cbf0ff0afe2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OTools.hxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _CONNECTIVITY_OTOOLS_HXX_
31 #define _CONNECTIVITY_OTOOLS_HXX_
33 #include "odbc/OFunctiondefs.hxx"
34 #include "odbc/odbcbasedllapi.hxx"
35 #include <com/sun/star/sdbc/SQLException.hpp>
36 #include <com/sun/star/util/Date.hpp>
37 #include <com/sun/star/util/Time.hpp>
38 #include <com/sun/star/util/DateTime.hpp>
39 #include <osl/thread.h>
40 #include <rtl/ustring.hxx>
41 #include <com/sun/star/uno/Sequence.hxx>
42 #include <rtl/textenc.h>
44 #define ODBC3SQLAllocHandle 1
45 #define ODBC3SQLConnect 2
46 #define ODBC3SQLDriverConnect 3
47 #define ODBC3SQLBrowseConnect 4
48 #define ODBC3SQLDataSources 5
49 #define ODBC3SQLDrivers 6
50 #define ODBC3SQLGetInfo 7
51 #define ODBC3SQLGetFunctions 8
52 #define ODBC3SQLGetTypeInfo 9
53 #define ODBC3SQLSetConnectAttr 10
54 #define ODBC3SQLGetConnectAttr 11
55 #define ODBC3SQLSetEnvAttr 12
56 #define ODBC3SQLGetEnvAttr 13
57 #define ODBC3SQLSetStmtAttr 14
58 #define ODBC3SQLGetStmtAttr 15
59 #define ODBC3SQLPrepare 16
60 #define ODBC3SQLBindParameter 17
61 #define ODBC3SQLSetCursorName 18
62 #define ODBC3SQLExecute 19
63 #define ODBC3SQLExecDirect 20
64 #define ODBC3SQLDescribeParam 21
65 #define ODBC3SQLNumParams 22
66 #define ODBC3SQLParamData 23
67 #define ODBC3SQLPutData 24
68 #define ODBC3SQLRowCount 25
69 #define ODBC3SQLNumResultCols 26
70 #define ODBC3SQLDescribeCol 27
71 #define ODBC3SQLColAttribute 28
72 #define ODBC3SQLBindCol 29
73 #define ODBC3SQLFetch 30
74 #define ODBC3SQLFetchScroll 31
75 #define ODBC3SQLGetData 32
76 #define ODBC3SQLSetPos 33
77 #define ODBC3SQLBulkOperations 34
78 #define ODBC3SQLMoreResults 35
79 #define ODBC3SQLGetDiagRec 36
80 #define ODBC3SQLColumnPrivileges 37
81 #define ODBC3SQLColumns 38
82 #define ODBC3SQLForeignKeys 39
83 #define ODBC3SQLPrimaryKeys 40
84 #define ODBC3SQLProcedureColumns 41
85 #define ODBC3SQLProcedures 42
86 #define ODBC3SQLSpecialColumns 43
87 #define ODBC3SQLStatistics 44
88 #define ODBC3SQLTablePrivileges 45
89 #define ODBC3SQLTables 46
90 #define ODBC3SQLFreeStmt 47
91 #define ODBC3SQLCloseCursor 48
92 #define ODBC3SQLCancel 49
93 #define ODBC3SQLEndTran 50
94 #define ODBC3SQLDisconnect 51
95 #define ODBC3SQLFreeHandle 52
96 #define ODBC3SQLGetCursorName 53
97 #define ODBC3SQLNativeSql 54
99 namespace connectivity
101 namespace odbc
103 class OConnection;
105 const sal_uInt32 ODBC_FRACTION_UNITS_PER_HSECOND = 10000000L;
106 const sal_Int32 MAX_PUT_DATA_LENGTH = 2000;
108 class OOO_DLLPUBLIC_ODBCBASE OTools
110 public:
111 static void ThrowException( OConnection* _pConnection,
112 SQLRETURN _rRetCode,
113 SQLHANDLE _pContext,
114 SQLSMALLINT _nHandleType,
115 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
116 sal_Bool _bNoFound=sal_True,
117 rtl_TextEncoding _nTextEncoding = RTL_TEXTENCODING_MS_1252)
118 throw(::com::sun::star::sdbc::SQLException);
120 static void GetInfo(OConnection* _pConnection,
121 SQLHANDLE _aConnectionHandle,
122 SQLUSMALLINT _nInfo,
123 ::rtl::OUString &_rValue,
124 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
125 rtl_TextEncoding _nTextEncoding)
126 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
128 static void GetInfo(OConnection* _pConnection,
129 SQLHANDLE _aConnectionHandle,
130 SQLUSMALLINT _nInfo,
131 sal_Int32 &_rValue,
132 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134 static void GetInfo(OConnection* _pConnection,
135 SQLHANDLE _aConnectionHandle,
136 SQLUSMALLINT _nInfo,
137 SQLUSMALLINT &_rValue,
138 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
140 static void GetInfo(OConnection* _pConnection,
141 SQLHANDLE _aConnectionHandle,
142 SQLUSMALLINT _nInfo,
143 SQLUINTEGER &_rValue,
144 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
146 static void GetInfo(OConnection* _pConnection,
147 SQLHANDLE _aConnectionHandle,
148 SQLUSMALLINT _nInfo,
149 sal_Bool &_rValue,
150 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
152 static sal_Int32 MapOdbcType2Jdbc(sal_Int32 _nType);
153 static sal_Int32 jdbcTypeToOdbc(sal_Int32 jdbcType);
155 static DATE_STRUCT DateToOdbcDate(const ::com::sun::star::util::Date& x)
157 DATE_STRUCT aVal;
158 aVal.year = x.Year;
159 aVal.month = x.Month;
160 aVal.day = x.Day;
161 return aVal;
163 static TIME_STRUCT TimeToOdbcTime(const ::com::sun::star::util::Time& x)
165 TIME_STRUCT aVal;
166 aVal.hour = x.Hours;
167 aVal.minute = x.Minutes;
168 aVal.second = x.Seconds;
169 return aVal;
171 static TIMESTAMP_STRUCT DateTimeToTimestamp(const ::com::sun::star::util::DateTime& x)
173 TIMESTAMP_STRUCT aVal;
174 aVal.year = x.Year;
175 aVal.month = x.Month;
176 aVal.day = x.Day;
177 aVal.hour = x.Hours;
178 aVal.minute = x.Minutes;
179 aVal.second = x.Seconds;
180 aVal.fraction = x.HundredthSeconds * ODBC_FRACTION_UNITS_PER_HSECOND;
181 return aVal;
183 /**
184 getBindTypes set the ODBC type for C
185 @param _bUseWChar true when Unicode should be used
186 @param _bUseOldTimeDate true when the old datetime format should be used
187 @param _nOdbcType the ODBC sql type
188 @param fCType the C type for the ODBC type
189 @param fSqlType the SQL type for the ODBC type
191 static void getBindTypes(sal_Bool _bUseWChar,
192 sal_Bool _bUseOldTimeDate,
193 SQLSMALLINT _nOdbcType,
194 SQLSMALLINT& fCType,
195 SQLSMALLINT& fSqlType);
197 static ::rtl::OUString getStringValue( OConnection* _pConnection,
198 SQLHANDLE _aStatementHandle,
199 sal_Int32 columnIndex,
200 SQLSMALLINT _fSqlType,
201 sal_Bool &_bWasNull,
202 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
203 rtl_TextEncoding _nTextEncoding) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
205 static ::com::sun::star::uno::Sequence<sal_Int8> getBytesValue(OConnection* _pConnection,
206 SQLHANDLE _aStatementHandle,
207 sal_Int32 columnIndex,
208 SQLSMALLINT _fSqlType,
209 sal_Bool &_bWasNull,
210 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
211 static void getValue( OConnection* _pConnection,
212 SQLHANDLE _aStatementHandle,
213 sal_Int32 columnIndex,
214 SQLSMALLINT _nType,
215 sal_Bool &_bWasNull,
216 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
217 void* _pValue,
218 SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
220 /**
221 bindData copies the from pValue to pData
222 @param _nOdbcType the ODBC sql type
223 @param _bUseWChar true when Unicode should be used
224 @param _pData contains a copy of the data to be set
225 @param _pValue contains the data to be copied
226 @param _nTextEncoding the text encoding
227 @param _nColumnSize the columnsize which is a out param
229 static void bindData( SQLSMALLINT _nOdbcType,
230 sal_Bool _bUseWChar,
231 sal_Int8 *&_pData,
232 SQLLEN*& pLen,
233 const void* _pValue,
234 rtl_TextEncoding _nTextEncoding,
235 SQLULEN& _nColumnSize);
237 static void bindParameter( OConnection* _pConnection,
238 SQLHANDLE _hStmt,
239 sal_Int32 nPos,
240 sal_Int8*& pDataBuffer,
241 sal_Int8* pLenBuffer,
242 SQLSMALLINT _nJDBCtype,
243 sal_Bool _bUseWChar,
244 sal_Bool _bUseOldTimeDate,
245 const void* _pValue,
246 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
247 rtl_TextEncoding _nTextEncoding)
248 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
250 static void bindValue( OConnection* _pConnection,
251 SQLHANDLE _aStatementHandle,
252 sal_Int32 columnIndex,
253 SQLSMALLINT _nType,
254 SQLSMALLINT _nMaxLen,
255 const void* _pValue,
256 void* _pData,
257 SQLLEN *pLen,
258 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
259 rtl_TextEncoding _nTextEncoding,
260 sal_Bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
263 template <class T> void getValue( OConnection* _pConnection,
264 SQLHANDLE _aStatementHandle,
265 sal_Int32 columnIndex,
266 SQLSMALLINT _nType,
267 sal_Bool &_bWasNull,
268 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
269 T& _rValue) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
271 OTools::getValue(_pConnection,_aStatementHandle,columnIndex,_nType,_bWasNull,_xInterface,&_rValue,sizeof _rValue);
273 //-----------------------------------------------------------------------------
278 #endif // _CONNECTIVITY_OTOOLS_HXX_