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