1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "ORealDriver.hxx"
27 #include "odbc/ODriver.hxx"
28 #include "odbc/OTools.hxx"
29 #include "odbc/OFunctions.hxx"
30 #include "diagnose_ex.h"
31
32 namespace connectivity
33 {
34 sal_Bool LoadFunctions(oslModule pODBCso);
35 sal_Bool LoadLibrary_ODBC3(::rtl::OUString &_rPath);
36 // extern declaration of the function pointer
37 extern T3SQLAllocHandle pODBC3SQLAllocHandle;
38 extern T3SQLConnect pODBC3SQLConnect;
39 extern T3SQLDriverConnect pODBC3SQLDriverConnect;
40 extern T3SQLBrowseConnect pODBC3SQLBrowseConnect;
41 extern T3SQLDataSources pODBC3SQLDataSources;
42 extern T3SQLDrivers pODBC3SQLDrivers;
43 extern T3SQLGetInfo pODBC3SQLGetInfo;
44 extern T3SQLGetFunctions pODBC3SQLGetFunctions;
45 extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo;
46 extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr;
47 extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr;
48 extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr;
49 extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr;
50 extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr;
51 extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr;
52 //extern T3SQLSetDescField pODBC3SQLSetDescField;
53 //extern T3SQLGetDescField pODBC3SQLGetDescField;
54 //extern T3SQLGetDescRec pODBC3SQLGetDescRec;
55 //extern T3SQLSetDescRec pODBC3SQLSetDescRec;
56 extern T3SQLPrepare pODBC3SQLPrepare;
57 extern T3SQLBindParameter pODBC3SQLBindParameter;
58 //extern T3SQLGetCursorName pODBC3SQLGetCursorName;
59 extern T3SQLSetCursorName pODBC3SQLSetCursorName;
60 extern T3SQLExecute pODBC3SQLExecute;
61 extern T3SQLExecDirect pODBC3SQLExecDirect;
62 //extern T3SQLNativeSql pODBC3SQLNativeSql;
63 extern T3SQLDescribeParam pODBC3SQLDescribeParam;
64 extern T3SQLNumParams pODBC3SQLNumParams;
65 extern T3SQLParamData pODBC3SQLParamData;
66 extern T3SQLPutData pODBC3SQLPutData;
67 extern T3SQLRowCount pODBC3SQLRowCount;
68 extern T3SQLNumResultCols pODBC3SQLNumResultCols;
69 extern T3SQLDescribeCol pODBC3SQLDescribeCol;
70 extern T3SQLColAttribute pODBC3SQLColAttribute;
71 extern T3SQLBindCol pODBC3SQLBindCol;
72 extern T3SQLFetch pODBC3SQLFetch;
73 extern T3SQLFetchScroll pODBC3SQLFetchScroll;
74 extern T3SQLGetData pODBC3SQLGetData;
75 extern T3SQLSetPos pODBC3SQLSetPos;
76 extern T3SQLBulkOperations pODBC3SQLBulkOperations;
77 extern T3SQLMoreResults pODBC3SQLMoreResults;
78 //extern T3SQLGetDiagField pODBC3SQLGetDiagField;
79 extern T3SQLGetDiagRec pODBC3SQLGetDiagRec;
80 extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges;
81 extern T3SQLColumns pODBC3SQLColumns;
82 extern T3SQLForeignKeys pODBC3SQLForeignKeys;
83 extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys;
84 extern T3SQLProcedureColumns pODBC3SQLProcedureColumns;
85 extern T3SQLProcedures pODBC3SQLProcedures;
86 extern T3SQLSpecialColumns pODBC3SQLSpecialColumns;
87 extern T3SQLStatistics pODBC3SQLStatistics;
88 extern T3SQLTablePrivileges pODBC3SQLTablePrivileges;
89 extern T3SQLTables pODBC3SQLTables;
90 extern T3SQLFreeStmt pODBC3SQLFreeStmt;
91 extern T3SQLCloseCursor pODBC3SQLCloseCursor;
92 extern T3SQLCancel pODBC3SQLCancel;
93 extern T3SQLEndTran pODBC3SQLEndTran;
94 extern T3SQLDisconnect pODBC3SQLDisconnect;
95 extern T3SQLFreeHandle pODBC3SQLFreeHandle;
96 extern T3SQLGetCursorName pODBC3SQLGetCursorName;
97 extern T3SQLNativeSql pODBC3SQLNativeSql;
98
99
100 namespace odbc
101 {
102 class ORealObdcDriver : public ODBCDriver
103 {
104 protected:
105 virtual oslGenericFunction getOdbcFunction(sal_Int32 _nIndex) const;
106 virtual SQLHANDLE EnvironmentHandle(::rtl::OUString &_rPath);
107 public:
ORealObdcDriver(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)108 ORealObdcDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) : ODBCDriver(_rxFactory) {}
109 };
110
111 //------------------------------------------------------------------
getOdbcFunction(sal_Int32 _nIndex) const112 oslGenericFunction ORealObdcDriver::getOdbcFunction(sal_Int32 _nIndex) const
113 {
114 oslGenericFunction pFunction = NULL;
115 switch(_nIndex)
116 {
117 case ODBC3SQLAllocHandle:
118 pFunction = (oslGenericFunction)pODBC3SQLAllocHandle;
119 break;
120 case ODBC3SQLConnect:
121 pFunction = (oslGenericFunction)pODBC3SQLConnect;
122 break;
123 case ODBC3SQLDriverConnect:
124 pFunction = (oslGenericFunction)pODBC3SQLDriverConnect;
125 break;
126 case ODBC3SQLBrowseConnect:
127 pFunction = (oslGenericFunction)pODBC3SQLBrowseConnect;
128 break;
129 case ODBC3SQLDataSources:
130 pFunction = (oslGenericFunction)pODBC3SQLDataSources;
131 break;
132 case ODBC3SQLDrivers:
133 pFunction = (oslGenericFunction)pODBC3SQLDrivers;
134 break;
135 case ODBC3SQLGetInfo:
136
137 pFunction = (oslGenericFunction)pODBC3SQLGetInfo;
138 break;
139 case ODBC3SQLGetFunctions:
140
141 pFunction = (oslGenericFunction)pODBC3SQLGetFunctions;
142 break;
143 case ODBC3SQLGetTypeInfo:
144
145 pFunction = (oslGenericFunction)pODBC3SQLGetTypeInfo;
146 break;
147 case ODBC3SQLSetConnectAttr:
148
149 pFunction = (oslGenericFunction)pODBC3SQLSetConnectAttr;
150 break;
151 case ODBC3SQLGetConnectAttr:
152
153 pFunction = (oslGenericFunction)pODBC3SQLGetConnectAttr;
154 break;
155 case ODBC3SQLSetEnvAttr:
156
157 pFunction = (oslGenericFunction)pODBC3SQLSetEnvAttr;
158 break;
159 case ODBC3SQLGetEnvAttr:
160
161 pFunction = (oslGenericFunction)pODBC3SQLGetEnvAttr;
162 break;
163 case ODBC3SQLSetStmtAttr:
164
165 pFunction = (oslGenericFunction)pODBC3SQLSetStmtAttr;
166 break;
167 case ODBC3SQLGetStmtAttr:
168
169 pFunction = (oslGenericFunction)pODBC3SQLGetStmtAttr;
170 break;
171 case ODBC3SQLPrepare:
172
173 pFunction = (oslGenericFunction)pODBC3SQLPrepare;
174 break;
175 case ODBC3SQLBindParameter:
176
177 pFunction = (oslGenericFunction)pODBC3SQLBindParameter;
178 break;
179 case ODBC3SQLSetCursorName:
180
181 pFunction = (oslGenericFunction)pODBC3SQLSetCursorName;
182 break;
183 case ODBC3SQLExecute:
184
185 pFunction = (oslGenericFunction)pODBC3SQLExecute;
186 break;
187 case ODBC3SQLExecDirect:
188
189 pFunction = (oslGenericFunction)pODBC3SQLExecDirect;
190 break;
191 case ODBC3SQLDescribeParam:
192
193 pFunction = (oslGenericFunction)pODBC3SQLDescribeParam;
194 break;
195 case ODBC3SQLNumParams:
196
197 pFunction = (oslGenericFunction)pODBC3SQLNumParams;
198 break;
199 case ODBC3SQLParamData:
200
201 pFunction = (oslGenericFunction)pODBC3SQLParamData;
202 break;
203 case ODBC3SQLPutData:
204
205 pFunction = (oslGenericFunction)pODBC3SQLPutData;
206 break;
207 case ODBC3SQLRowCount:
208
209 pFunction = (oslGenericFunction)pODBC3SQLRowCount;
210 break;
211 case ODBC3SQLNumResultCols:
212
213 pFunction = (oslGenericFunction)pODBC3SQLNumResultCols;
214 break;
215 case ODBC3SQLDescribeCol:
216
217 pFunction = (oslGenericFunction)pODBC3SQLDescribeCol;
218 break;
219 case ODBC3SQLColAttribute:
220
221 pFunction = (oslGenericFunction)pODBC3SQLColAttribute;
222 break;
223 case ODBC3SQLBindCol:
224
225 pFunction = (oslGenericFunction)pODBC3SQLBindCol;
226 break;
227 case ODBC3SQLFetch:
228
229 pFunction = (oslGenericFunction)pODBC3SQLFetch;
230 break;
231 case ODBC3SQLFetchScroll:
232
233 pFunction = (oslGenericFunction)pODBC3SQLFetchScroll;
234 break;
235 case ODBC3SQLGetData:
236
237 pFunction = (oslGenericFunction)pODBC3SQLGetData;
238 break;
239 case ODBC3SQLSetPos:
240
241 pFunction = (oslGenericFunction)pODBC3SQLSetPos;
242 break;
243 case ODBC3SQLBulkOperations:
244
245 pFunction = (oslGenericFunction)pODBC3SQLBulkOperations;
246 break;
247 case ODBC3SQLMoreResults:
248
249 pFunction = (oslGenericFunction)pODBC3SQLMoreResults;
250 break;
251 case ODBC3SQLGetDiagRec:
252
253 pFunction = (oslGenericFunction)pODBC3SQLGetDiagRec;
254 break;
255 case ODBC3SQLColumnPrivileges:
256
257 pFunction = (oslGenericFunction)pODBC3SQLColumnPrivileges;
258 break;
259 case ODBC3SQLColumns:
260
261 pFunction = (oslGenericFunction)pODBC3SQLColumns;
262 break;
263 case ODBC3SQLForeignKeys:
264
265 pFunction = (oslGenericFunction)pODBC3SQLForeignKeys;
266 break;
267 case ODBC3SQLPrimaryKeys:
268
269 pFunction = (oslGenericFunction)pODBC3SQLPrimaryKeys;
270 break;
271 case ODBC3SQLProcedureColumns:
272
273 pFunction = (oslGenericFunction)pODBC3SQLProcedureColumns;
274 break;
275 case ODBC3SQLProcedures:
276
277 pFunction = (oslGenericFunction)pODBC3SQLProcedures;
278 break;
279 case ODBC3SQLSpecialColumns:
280
281 pFunction = (oslGenericFunction)pODBC3SQLSpecialColumns;
282 break;
283 case ODBC3SQLStatistics:
284
285 pFunction = (oslGenericFunction)pODBC3SQLStatistics;
286 break;
287 case ODBC3SQLTablePrivileges:
288
289 pFunction = (oslGenericFunction)pODBC3SQLTablePrivileges;
290 break;
291 case ODBC3SQLTables:
292
293 pFunction = (oslGenericFunction)pODBC3SQLTables;
294 break;
295 case ODBC3SQLFreeStmt:
296
297 pFunction = (oslGenericFunction)pODBC3SQLFreeStmt;
298 break;
299 case ODBC3SQLCloseCursor:
300
301 pFunction = (oslGenericFunction)pODBC3SQLCloseCursor;
302 break;
303 case ODBC3SQLCancel:
304
305 pFunction = (oslGenericFunction)pODBC3SQLCancel;
306 break;
307 case ODBC3SQLEndTran:
308
309 pFunction = (oslGenericFunction)pODBC3SQLEndTran;
310 break;
311 case ODBC3SQLDisconnect:
312
313 pFunction = (oslGenericFunction)pODBC3SQLDisconnect;
314 break;
315 case ODBC3SQLFreeHandle:
316
317 pFunction = (oslGenericFunction)pODBC3SQLFreeHandle;
318 break;
319 case ODBC3SQLGetCursorName:
320
321 pFunction = (oslGenericFunction)pODBC3SQLGetCursorName;
322 break;
323 case ODBC3SQLNativeSql:
324
325 pFunction = (oslGenericFunction)pODBC3SQLNativeSql;
326 break;
327 default:
328 OSL_ENSURE(0,"Function unknown!");
329 }
330 return pFunction;
331 }
332
333 //------------------------------------------------------------------
ODBCDriver_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)334 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ODBCDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
335 {
336 return *(new ORealObdcDriver(_rxFactory));
337 }
338 // -----------------------------------------------------------------------------
339 // ODBC Environment (gemeinsam fuer alle Connections):
EnvironmentHandle(::rtl::OUString & _rPath)340 SQLHANDLE ORealObdcDriver::EnvironmentHandle(::rtl::OUString &_rPath)
341 {
342 // Ist (fuer diese Instanz) bereits ein Environment erzeugt worden?
343 if (!m_pDriverHandle)
344 {
345 SQLHANDLE h = SQL_NULL_HANDLE;
346 // Environment allozieren
347
348 // ODBC-DLL jetzt laden:
349 if (!LoadLibrary_ODBC3(_rPath) || N3SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&h) != SQL_SUCCESS)
350 return SQL_NULL_HANDLE;
351
352 // In globaler Struktur merken ...
353 m_pDriverHandle = h;
354 SQLRETURN nError = N3SQLSetEnvAttr(h, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
355 OSL_UNUSED( nError );
356 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
357 }
358
359 return m_pDriverHandle;
360 }
361 // -----------------------------------------------------------------------------
362
363 }
364 }
365
366