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