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