Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef _CONNECTIVITY_OTOOLS_HXX_
20 : #define _CONNECTIVITY_OTOOLS_HXX_
21 :
22 : #include "odbc/OFunctiondefs.hxx"
23 : #include "odbc/odbcbasedllapi.hxx"
24 : #include <com/sun/star/sdbc/SQLException.hpp>
25 : #include <com/sun/star/util/Date.hpp>
26 : #include <com/sun/star/util/Time.hpp>
27 : #include <com/sun/star/util/DateTime.hpp>
28 : #include <osl/thread.h>
29 : #include <rtl/ustring.hxx>
30 : #include <com/sun/star/uno/Sequence.hxx>
31 : #include <rtl/textenc.h>
32 :
33 : #define ODBC3SQLAllocHandle 1
34 : #define ODBC3SQLConnect 2
35 : #define ODBC3SQLDriverConnect 3
36 : #define ODBC3SQLBrowseConnect 4
37 : #define ODBC3SQLDataSources 5
38 : #define ODBC3SQLDrivers 6
39 : #define ODBC3SQLGetInfo 7
40 : #define ODBC3SQLGetFunctions 8
41 : #define ODBC3SQLGetTypeInfo 9
42 : #define ODBC3SQLSetConnectAttr 10
43 : #define ODBC3SQLGetConnectAttr 11
44 : #define ODBC3SQLSetEnvAttr 12
45 : #define ODBC3SQLGetEnvAttr 13
46 : #define ODBC3SQLSetStmtAttr 14
47 : #define ODBC3SQLGetStmtAttr 15
48 : #define ODBC3SQLPrepare 16
49 : #define ODBC3SQLBindParameter 17
50 : #define ODBC3SQLSetCursorName 18
51 : #define ODBC3SQLExecute 19
52 : #define ODBC3SQLExecDirect 20
53 : #define ODBC3SQLDescribeParam 21
54 : #define ODBC3SQLNumParams 22
55 : #define ODBC3SQLParamData 23
56 : #define ODBC3SQLPutData 24
57 : #define ODBC3SQLRowCount 25
58 : #define ODBC3SQLNumResultCols 26
59 : #define ODBC3SQLDescribeCol 27
60 : #define ODBC3SQLColAttribute 28
61 : #define ODBC3SQLBindCol 29
62 : #define ODBC3SQLFetch 30
63 : #define ODBC3SQLFetchScroll 31
64 : #define ODBC3SQLGetData 32
65 : #define ODBC3SQLSetPos 33
66 : #define ODBC3SQLBulkOperations 34
67 : #define ODBC3SQLMoreResults 35
68 : #define ODBC3SQLGetDiagRec 36
69 : #define ODBC3SQLColumnPrivileges 37
70 : #define ODBC3SQLColumns 38
71 : #define ODBC3SQLForeignKeys 39
72 : #define ODBC3SQLPrimaryKeys 40
73 : #define ODBC3SQLProcedureColumns 41
74 : #define ODBC3SQLProcedures 42
75 : #define ODBC3SQLSpecialColumns 43
76 : #define ODBC3SQLStatistics 44
77 : #define ODBC3SQLTablePrivileges 45
78 : #define ODBC3SQLTables 46
79 : #define ODBC3SQLFreeStmt 47
80 : #define ODBC3SQLCloseCursor 48
81 : #define ODBC3SQLCancel 49
82 : #define ODBC3SQLEndTran 50
83 : #define ODBC3SQLDisconnect 51
84 : #define ODBC3SQLFreeHandle 52
85 : #define ODBC3SQLGetCursorName 53
86 : #define ODBC3SQLNativeSql 54
87 :
88 : namespace connectivity
89 : {
90 : namespace odbc
91 : {
92 : class OConnection;
93 :
94 : const sal_uInt32 ODBC_FRACTION_UNITS_PER_HSECOND = 10000000L;
95 : const sal_Int32 MAX_PUT_DATA_LENGTH = 2000;
96 :
97 : class OOO_DLLPUBLIC_ODBCBASE OTools
98 : {
99 : public:
100 : static void ThrowException( const OConnection* _pConnection,
101 : SQLRETURN _rRetCode,
102 : SQLHANDLE _pContext,
103 : SQLSMALLINT _nHandleType,
104 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
105 : sal_Bool _bNoFound=sal_True,
106 : rtl_TextEncoding _nTextEncoding = RTL_TEXTENCODING_MS_1252)
107 : throw(::com::sun::star::sdbc::SQLException);
108 :
109 : static void GetInfo(OConnection* _pConnection,
110 : SQLHANDLE _aConnectionHandle,
111 : SQLUSMALLINT _nInfo,
112 : ::rtl::OUString &_rValue,
113 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
114 : rtl_TextEncoding _nTextEncoding)
115 : throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
116 :
117 : static void GetInfo(OConnection* _pConnection,
118 : SQLHANDLE _aConnectionHandle,
119 : SQLUSMALLINT _nInfo,
120 : sal_Int32 &_rValue,
121 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
122 :
123 : static void GetInfo(OConnection* _pConnection,
124 : SQLHANDLE _aConnectionHandle,
125 : SQLUSMALLINT _nInfo,
126 : SQLUSMALLINT &_rValue,
127 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
128 :
129 : static void GetInfo(OConnection* _pConnection,
130 : SQLHANDLE _aConnectionHandle,
131 : SQLUSMALLINT _nInfo,
132 : SQLUINTEGER &_rValue,
133 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134 :
135 : static void GetInfo(OConnection* _pConnection,
136 : SQLHANDLE _aConnectionHandle,
137 : SQLUSMALLINT _nInfo,
138 : sal_Bool &_rValue,
139 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
140 :
141 : static sal_Int32 MapOdbcType2Jdbc(SQLSMALLINT _nType);
142 : static SQLSMALLINT jdbcTypeToOdbc(sal_Int32 jdbcType);
143 :
144 0 : static DATE_STRUCT DateToOdbcDate(const ::com::sun::star::util::Date& x)
145 : {
146 : DATE_STRUCT aVal;
147 0 : aVal.year = x.Year;
148 0 : aVal.month = x.Month;
149 0 : aVal.day = x.Day;
150 0 : return aVal;
151 : }
152 0 : static TIME_STRUCT TimeToOdbcTime(const ::com::sun::star::util::Time& x)
153 : {
154 : TIME_STRUCT aVal;
155 0 : aVal.hour = x.Hours;
156 0 : aVal.minute = x.Minutes;
157 0 : aVal.second = x.Seconds;
158 0 : return aVal;
159 : }
160 0 : static TIMESTAMP_STRUCT DateTimeToTimestamp(const ::com::sun::star::util::DateTime& x)
161 : {
162 : TIMESTAMP_STRUCT aVal;
163 0 : aVal.year = x.Year;
164 0 : aVal.month = x.Month;
165 0 : aVal.day = x.Day;
166 0 : aVal.hour = x.Hours;
167 0 : aVal.minute = x.Minutes;
168 0 : aVal.second = x.Seconds;
169 0 : aVal.fraction = x.HundredthSeconds * ODBC_FRACTION_UNITS_PER_HSECOND;
170 0 : return aVal;
171 : }
172 : /**
173 : getBindTypes set the ODBC type for C
174 : @param _bUseWChar true when Unicode should be used
175 : @param _bUseOldTimeDate true when the old datetime format should be used
176 : @param _nOdbcType the ODBC sql type
177 : @param fCType the C type for the ODBC type
178 : @param fSqlType the SQL type for the ODBC type
179 : */
180 : static void getBindTypes(sal_Bool _bUseWChar,
181 : sal_Bool _bUseOldTimeDate,
182 : SQLSMALLINT _nOdbcType,
183 : SQLSMALLINT& fCType,
184 : SQLSMALLINT& fSqlType);
185 :
186 : static ::rtl::OUString getStringValue( OConnection* _pConnection,
187 : SQLHANDLE _aStatementHandle,
188 : sal_Int32 columnIndex,
189 : SQLSMALLINT _fSqlType,
190 : sal_Bool &_bWasNull,
191 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
192 : rtl_TextEncoding _nTextEncoding) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
193 :
194 : static ::com::sun::star::uno::Sequence<sal_Int8> getBytesValue(const OConnection* _pConnection,
195 : SQLHANDLE _aStatementHandle,
196 : sal_Int32 columnIndex,
197 : SQLSMALLINT _fSqlType,
198 : sal_Bool &_bWasNull,
199 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
200 : static void getValue( OConnection* _pConnection,
201 : SQLHANDLE _aStatementHandle,
202 : sal_Int32 columnIndex,
203 : SQLSMALLINT _nType,
204 : sal_Bool &_bWasNull,
205 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
206 : void* _pValue,
207 : SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
208 :
209 : static void bindValue( OConnection* _pConnection,
210 : SQLHANDLE _aStatementHandle,
211 : sal_Int32 columnIndex,
212 : SQLSMALLINT _nType,
213 : SQLSMALLINT _nMaxLen,
214 : const void* _pValue,
215 : void* _pData,
216 : SQLLEN *pLen,
217 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
218 : rtl_TextEncoding _nTextEncoding,
219 : sal_Bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
220 : };
221 :
222 0 : template <class T> void getValue( OConnection* _pConnection,
223 : SQLHANDLE _aStatementHandle,
224 : sal_Int32 columnIndex,
225 : SQLSMALLINT _nType,
226 : sal_Bool &_bWasNull,
227 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
228 : T& _rValue) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
229 : {
230 0 : OTools::getValue(_pConnection,_aStatementHandle,columnIndex,_nType,_bWasNull,_xInterface,&_rValue,sizeof _rValue);
231 0 : }
232 : //-----------------------------------------------------------------------------
233 :
234 :
235 : }
236 : }
237 : #endif // _CONNECTIVITY_OTOOLS_HXX_
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|