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