1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 namespace connectivity
29 class ORealObdcDriver
: public ODBCDriver
32 virtual oslGenericFunction
getOdbcFunction(ODBC3SQLFunctionId _nIndex
) const override
;
33 virtual SQLHANDLE
EnvironmentHandle(OUString
&_rPath
) override
;
35 explicit ORealObdcDriver(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& _rxFactory
) : ODBCDriver(_rxFactory
) {}
39 oslGenericFunction
ORealObdcDriver::getOdbcFunction(ODBC3SQLFunctionId _nIndex
) const
41 oslGenericFunction pFunction
= nullptr;
44 case ODBC3SQLFunctionId::AllocHandle
:
45 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLAllocHandle
);
47 case ODBC3SQLFunctionId::Connect
:
48 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLConnect
);
50 case ODBC3SQLFunctionId::DriverConnect
:
51 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLDriverConnect
);
53 case ODBC3SQLFunctionId::BrowseConnect
:
54 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLBrowseConnect
);
56 case ODBC3SQLFunctionId::DataSources
:
57 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLDataSources
);
59 case ODBC3SQLFunctionId::Drivers
:
60 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLDrivers
);
62 case ODBC3SQLFunctionId::GetInfo
:
64 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetInfo
);
66 case ODBC3SQLFunctionId::GetFunctions
:
68 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetFunctions
);
70 case ODBC3SQLFunctionId::GetTypeInfo
:
72 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetTypeInfo
);
74 case ODBC3SQLFunctionId::SetConnectAttr
:
76 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLSetConnectAttr
);
78 case ODBC3SQLFunctionId::GetConnectAttr
:
80 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetConnectAttr
);
82 case ODBC3SQLFunctionId::SetEnvAttr
:
84 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLSetEnvAttr
);
86 case ODBC3SQLFunctionId::GetEnvAttr
:
88 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetEnvAttr
);
90 case ODBC3SQLFunctionId::SetStmtAttr
:
92 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLSetStmtAttr
);
94 case ODBC3SQLFunctionId::GetStmtAttr
:
96 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetStmtAttr
);
98 case ODBC3SQLFunctionId::Prepare
:
100 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLPrepare
);
102 case ODBC3SQLFunctionId::BindParameter
:
104 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLBindParameter
);
106 case ODBC3SQLFunctionId::SetCursorName
:
108 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLSetCursorName
);
110 case ODBC3SQLFunctionId::Execute
:
112 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLExecute
);
114 case ODBC3SQLFunctionId::ExecDirect
:
116 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLExecDirect
);
118 case ODBC3SQLFunctionId::DescribeParam
:
120 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLDescribeParam
);
122 case ODBC3SQLFunctionId::NumParams
:
124 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLNumParams
);
126 case ODBC3SQLFunctionId::ParamData
:
128 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLParamData
);
130 case ODBC3SQLFunctionId::PutData
:
132 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLPutData
);
134 case ODBC3SQLFunctionId::RowCount
:
136 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLRowCount
);
138 case ODBC3SQLFunctionId::NumResultCols
:
140 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLNumResultCols
);
142 case ODBC3SQLFunctionId::DescribeCol
:
144 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLDescribeCol
);
146 case ODBC3SQLFunctionId::ColAttribute
:
148 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLColAttribute
);
150 case ODBC3SQLFunctionId::BindCol
:
152 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLBindCol
);
154 case ODBC3SQLFunctionId::Fetch
:
156 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLFetch
);
158 case ODBC3SQLFunctionId::FetchScroll
:
160 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLFetchScroll
);
162 case ODBC3SQLFunctionId::GetData
:
164 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetData
);
166 case ODBC3SQLFunctionId::SetPos
:
168 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLSetPos
);
170 case ODBC3SQLFunctionId::BulkOperations
:
172 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLBulkOperations
);
174 case ODBC3SQLFunctionId::MoreResults
:
176 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLMoreResults
);
178 case ODBC3SQLFunctionId::GetDiagRec
:
180 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetDiagRec
);
182 case ODBC3SQLFunctionId::ColumnPrivileges
:
184 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLColumnPrivileges
);
186 case ODBC3SQLFunctionId::Columns
:
188 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLColumns
);
190 case ODBC3SQLFunctionId::ForeignKeys
:
192 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLForeignKeys
);
194 case ODBC3SQLFunctionId::PrimaryKeys
:
196 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLPrimaryKeys
);
198 case ODBC3SQLFunctionId::ProcedureColumns
:
200 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLProcedureColumns
);
202 case ODBC3SQLFunctionId::Procedures
:
204 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLProcedures
);
206 case ODBC3SQLFunctionId::SpecialColumns
:
208 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLSpecialColumns
);
210 case ODBC3SQLFunctionId::Statistics
:
212 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLStatistics
);
214 case ODBC3SQLFunctionId::TablePrivileges
:
216 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLTablePrivileges
);
218 case ODBC3SQLFunctionId::Tables
:
220 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLTables
);
222 case ODBC3SQLFunctionId::FreeStmt
:
224 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLFreeStmt
);
226 case ODBC3SQLFunctionId::CloseCursor
:
228 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLCloseCursor
);
230 case ODBC3SQLFunctionId::Cancel
:
232 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLCancel
);
234 case ODBC3SQLFunctionId::EndTran
:
236 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLEndTran
);
238 case ODBC3SQLFunctionId::Disconnect
:
240 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLDisconnect
);
242 case ODBC3SQLFunctionId::FreeHandle
:
244 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLFreeHandle
);
246 case ODBC3SQLFunctionId::GetCursorName
:
248 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLGetCursorName
);
250 case ODBC3SQLFunctionId::NativeSql
:
252 pFunction
= reinterpret_cast<oslGenericFunction
>(pODBC3SQLNativeSql
);
255 OSL_FAIL("Function unknown!");
261 css::uno::Reference
< css::uno::XInterface
> ODBCDriver_CreateInstance(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& _rxFactory
)
263 return *(new ORealObdcDriver(_rxFactory
));
266 // ODBC Environment (common for all Connections):
267 SQLHANDLE
ORealObdcDriver::EnvironmentHandle(OUString
&_rPath
)
269 // Is (for this instance) already an Environment made?
270 if (!m_pDriverHandle
)
272 SQLHANDLE h
= SQL_NULL_HANDLE
;
273 // allocate Environment
275 // load ODBC-DLL now:
276 if (!LoadLibrary_ODBC3(_rPath
) || N3SQLAllocHandle(SQL_HANDLE_ENV
,SQL_NULL_HANDLE
,&h
) != SQL_SUCCESS
)
277 return SQL_NULL_HANDLE
;
279 // Save in global Structure
281 N3SQLSetEnvAttr(h
, SQL_ATTR_ODBC_VERSION
, reinterpret_cast<SQLPOINTER
>(SQL_OV_ODBC3
), SQL_IS_UINTEGER
);
282 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
285 return m_pDriverHandle
;
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */