Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / odbc / ORealDriver.cxx
blobba37cb9c5afdccd24ce0691d2c77f6d57bc488d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ORealDriver.hxx"
30 #include "odbc/ODriver.hxx"
31 #include "odbc/OTools.hxx"
32 #include "odbc/OFunctions.hxx"
33 #include "diagnose_ex.h"
35 namespace connectivity
37 sal_Bool LoadFunctions(oslModule pODBCso);
38 sal_Bool LoadLibrary_ODBC3(::rtl::OUString &_rPath);
39 // extern declaration of the function pointer
40 extern T3SQLAllocHandle pODBC3SQLAllocHandle;
41 extern T3SQLConnect pODBC3SQLConnect;
42 extern T3SQLDriverConnect pODBC3SQLDriverConnect;
43 extern T3SQLBrowseConnect pODBC3SQLBrowseConnect;
44 extern T3SQLDataSources pODBC3SQLDataSources;
45 extern T3SQLDrivers pODBC3SQLDrivers;
46 extern T3SQLGetInfo pODBC3SQLGetInfo;
47 extern T3SQLGetFunctions pODBC3SQLGetFunctions;
48 extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo;
49 extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr;
50 extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr;
51 extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr;
52 extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr;
53 extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr;
54 extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr;
55 //extern T3SQLSetDescField pODBC3SQLSetDescField;
56 //extern T3SQLGetDescField pODBC3SQLGetDescField;
57 //extern T3SQLGetDescRec pODBC3SQLGetDescRec;
58 //extern T3SQLSetDescRec pODBC3SQLSetDescRec;
59 extern T3SQLPrepare pODBC3SQLPrepare;
60 extern T3SQLBindParameter pODBC3SQLBindParameter;
61 //extern T3SQLGetCursorName pODBC3SQLGetCursorName;
62 extern T3SQLSetCursorName pODBC3SQLSetCursorName;
63 extern T3SQLExecute pODBC3SQLExecute;
64 extern T3SQLExecDirect pODBC3SQLExecDirect;
65 //extern T3SQLNativeSql pODBC3SQLNativeSql;
66 extern T3SQLDescribeParam pODBC3SQLDescribeParam;
67 extern T3SQLNumParams pODBC3SQLNumParams;
68 extern T3SQLParamData pODBC3SQLParamData;
69 extern T3SQLPutData pODBC3SQLPutData;
70 extern T3SQLRowCount pODBC3SQLRowCount;
71 extern T3SQLNumResultCols pODBC3SQLNumResultCols;
72 extern T3SQLDescribeCol pODBC3SQLDescribeCol;
73 extern T3SQLColAttribute pODBC3SQLColAttribute;
74 extern T3SQLBindCol pODBC3SQLBindCol;
75 extern T3SQLFetch pODBC3SQLFetch;
76 extern T3SQLFetchScroll pODBC3SQLFetchScroll;
77 extern T3SQLGetData pODBC3SQLGetData;
78 extern T3SQLSetPos pODBC3SQLSetPos;
79 extern T3SQLBulkOperations pODBC3SQLBulkOperations;
80 extern T3SQLMoreResults pODBC3SQLMoreResults;
81 //extern T3SQLGetDiagField pODBC3SQLGetDiagField;
82 extern T3SQLGetDiagRec pODBC3SQLGetDiagRec;
83 extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges;
84 extern T3SQLColumns pODBC3SQLColumns;
85 extern T3SQLForeignKeys pODBC3SQLForeignKeys;
86 extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys;
87 extern T3SQLProcedureColumns pODBC3SQLProcedureColumns;
88 extern T3SQLProcedures pODBC3SQLProcedures;
89 extern T3SQLSpecialColumns pODBC3SQLSpecialColumns;
90 extern T3SQLStatistics pODBC3SQLStatistics;
91 extern T3SQLTablePrivileges pODBC3SQLTablePrivileges;
92 extern T3SQLTables pODBC3SQLTables;
93 extern T3SQLFreeStmt pODBC3SQLFreeStmt;
94 extern T3SQLCloseCursor pODBC3SQLCloseCursor;
95 extern T3SQLCancel pODBC3SQLCancel;
96 extern T3SQLEndTran pODBC3SQLEndTran;
97 extern T3SQLDisconnect pODBC3SQLDisconnect;
98 extern T3SQLFreeHandle pODBC3SQLFreeHandle;
99 extern T3SQLGetCursorName pODBC3SQLGetCursorName;
100 extern T3SQLNativeSql pODBC3SQLNativeSql;
103 namespace odbc
105 class ORealObdcDriver : public ODBCDriver
107 protected:
108 virtual oslGenericFunction getOdbcFunction(sal_Int32 _nIndex) const;
109 virtual SQLHANDLE EnvironmentHandle(::rtl::OUString &_rPath);
110 public:
111 ORealObdcDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) : ODBCDriver(_rxFactory) {}
114 //------------------------------------------------------------------
115 oslGenericFunction ORealObdcDriver::getOdbcFunction(sal_Int32 _nIndex) const
117 oslGenericFunction pFunction = NULL;
118 switch(_nIndex)
120 case ODBC3SQLAllocHandle:
121 pFunction = (oslGenericFunction)pODBC3SQLAllocHandle;
122 break;
123 case ODBC3SQLConnect:
124 pFunction = (oslGenericFunction)pODBC3SQLConnect;
125 break;
126 case ODBC3SQLDriverConnect:
127 pFunction = (oslGenericFunction)pODBC3SQLDriverConnect;
128 break;
129 case ODBC3SQLBrowseConnect:
130 pFunction = (oslGenericFunction)pODBC3SQLBrowseConnect;
131 break;
132 case ODBC3SQLDataSources:
133 pFunction = (oslGenericFunction)pODBC3SQLDataSources;
134 break;
135 case ODBC3SQLDrivers:
136 pFunction = (oslGenericFunction)pODBC3SQLDrivers;
137 break;
138 case ODBC3SQLGetInfo:
140 pFunction = (oslGenericFunction)pODBC3SQLGetInfo;
141 break;
142 case ODBC3SQLGetFunctions:
144 pFunction = (oslGenericFunction)pODBC3SQLGetFunctions;
145 break;
146 case ODBC3SQLGetTypeInfo:
148 pFunction = (oslGenericFunction)pODBC3SQLGetTypeInfo;
149 break;
150 case ODBC3SQLSetConnectAttr:
152 pFunction = (oslGenericFunction)pODBC3SQLSetConnectAttr;
153 break;
154 case ODBC3SQLGetConnectAttr:
156 pFunction = (oslGenericFunction)pODBC3SQLGetConnectAttr;
157 break;
158 case ODBC3SQLSetEnvAttr:
160 pFunction = (oslGenericFunction)pODBC3SQLSetEnvAttr;
161 break;
162 case ODBC3SQLGetEnvAttr:
164 pFunction = (oslGenericFunction)pODBC3SQLGetEnvAttr;
165 break;
166 case ODBC3SQLSetStmtAttr:
168 pFunction = (oslGenericFunction)pODBC3SQLSetStmtAttr;
169 break;
170 case ODBC3SQLGetStmtAttr:
172 pFunction = (oslGenericFunction)pODBC3SQLGetStmtAttr;
173 break;
174 case ODBC3SQLPrepare:
176 pFunction = (oslGenericFunction)pODBC3SQLPrepare;
177 break;
178 case ODBC3SQLBindParameter:
180 pFunction = (oslGenericFunction)pODBC3SQLBindParameter;
181 break;
182 case ODBC3SQLSetCursorName:
184 pFunction = (oslGenericFunction)pODBC3SQLSetCursorName;
185 break;
186 case ODBC3SQLExecute:
188 pFunction = (oslGenericFunction)pODBC3SQLExecute;
189 break;
190 case ODBC3SQLExecDirect:
192 pFunction = (oslGenericFunction)pODBC3SQLExecDirect;
193 break;
194 case ODBC3SQLDescribeParam:
196 pFunction = (oslGenericFunction)pODBC3SQLDescribeParam;
197 break;
198 case ODBC3SQLNumParams:
200 pFunction = (oslGenericFunction)pODBC3SQLNumParams;
201 break;
202 case ODBC3SQLParamData:
204 pFunction = (oslGenericFunction)pODBC3SQLParamData;
205 break;
206 case ODBC3SQLPutData:
208 pFunction = (oslGenericFunction)pODBC3SQLPutData;
209 break;
210 case ODBC3SQLRowCount:
212 pFunction = (oslGenericFunction)pODBC3SQLRowCount;
213 break;
214 case ODBC3SQLNumResultCols:
216 pFunction = (oslGenericFunction)pODBC3SQLNumResultCols;
217 break;
218 case ODBC3SQLDescribeCol:
220 pFunction = (oslGenericFunction)pODBC3SQLDescribeCol;
221 break;
222 case ODBC3SQLColAttribute:
224 pFunction = (oslGenericFunction)pODBC3SQLColAttribute;
225 break;
226 case ODBC3SQLBindCol:
228 pFunction = (oslGenericFunction)pODBC3SQLBindCol;
229 break;
230 case ODBC3SQLFetch:
232 pFunction = (oslGenericFunction)pODBC3SQLFetch;
233 break;
234 case ODBC3SQLFetchScroll:
236 pFunction = (oslGenericFunction)pODBC3SQLFetchScroll;
237 break;
238 case ODBC3SQLGetData:
240 pFunction = (oslGenericFunction)pODBC3SQLGetData;
241 break;
242 case ODBC3SQLSetPos:
244 pFunction = (oslGenericFunction)pODBC3SQLSetPos;
245 break;
246 case ODBC3SQLBulkOperations:
248 pFunction = (oslGenericFunction)pODBC3SQLBulkOperations;
249 break;
250 case ODBC3SQLMoreResults:
252 pFunction = (oslGenericFunction)pODBC3SQLMoreResults;
253 break;
254 case ODBC3SQLGetDiagRec:
256 pFunction = (oslGenericFunction)pODBC3SQLGetDiagRec;
257 break;
258 case ODBC3SQLColumnPrivileges:
260 pFunction = (oslGenericFunction)pODBC3SQLColumnPrivileges;
261 break;
262 case ODBC3SQLColumns:
264 pFunction = (oslGenericFunction)pODBC3SQLColumns;
265 break;
266 case ODBC3SQLForeignKeys:
268 pFunction = (oslGenericFunction)pODBC3SQLForeignKeys;
269 break;
270 case ODBC3SQLPrimaryKeys:
272 pFunction = (oslGenericFunction)pODBC3SQLPrimaryKeys;
273 break;
274 case ODBC3SQLProcedureColumns:
276 pFunction = (oslGenericFunction)pODBC3SQLProcedureColumns;
277 break;
278 case ODBC3SQLProcedures:
280 pFunction = (oslGenericFunction)pODBC3SQLProcedures;
281 break;
282 case ODBC3SQLSpecialColumns:
284 pFunction = (oslGenericFunction)pODBC3SQLSpecialColumns;
285 break;
286 case ODBC3SQLStatistics:
288 pFunction = (oslGenericFunction)pODBC3SQLStatistics;
289 break;
290 case ODBC3SQLTablePrivileges:
292 pFunction = (oslGenericFunction)pODBC3SQLTablePrivileges;
293 break;
294 case ODBC3SQLTables:
296 pFunction = (oslGenericFunction)pODBC3SQLTables;
297 break;
298 case ODBC3SQLFreeStmt:
300 pFunction = (oslGenericFunction)pODBC3SQLFreeStmt;
301 break;
302 case ODBC3SQLCloseCursor:
304 pFunction = (oslGenericFunction)pODBC3SQLCloseCursor;
305 break;
306 case ODBC3SQLCancel:
308 pFunction = (oslGenericFunction)pODBC3SQLCancel;
309 break;
310 case ODBC3SQLEndTran:
312 pFunction = (oslGenericFunction)pODBC3SQLEndTran;
313 break;
314 case ODBC3SQLDisconnect:
316 pFunction = (oslGenericFunction)pODBC3SQLDisconnect;
317 break;
318 case ODBC3SQLFreeHandle:
320 pFunction = (oslGenericFunction)pODBC3SQLFreeHandle;
321 break;
322 case ODBC3SQLGetCursorName:
324 pFunction = (oslGenericFunction)pODBC3SQLGetCursorName;
325 break;
326 case ODBC3SQLNativeSql:
328 pFunction = (oslGenericFunction)pODBC3SQLNativeSql;
329 break;
330 default:
331 OSL_FAIL("Function unknown!");
333 return pFunction;
336 //------------------------------------------------------------------
337 ::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 )
339 return *(new ORealObdcDriver(_rxFactory));
341 // -----------------------------------------------------------------------------
342 // ODBC Environment (common for all Connections):
343 SQLHANDLE ORealObdcDriver::EnvironmentHandle(::rtl::OUString &_rPath)
345 // Is (for this instance) already a Enviroment made?
346 if (!m_pDriverHandle)
348 SQLHANDLE h = SQL_NULL_HANDLE;
349 // allocate Environment
351 // load ODBC-DLL now:
352 if (!LoadLibrary_ODBC3(_rPath) || N3SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&h) != SQL_SUCCESS)
353 return SQL_NULL_HANDLE;
355 // Save in global Structure
356 m_pDriverHandle = h;
357 SQLRETURN nError = N3SQLSetEnvAttr(h, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
358 OSL_UNUSED( nError );
359 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
362 return m_pDriverHandle;
364 // -----------------------------------------------------------------------------
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */