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 INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX
20 : #define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX
21 :
22 : #include <connectivity/odbc.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 : enum class ODBC3SQLFunctionId
34 : {
35 : AllocHandle = 1,
36 : Connect = 2,
37 : DriverConnect = 3,
38 : BrowseConnect = 4,
39 : DataSources = 5,
40 : Drivers = 6,
41 : GetInfo = 7,
42 : GetFunctions = 8,
43 : GetTypeInfo = 9,
44 : SetConnectAttr = 10,
45 : GetConnectAttr = 11,
46 : SetEnvAttr = 12,
47 : GetEnvAttr = 13,
48 : SetStmtAttr = 14,
49 : GetStmtAttr = 15,
50 : Prepare = 16,
51 : BindParameter = 17,
52 : SetCursorName = 18,
53 : Execute = 19,
54 : ExecDirect = 20,
55 : DescribeParam = 21,
56 : NumParams = 22,
57 : ParamData = 23,
58 : PutData = 24,
59 : RowCount = 25,
60 : NumResultCols = 26,
61 : DescribeCol = 27,
62 : ColAttribute = 28,
63 : BindCol = 29,
64 : Fetch = 30,
65 : FetchScroll = 31,
66 : GetData = 32,
67 : SetPos = 33,
68 : BulkOperations = 34,
69 : MoreResults = 35,
70 : GetDiagRec = 36,
71 : ColumnPrivileges = 37,
72 : Columns = 38,
73 : ForeignKeys = 39,
74 : PrimaryKeys = 40,
75 : ProcedureColumns = 41,
76 : Procedures = 42,
77 : SpecialColumns = 43,
78 : Statistics = 44,
79 : TablePrivileges = 45,
80 : Tables = 46,
81 : FreeStmt = 47,
82 : CloseCursor = 48,
83 : Cancel = 49,
84 : EndTran = 50,
85 : Disconnect = 51,
86 : FreeHandle = 52,
87 : GetCursorName = 53,
88 : NativeSql = 54,
89 : };
90 :
91 : namespace connectivity
92 : {
93 : namespace odbc
94 : {
95 : class OConnection;
96 :
97 : const sal_Int32 MAX_PUT_DATA_LENGTH = 2000;
98 :
99 : class OOO_DLLPUBLIC_ODBCBASE OTools
100 : {
101 : public:
102 : static void ThrowException( const OConnection* _pConnection,
103 : SQLRETURN _rRetCode,
104 : SQLHANDLE _pContext,
105 : SQLSMALLINT _nHandleType,
106 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
107 : bool _bNoFound=true,
108 : rtl_TextEncoding _nTextEncoding = RTL_TEXTENCODING_MS_1252)
109 : throw(::com::sun::star::sdbc::SQLException);
110 :
111 : static void GetInfo(OConnection* _pConnection,
112 : SQLHANDLE _aConnectionHandle,
113 : SQLUSMALLINT _nInfo,
114 : OUString &_rValue,
115 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
116 : rtl_TextEncoding _nTextEncoding)
117 : throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
118 :
119 : static void GetInfo(OConnection* _pConnection,
120 : SQLHANDLE _aConnectionHandle,
121 : SQLUSMALLINT _nInfo,
122 : sal_Int32 &_rValue,
123 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
124 :
125 : static void GetInfo(OConnection* _pConnection,
126 : SQLHANDLE _aConnectionHandle,
127 : SQLUSMALLINT _nInfo,
128 : SQLUSMALLINT &_rValue,
129 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
130 :
131 : static void GetInfo(OConnection* _pConnection,
132 : SQLHANDLE _aConnectionHandle,
133 : SQLUSMALLINT _nInfo,
134 : SQLUINTEGER &_rValue,
135 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
136 :
137 : static void GetInfo(OConnection* _pConnection,
138 : SQLHANDLE _aConnectionHandle,
139 : SQLUSMALLINT _nInfo,
140 : bool &_rValue,
141 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
142 :
143 : static sal_Int32 MapOdbcType2Jdbc(SQLSMALLINT _nType);
144 : static SQLSMALLINT jdbcTypeToOdbc(sal_Int32 jdbcType);
145 :
146 0 : static DATE_STRUCT DateToOdbcDate(const ::com::sun::star::util::Date& x)
147 : {
148 : DATE_STRUCT aVal;
149 0 : aVal.year = x.Year;
150 0 : aVal.month = x.Month;
151 0 : aVal.day = x.Day;
152 0 : return aVal;
153 : }
154 0 : static TIME_STRUCT TimeToOdbcTime(const ::com::sun::star::util::Time& x)
155 : {
156 : TIME_STRUCT aVal;
157 0 : aVal.hour = x.Hours;
158 0 : aVal.minute = x.Minutes;
159 0 : aVal.second = x.Seconds;
160 0 : return aVal;
161 : }
162 0 : static TIMESTAMP_STRUCT DateTimeToTimestamp(const ::com::sun::star::util::DateTime& x)
163 : {
164 : TIMESTAMP_STRUCT aVal;
165 0 : aVal.year = x.Year;
166 0 : aVal.month = x.Month;
167 0 : aVal.day = x.Day;
168 0 : aVal.hour = x.Hours;
169 0 : aVal.minute = x.Minutes;
170 0 : aVal.second = x.Seconds;
171 0 : aVal.fraction = x.NanoSeconds;
172 0 : return aVal;
173 : }
174 : /**
175 : getBindTypes set the ODBC type for C
176 : @param _bUseWChar true when Unicode should be used
177 : @param _bUseOldTimeDate true when the old datetime format should be used
178 : @param _nOdbcType the ODBC sql type
179 : @param fCType the C type for the ODBC type
180 : @param fSqlType the SQL type for the ODBC type
181 : */
182 : static void getBindTypes(bool _bUseWChar,
183 : bool _bUseOldTimeDate,
184 : SQLSMALLINT _nOdbcType,
185 : SQLSMALLINT& fCType,
186 : SQLSMALLINT& fSqlType);
187 :
188 : static OUString getStringValue( OConnection* _pConnection,
189 : SQLHANDLE _aStatementHandle,
190 : sal_Int32 columnIndex,
191 : SQLSMALLINT _fSqlType,
192 : bool &_bWasNull,
193 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
194 : rtl_TextEncoding _nTextEncoding) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
195 :
196 : static ::com::sun::star::uno::Sequence<sal_Int8> getBytesValue(const OConnection* _pConnection,
197 : SQLHANDLE _aStatementHandle,
198 : sal_Int32 columnIndex,
199 : SQLSMALLINT _fSqlType,
200 : bool &_bWasNull,
201 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
202 : static void getValue( OConnection* _pConnection,
203 : SQLHANDLE _aStatementHandle,
204 : sal_Int32 columnIndex,
205 : SQLSMALLINT _nType,
206 : bool &_bWasNull,
207 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
208 : void* _pValue,
209 : SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
210 :
211 : static void bindValue( OConnection* _pConnection,
212 : SQLHANDLE _aStatementHandle,
213 : sal_Int32 columnIndex,
214 : SQLSMALLINT _nType,
215 : SQLSMALLINT _nMaxLen,
216 : const void* _pValue,
217 : void* _pData,
218 : SQLLEN *pLen,
219 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
220 : rtl_TextEncoding _nTextEncoding,
221 : bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
222 : };
223 :
224 0 : template <class T> void getValue( OConnection* _pConnection,
225 : SQLHANDLE _aStatementHandle,
226 : sal_Int32 columnIndex,
227 : SQLSMALLINT _nType,
228 : bool &_bWasNull,
229 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
230 : T& _rValue) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
231 : {
232 0 : OTools::getValue(_pConnection,_aStatementHandle,columnIndex,_nType,_bWasNull,_xInterface,&_rValue,sizeof _rValue);
233 0 : }
234 :
235 :
236 :
237 : }
238 : }
239 : #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX
240 :
241 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|