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 <sal/config.h>
22 #include <odbc/OConnection.hxx>
23 #include <odbc/ODriver.hxx>
24 #include <resource/sharedresources.hxx>
25 #include <strings.hrc>
27 #include <connectivity/dbexception.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <osl/module.h>
33 using namespace connectivity::odbc
;
34 using namespace com::sun::star::uno
;
35 using namespace com::sun::star::lang
;
36 using namespace com::sun::star::beans
;
37 using namespace com::sun::star::sdbc
;
39 ODBCDriver::ODBCDriver(css::uno::Reference
< css::uno::XComponentContext
> _xContext
)
40 :ODriver_BASE(m_aMutex
)
41 ,m_xContext(std::move(_xContext
))
45 void ODBCDriver::disposing()
47 ::osl::MutexGuard
aGuard(m_aMutex
);
50 for (auto const& connection
: m_xConnections
)
52 Reference
< XComponent
> xComp(connection
.get(), UNO_QUERY
);
56 m_xConnections
.clear();
58 ODriver_BASE::disposing();
63 OUString
ODBCDriver::getImplementationName( )
65 return u
"com.sun.star.comp.sdbc.ODBCDriver"_ustr
;
66 // this name is referenced in the configuration and in the odbc.xml
67 // Please take care when changing it.
71 Sequence
< OUString
> ODBCDriver::getSupportedServiceNames( )
73 return { u
"com.sun.star.sdbc.Driver"_ustr
};
77 sal_Bool SAL_CALL
ODBCDriver::supportsService( const OUString
& _rServiceName
)
79 return cppu::supportsService(this, _rServiceName
);
83 Reference
< XConnection
> SAL_CALL
ODBCDriver::connect( const OUString
& url
, const Sequence
< PropertyValue
>& info
)
85 if ( ! acceptsURL(url
) )
88 rtl::Reference
<OConnection
> pCon
= new OConnection(EnvironmentHandle(), this);
89 pCon
->Construct(url
,info
);
90 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
95 sal_Bool SAL_CALL
ODBCDriver::acceptsURL( const OUString
& url
)
97 return url
.startsWith("sdbc:odbc:");
100 Sequence
< DriverPropertyInfo
> SAL_CALL
ODBCDriver::getPropertyInfo( const OUString
& url
, const Sequence
< PropertyValue
>& /*info*/ )
102 if ( acceptsURL(url
) )
104 Sequence
< OUString
> aBooleanValues
{ u
"false"_ustr
, u
"true"_ustr
};
110 u
"CharSet of the database."_ustr
,
117 u
"Use catalog for file-based databases."_ustr
,
123 u
"SystemDriverSettings"_ustr
,
124 u
"Driver settings."_ustr
,
130 u
"ParameterNameSubstitution"_ustr
,
131 u
"Change named parameters with '?'."_ustr
,
137 u
"IgnoreDriverPrivileges"_ustr
,
138 u
"Ignore the privileges from the database driver."_ustr
,
144 u
"IsAutoRetrievingEnabled"_ustr
,
145 u
"Retrieve generated values."_ustr
,
151 u
"AutoRetrievingStatement"_ustr
,
152 u
"Auto-increment statement."_ustr
,
158 u
"GenerateASBeforeCorrelationName"_ustr
,
159 u
"Generate AS before table correlation names."_ustr
,
165 u
"EscapeDateTime"_ustr
,
166 u
"Escape date time format."_ustr
,
173 ::connectivity::SharedResources aResources
;
174 const OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
175 ::dbtools::throwGenericSQLException(sMessage
,*this);
178 sal_Int32 SAL_CALL
ODBCDriver::getMajorVersion( )
183 sal_Int32 SAL_CALL
ODBCDriver::getMinorVersion( )
188 // Implib definitions for ODBC-DLL/shared library:
192 constinit oslGenericFunction pODBC3SQLFunctions
[static_cast<size_t>(ODBC3SQLFunctionId::LAST
)]{};
194 bool LoadFunctions(oslModule pODBCso
)
196 auto load
= [pODBCso
](ODBC3SQLFunctionId id
, const OUString
& name
)
198 assert(id
> ODBC3SQLFunctionId::FIRST
&& id
< ODBC3SQLFunctionId::LAST
);
199 auto& rpFunc
= pODBC3SQLFunctions
[static_cast<size_t>(id
)];
200 assert(rpFunc
== nullptr);
201 rpFunc
= osl_getFunctionSymbol(pODBCso
, name
.pData
);
202 return rpFunc
!= nullptr;
205 // Optional functions for Unicode support
208 load(ODBC3SQLFunctionId::DriverConnectW
, u
"SQLDriverConnectW"_ustr
);
209 load(ODBC3SQLFunctionId::GetInfoW
, u
"SQLGetInfoW"_ustr
);
210 load(ODBC3SQLFunctionId::SetConnectAttrW
, u
"SQLSetConnectAttrW"_ustr
);
211 load(ODBC3SQLFunctionId::GetConnectAttrW
, u
"SQLGetConnectAttrW"_ustr
);
212 load(ODBC3SQLFunctionId::PrepareW
, u
"SQLPrepareW"_ustr
);
213 load(ODBC3SQLFunctionId::SetCursorNameW
, u
"SQLSetCursorNameW"_ustr
);
214 load(ODBC3SQLFunctionId::ExecDirectW
, u
"SQLExecDirectW"_ustr
);
215 load(ODBC3SQLFunctionId::ColAttributeW
, u
"SQLColAttributeW"_ustr
);
216 load(ODBC3SQLFunctionId::GetDiagRecW
, u
"SQLGetDiagRecW"_ustr
);
217 load(ODBC3SQLFunctionId::ColumnPrivilegesW
, u
"SQLColumnPrivilegesW"_ustr
);
218 load(ODBC3SQLFunctionId::ColumnsW
, u
"SQLColumnsW"_ustr
);
219 load(ODBC3SQLFunctionId::ForeignKeysW
, u
"SQLForeignKeysW"_ustr
);
220 load(ODBC3SQLFunctionId::PrimaryKeysW
, u
"SQLPrimaryKeysW"_ustr
);
221 load(ODBC3SQLFunctionId::ProcedureColumnsW
, u
"SQLProcedureColumnsW"_ustr
);
222 load(ODBC3SQLFunctionId::ProceduresW
, u
"SQLProceduresW"_ustr
);
223 load(ODBC3SQLFunctionId::SpecialColumnsW
, u
"SQLSpecialColumnsW"_ustr
);
224 load(ODBC3SQLFunctionId::StatisticsW
, u
"SQLStatisticsW"_ustr
);
225 load(ODBC3SQLFunctionId::TablePrivilegesW
, u
"SQLTablePrivilegesW"_ustr
);
226 load(ODBC3SQLFunctionId::TablesW
, u
"SQLTablesW"_ustr
);
227 load(ODBC3SQLFunctionId::GetCursorNameW
, u
"SQLGetCursorNameW"_ustr
);
228 load(ODBC3SQLFunctionId::NativeSqlW
, u
"SQLNativeSqlW"_ustr
);
231 return load(ODBC3SQLFunctionId::AllocHandle
, u
"SQLAllocHandle"_ustr
)
232 && load(ODBC3SQLFunctionId::DriverConnect
, u
"SQLDriverConnect"_ustr
)
233 && load(ODBC3SQLFunctionId::GetInfo
, u
"SQLGetInfo"_ustr
)
234 && load(ODBC3SQLFunctionId::GetFunctions
, u
"SQLGetFunctions"_ustr
)
235 && load(ODBC3SQLFunctionId::GetTypeInfo
, u
"SQLGetTypeInfo"_ustr
)
236 && load(ODBC3SQLFunctionId::SetConnectAttr
, u
"SQLSetConnectAttr"_ustr
)
237 && load(ODBC3SQLFunctionId::GetConnectAttr
, u
"SQLGetConnectAttr"_ustr
)
238 && load(ODBC3SQLFunctionId::SetEnvAttr
, u
"SQLSetEnvAttr"_ustr
)
239 && load(ODBC3SQLFunctionId::GetEnvAttr
, u
"SQLGetEnvAttr"_ustr
)
240 && load(ODBC3SQLFunctionId::SetStmtAttr
, u
"SQLSetStmtAttr"_ustr
)
241 && load(ODBC3SQLFunctionId::GetStmtAttr
, u
"SQLGetStmtAttr"_ustr
)
242 && load(ODBC3SQLFunctionId::Prepare
, u
"SQLPrepare"_ustr
)
243 && load(ODBC3SQLFunctionId::BindParameter
, u
"SQLBindParameter"_ustr
)
244 && load(ODBC3SQLFunctionId::SetCursorName
, u
"SQLSetCursorName"_ustr
)
245 && load(ODBC3SQLFunctionId::Execute
, u
"SQLExecute"_ustr
)
246 && load(ODBC3SQLFunctionId::ExecDirect
, u
"SQLExecDirect"_ustr
)
247 && load(ODBC3SQLFunctionId::DescribeParam
, u
"SQLDescribeParam"_ustr
)
248 && load(ODBC3SQLFunctionId::NumParams
, u
"SQLNumParams"_ustr
)
249 && load(ODBC3SQLFunctionId::ParamData
, u
"SQLParamData"_ustr
)
250 && load(ODBC3SQLFunctionId::PutData
, u
"SQLPutData"_ustr
)
251 && load(ODBC3SQLFunctionId::RowCount
, u
"SQLRowCount"_ustr
)
252 && load(ODBC3SQLFunctionId::NumResultCols
, u
"SQLNumResultCols"_ustr
)
253 && load(ODBC3SQLFunctionId::ColAttribute
, u
"SQLColAttribute"_ustr
)
254 && load(ODBC3SQLFunctionId::BindCol
, u
"SQLBindCol"_ustr
)
255 && load(ODBC3SQLFunctionId::Fetch
, u
"SQLFetch"_ustr
)
256 && load(ODBC3SQLFunctionId::FetchScroll
, u
"SQLFetchScroll"_ustr
)
257 && load(ODBC3SQLFunctionId::GetData
, u
"SQLGetData"_ustr
)
258 && load(ODBC3SQLFunctionId::SetPos
, u
"SQLSetPos"_ustr
)
259 && load(ODBC3SQLFunctionId::BulkOperations
, u
"SQLBulkOperations"_ustr
)
260 && load(ODBC3SQLFunctionId::MoreResults
, u
"SQLMoreResults"_ustr
)
261 && load(ODBC3SQLFunctionId::GetDiagRec
, u
"SQLGetDiagRec"_ustr
)
262 && load(ODBC3SQLFunctionId::ColumnPrivileges
, u
"SQLColumnPrivileges"_ustr
)
263 && load(ODBC3SQLFunctionId::Columns
, u
"SQLColumns"_ustr
)
264 && load(ODBC3SQLFunctionId::ForeignKeys
, u
"SQLForeignKeys"_ustr
)
265 && load(ODBC3SQLFunctionId::PrimaryKeys
, u
"SQLPrimaryKeys"_ustr
)
266 && load(ODBC3SQLFunctionId::ProcedureColumns
, u
"SQLProcedureColumns"_ustr
)
267 && load(ODBC3SQLFunctionId::Procedures
, u
"SQLProcedures"_ustr
)
268 && load(ODBC3SQLFunctionId::SpecialColumns
, u
"SQLSpecialColumns"_ustr
)
269 && load(ODBC3SQLFunctionId::Statistics
, u
"SQLStatistics"_ustr
)
270 && load(ODBC3SQLFunctionId::TablePrivileges
, u
"SQLTablePrivileges"_ustr
)
271 && load(ODBC3SQLFunctionId::Tables
, u
"SQLTables"_ustr
)
272 && load(ODBC3SQLFunctionId::FreeStmt
, u
"SQLFreeStmt"_ustr
)
273 && load(ODBC3SQLFunctionId::CloseCursor
, u
"SQLCloseCursor"_ustr
)
274 && load(ODBC3SQLFunctionId::Cancel
, u
"SQLCancel"_ustr
)
275 && load(ODBC3SQLFunctionId::EndTran
, u
"SQLEndTran"_ustr
)
276 && load(ODBC3SQLFunctionId::Disconnect
, u
"SQLDisconnect"_ustr
)
277 && load(ODBC3SQLFunctionId::FreeHandle
, u
"SQLFreeHandle"_ustr
)
278 && load(ODBC3SQLFunctionId::GetCursorName
, u
"SQLGetCursorName"_ustr
)
279 && load(ODBC3SQLFunctionId::NativeSql
, u
"SQLNativeSql"_ustr
);
282 // Take care of Dynamically loading of the DLL/shared lib and Addresses:
283 // Returns sal_True at success
284 bool LoadLibrary_ODBC3(OUString
&_rPath
)
286 static bool bLoaded
= false;
287 static oslModule pODBCso
= nullptr;
291 #ifdef DISABLE_DYNLOADING
295 _rPath
= "ODBC32.DLL";
299 _rPath
= "libiodbc.dylib";
301 _rPath
= "libodbc.so.2";
302 pODBCso
= osl_loadModule( _rPath
.pData
,SAL_LOADMODULE_NOW
);
305 _rPath
= "libodbc.so.1";
306 pODBCso
= osl_loadModule( _rPath
.pData
,SAL_LOADMODULE_NOW
);
309 _rPath
= "libodbc.so";
315 pODBCso
= osl_loadModule( _rPath
.pData
,SAL_LOADMODULE_NOW
);
316 #endif // DISABLE_DYNLOADING
320 bLoaded
= LoadFunctions(pODBCso
);
324 class ORealOdbcDriver
: public connectivity::odbc::ODBCDriver
, public connectivity::odbc::Functions
327 explicit ORealOdbcDriver(const css::uno::Reference
<css::uno::XComponentContext
>& _rxContext
)
328 : ODBCDriver(_rxContext
)
331 const Functions
& functions() const override
{ return *this; }
335 bool has(ODBC3SQLFunctionId id
) const override
337 assert(id
> ODBC3SQLFunctionId::FIRST
&& id
< ODBC3SQLFunctionId::LAST
);
338 return pODBC3SQLFunctions
[static_cast<size_t>(id
)] != nullptr;
341 SQLRETURN
AllocHandle(SQLSMALLINT HandleType
, SQLHANDLE InputHandle
,
342 SQLHANDLE
* OutputHandlePtr
) const override
344 return ODBCFunc(ODBC3SQLFunctionId::AllocHandle
, HandleType
, InputHandle
, OutputHandlePtr
);
347 SQLRETURN
DriverConnect(SQLHDBC ConnectionHandle
, HWND WindowHandle
,
348 SQLCHAR
* InConnectionString
, SQLSMALLINT StringLength1
,
349 SQLCHAR
* OutConnectionString
, SQLSMALLINT BufferLength
,
350 SQLSMALLINT
* StringLength2Ptr
,
351 SQLUSMALLINT DriverCompletion
) const override
353 return ODBCFunc(ODBC3SQLFunctionId::DriverConnect
, ConnectionHandle
, WindowHandle
,
354 InConnectionString
, StringLength1
, OutConnectionString
, BufferLength
,
355 StringLength2Ptr
, DriverCompletion
);
358 SQLRETURN
DriverConnectW(SQLHDBC ConnectionHandle
, HWND WindowHandle
,
359 SQLWCHAR
* InConnectionString
, SQLSMALLINT StringLength1
,
360 SQLWCHAR
* OutConnectionString
, SQLSMALLINT BufferLength
,
361 SQLSMALLINT
* StringLength2Ptr
,
362 SQLUSMALLINT DriverCompletion
) const override
364 return ODBCFunc(ODBC3SQLFunctionId::DriverConnectW
, ConnectionHandle
, WindowHandle
,
365 InConnectionString
, StringLength1
, OutConnectionString
, BufferLength
,
366 StringLength2Ptr
, DriverCompletion
);
369 SQLRETURN
GetInfo(SQLHDBC ConnectionHandle
, SQLUSMALLINT InfoType
, SQLPOINTER InfoValuePtr
,
370 SQLSMALLINT BufferLength
, SQLSMALLINT
* StringLengthPtr
) const override
372 return ODBCFunc(ODBC3SQLFunctionId::GetInfo
, ConnectionHandle
, InfoType
, InfoValuePtr
,
373 BufferLength
, StringLengthPtr
);
376 SQLRETURN
GetInfoW(SQLHDBC ConnectionHandle
, SQLUSMALLINT InfoType
, SQLPOINTER InfoValuePtr
,
377 SQLSMALLINT BufferLength
, SQLSMALLINT
* StringLengthPtr
) const override
379 return ODBCFunc(ODBC3SQLFunctionId::GetInfoW
, ConnectionHandle
, InfoType
, InfoValuePtr
,
380 BufferLength
, StringLengthPtr
);
383 SQLRETURN
GetFunctions(SQLHDBC ConnectionHandle
, SQLUSMALLINT FunctionId
,
384 SQLUSMALLINT
* SupportedPtr
) const override
386 return ODBCFunc(ODBC3SQLFunctionId::GetFunctions
, ConnectionHandle
, FunctionId
,
390 SQLRETURN
GetTypeInfo(SQLHSTMT StatementHandle
, SQLSMALLINT DataType
) const override
392 return ODBCFunc(ODBC3SQLFunctionId::GetTypeInfo
, StatementHandle
, DataType
);
395 SQLRETURN
SetConnectAttr(SQLHDBC ConnectionHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
396 SQLINTEGER StringLength
) const override
398 return ODBCFunc(ODBC3SQLFunctionId::SetConnectAttr
, ConnectionHandle
, Attribute
, ValuePtr
,
402 SQLRETURN
SetConnectAttrW(SQLHDBC ConnectionHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
403 SQLINTEGER StringLength
) const override
405 return ODBCFunc(ODBC3SQLFunctionId::SetConnectAttrW
, ConnectionHandle
, Attribute
, ValuePtr
,
409 SQLRETURN
GetConnectAttr(SQLHDBC ConnectionHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
410 SQLINTEGER BufferLength
, SQLINTEGER
* StringLength
) const override
412 return ODBCFunc(ODBC3SQLFunctionId::GetConnectAttr
, ConnectionHandle
, Attribute
, ValuePtr
,
413 BufferLength
, StringLength
);
416 SQLRETURN
GetConnectAttrW(SQLHDBC ConnectionHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
417 SQLINTEGER BufferLength
, SQLINTEGER
* StringLength
) const override
419 return ODBCFunc(ODBC3SQLFunctionId::GetConnectAttrW
, ConnectionHandle
, Attribute
, ValuePtr
,
420 BufferLength
, StringLength
);
423 SQLRETURN
SetEnvAttr(SQLHENV EnvironmentHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
424 SQLINTEGER StringLength
) const override
426 return ODBCFunc(ODBC3SQLFunctionId::SetEnvAttr
, EnvironmentHandle
, Attribute
, ValuePtr
,
430 SQLRETURN
GetEnvAttr(SQLHENV EnvironmentHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
431 SQLINTEGER BufferLength
, SQLINTEGER
* StringLength
) const override
433 return ODBCFunc(ODBC3SQLFunctionId::GetEnvAttr
, EnvironmentHandle
, Attribute
, ValuePtr
,
434 BufferLength
, StringLength
);
437 SQLRETURN
SetStmtAttr(SQLHSTMT StatementHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
438 SQLINTEGER StringLength
) const override
440 return ODBCFunc(ODBC3SQLFunctionId::SetStmtAttr
, StatementHandle
, Attribute
, ValuePtr
,
444 SQLRETURN
GetStmtAttr(SQLHSTMT StatementHandle
, SQLINTEGER Attribute
, SQLPOINTER ValuePtr
,
445 SQLINTEGER BufferLength
, SQLINTEGER
* StringLength
) const override
447 return ODBCFunc(ODBC3SQLFunctionId::GetStmtAttr
, StatementHandle
, Attribute
, ValuePtr
,
448 BufferLength
, StringLength
);
451 SQLRETURN
Prepare(SQLHSTMT StatementHandle
, SQLCHAR
* StatementText
,
452 SQLINTEGER TextLength
) const override
454 return ODBCFunc(ODBC3SQLFunctionId::Prepare
, StatementHandle
, StatementText
, TextLength
);
457 SQLRETURN
PrepareW(SQLHSTMT StatementHandle
, SQLWCHAR
* StatementText
,
458 SQLINTEGER TextLength
) const override
460 return ODBCFunc(ODBC3SQLFunctionId::PrepareW
, StatementHandle
, StatementText
, TextLength
);
463 SQLRETURN
BindParameter(SQLHSTMT StatementHandle
, SQLUSMALLINT ParameterNumber
,
464 SQLSMALLINT InputOutputType
, SQLSMALLINT ValueType
,
465 SQLSMALLINT ParameterType
, SQLULEN ColumnSize
,
466 SQLSMALLINT DecimalDigits
, SQLPOINTER ParameterValuePtr
,
467 SQLLEN BufferLength
, SQLLEN
* StrLen_or_IndPtr
) const override
469 return ODBCFunc(ODBC3SQLFunctionId::BindParameter
, StatementHandle
, ParameterNumber
,
470 InputOutputType
, ValueType
, ParameterType
, ColumnSize
, DecimalDigits
,
471 ParameterValuePtr
, BufferLength
, StrLen_or_IndPtr
);
474 SQLRETURN
SetCursorName(SQLHSTMT StatementHandle
, SQLCHAR
* CursorName
,
475 SQLSMALLINT NameLength
) const override
477 return ODBCFunc(ODBC3SQLFunctionId::SetCursorName
, StatementHandle
, CursorName
, NameLength
);
480 SQLRETURN
SetCursorNameW(SQLHSTMT StatementHandle
, SQLWCHAR
* CursorName
,
481 SQLSMALLINT NameLength
) const override
483 return ODBCFunc(ODBC3SQLFunctionId::SetCursorNameW
, StatementHandle
, CursorName
, NameLength
);
486 SQLRETURN
Execute(SQLHSTMT StatementHandle
) const override
488 return ODBCFunc(ODBC3SQLFunctionId::Execute
, StatementHandle
);
491 SQLRETURN
ExecDirect(SQLHSTMT StatementHandle
, SQLCHAR
* StatementText
,
492 SQLINTEGER TextLength
) const override
494 return ODBCFunc(ODBC3SQLFunctionId::ExecDirect
, StatementHandle
, StatementText
, TextLength
);
497 SQLRETURN
ExecDirectW(SQLHSTMT StatementHandle
, SQLWCHAR
* StatementText
,
498 SQLINTEGER TextLength
) const override
500 return ODBCFunc(ODBC3SQLFunctionId::ExecDirectW
, StatementHandle
, StatementText
, TextLength
);
503 SQLRETURN
DescribeParam(SQLHSTMT StatementHandle
, SQLUSMALLINT ParameterNumber
,
504 SQLSMALLINT
* DataTypePtr
, SQLULEN
* ParameterSizePtr
,
505 SQLSMALLINT
* DecimalDigitsPtr
, SQLSMALLINT
* NullablePtr
) const override
507 return ODBCFunc(ODBC3SQLFunctionId::DescribeParam
, StatementHandle
, ParameterNumber
,
508 DataTypePtr
, ParameterSizePtr
, DecimalDigitsPtr
, NullablePtr
);
511 SQLRETURN
NumParams(SQLHSTMT StatementHandle
, SQLSMALLINT
* ParameterCountPtr
) const override
513 return ODBCFunc(ODBC3SQLFunctionId::NumParams
, StatementHandle
, ParameterCountPtr
);
516 SQLRETURN
ParamData(SQLHSTMT StatementHandle
, SQLPOINTER
* ValuePtrPtr
) const override
518 return ODBCFunc(ODBC3SQLFunctionId::ParamData
, StatementHandle
, ValuePtrPtr
);
521 SQLRETURN
PutData(SQLHSTMT StatementHandle
, SQLPOINTER DataPtr
,
522 SQLLEN StrLen_or_Ind
) const override
524 return ODBCFunc(ODBC3SQLFunctionId::PutData
, StatementHandle
, DataPtr
, StrLen_or_Ind
);
527 SQLRETURN
RowCount(SQLHSTMT StatementHandle
, SQLLEN
* RowCountPtr
) const override
529 return ODBCFunc(ODBC3SQLFunctionId::RowCount
, StatementHandle
, RowCountPtr
);
532 SQLRETURN
NumResultCols(SQLHSTMT StatementHandle
, SQLSMALLINT
* ColumnCountPtr
) const override
534 return ODBCFunc(ODBC3SQLFunctionId::NumResultCols
, StatementHandle
, ColumnCountPtr
);
537 SQLRETURN
ColAttribute(SQLHSTMT StatementHandle
, SQLUSMALLINT ColumnNumber
,
538 SQLUSMALLINT FieldIdentifier
, SQLPOINTER CharacterAttributePtr
,
539 SQLSMALLINT BufferLength
, SQLSMALLINT
* StringLengthPtr
,
540 SQLLEN
* NumericAttributePtr
) const override
542 return ODBCFunc(ODBC3SQLFunctionId::ColAttribute
, StatementHandle
, ColumnNumber
,
543 FieldIdentifier
, CharacterAttributePtr
, BufferLength
, StringLengthPtr
,
544 NumericAttributePtr
);
547 SQLRETURN
ColAttributeW(SQLHSTMT StatementHandle
, SQLUSMALLINT ColumnNumber
,
548 SQLUSMALLINT FieldIdentifier
, SQLPOINTER CharacterAttributePtr
,
549 SQLSMALLINT BufferLength
, SQLSMALLINT
* StringLengthPtr
,
550 SQLLEN
* NumericAttributePtr
) const override
552 return ODBCFunc(ODBC3SQLFunctionId::ColAttributeW
, StatementHandle
, ColumnNumber
,
553 FieldIdentifier
, CharacterAttributePtr
, BufferLength
, StringLengthPtr
,
554 NumericAttributePtr
);
557 SQLRETURN
BindCol(SQLHSTMT StatementHandle
, SQLUSMALLINT ColumnNumber
, SQLSMALLINT TargetType
,
558 SQLPOINTER TargetValuePtr
, SQLLEN BufferLength
,
559 SQLLEN
* StrLen_or_IndPtr
) const override
561 return ODBCFunc(ODBC3SQLFunctionId::BindCol
, StatementHandle
, ColumnNumber
, TargetType
,
562 TargetValuePtr
, BufferLength
, StrLen_or_IndPtr
);
565 SQLRETURN
Fetch(SQLHSTMT StatementHandle
) const override
567 return ODBCFunc(ODBC3SQLFunctionId::Fetch
, StatementHandle
);
570 SQLRETURN
FetchScroll(SQLHSTMT StatementHandle
, SQLSMALLINT FetchOrientation
,
571 SQLLEN FetchOffset
) const override
573 return ODBCFunc(ODBC3SQLFunctionId::FetchScroll
, StatementHandle
, FetchOrientation
,
577 SQLRETURN
GetData(SQLHSTMT StatementHandle
, SQLUSMALLINT ColumnNumber
, SQLSMALLINT TargetType
,
578 SQLPOINTER TargetValuePtr
, SQLLEN BufferLength
,
579 SQLLEN
* StrLen_or_IndPtr
) const override
581 return ODBCFunc(ODBC3SQLFunctionId::GetData
, StatementHandle
, ColumnNumber
, TargetType
,
582 TargetValuePtr
, BufferLength
, StrLen_or_IndPtr
);
585 SQLRETURN
SetPos(SQLHSTMT StatementHandle
, SQLSETPOSIROW RowNumber
, SQLUSMALLINT Operation
,
586 SQLUSMALLINT LockType
) const override
588 return ODBCFunc(ODBC3SQLFunctionId::SetPos
, StatementHandle
, RowNumber
, Operation
,
592 SQLRETURN
BulkOperations(SQLHSTMT StatementHandle
, SQLSMALLINT Operation
) const override
594 return ODBCFunc(ODBC3SQLFunctionId::BulkOperations
, StatementHandle
, Operation
);
597 SQLRETURN
MoreResults(SQLHSTMT StatementHandle
) const override
599 return ODBCFunc(ODBC3SQLFunctionId::MoreResults
, StatementHandle
);
602 SQLRETURN
GetDiagRec(SQLSMALLINT HandleType
, SQLHANDLE Handle
, SQLSMALLINT RecNumber
,
603 SQLCHAR
* Sqlstate
, SQLINTEGER
* NativeErrorPtr
, SQLCHAR
* MessageText
,
604 SQLSMALLINT BufferLength
, SQLSMALLINT
* TextLengthPtr
) const override
606 return ODBCFunc(ODBC3SQLFunctionId::GetDiagRec
, HandleType
, Handle
, RecNumber
, Sqlstate
,
607 NativeErrorPtr
, MessageText
, BufferLength
, TextLengthPtr
);
610 SQLRETURN
GetDiagRecW(SQLSMALLINT HandleType
, SQLHANDLE Handle
, SQLSMALLINT RecNumber
,
611 SQLWCHAR
* Sqlstate
, SQLINTEGER
* NativeErrorPtr
, SQLWCHAR
* MessageText
,
612 SQLSMALLINT BufferLength
, SQLSMALLINT
* TextLengthPtr
) const override
614 return ODBCFunc(ODBC3SQLFunctionId::GetDiagRecW
, HandleType
, Handle
, RecNumber
, Sqlstate
,
615 NativeErrorPtr
, MessageText
, BufferLength
, TextLengthPtr
);
618 SQLRETURN
ColumnPrivileges(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
,
619 SQLSMALLINT NameLength1
, SQLCHAR
* SchemaName
,
620 SQLSMALLINT NameLength2
, SQLCHAR
* TableName
, SQLSMALLINT NameLength3
,
621 SQLCHAR
* ColumnName
, SQLSMALLINT NameLength4
) const override
623 return ODBCFunc(ODBC3SQLFunctionId::ColumnPrivileges
, StatementHandle
, CatalogName
,
624 NameLength1
, SchemaName
, NameLength2
, TableName
, NameLength3
, ColumnName
,
628 SQLRETURN
ColumnPrivilegesW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
,
629 SQLSMALLINT NameLength1
, SQLWCHAR
* SchemaName
,
630 SQLSMALLINT NameLength2
, SQLWCHAR
* TableName
, SQLSMALLINT NameLength3
,
631 SQLWCHAR
* ColumnName
, SQLSMALLINT NameLength4
) const override
633 return ODBCFunc(ODBC3SQLFunctionId::ColumnPrivilegesW
, StatementHandle
, CatalogName
,
634 NameLength1
, SchemaName
, NameLength2
, TableName
, NameLength3
, ColumnName
,
638 SQLRETURN
Columns(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
639 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLCHAR
* TableName
,
640 SQLSMALLINT NameLength3
, SQLCHAR
* ColumnName
,
641 SQLSMALLINT NameLength4
) const override
643 return ODBCFunc(ODBC3SQLFunctionId::Columns
, StatementHandle
, CatalogName
, NameLength1
,
644 SchemaName
, NameLength2
, TableName
, NameLength3
, ColumnName
, NameLength4
);
647 SQLRETURN
ColumnsW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
648 SQLWCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLWCHAR
* TableName
,
649 SQLSMALLINT NameLength3
, SQLWCHAR
* ColumnName
,
650 SQLSMALLINT NameLength4
) const override
652 return ODBCFunc(ODBC3SQLFunctionId::ColumnsW
, StatementHandle
, CatalogName
, NameLength1
,
653 SchemaName
, NameLength2
, TableName
, NameLength3
, ColumnName
, NameLength4
);
656 SQLRETURN
ForeignKeys(SQLHSTMT StatementHandle
, SQLCHAR
* PKCatalogName
, SQLSMALLINT NameLength1
,
657 SQLCHAR
* PKSchemaName
, SQLSMALLINT NameLength2
, SQLCHAR
* PKTableName
,
658 SQLSMALLINT NameLength3
, SQLCHAR
* FKCatalogName
, SQLSMALLINT NameLength4
,
659 SQLCHAR
* FKSchemaName
, SQLSMALLINT NameLength5
, SQLCHAR
* FKTableName
,
660 SQLSMALLINT NameLength6
) const override
662 return ODBCFunc(ODBC3SQLFunctionId::ForeignKeys
, StatementHandle
, PKCatalogName
,
663 NameLength1
, PKSchemaName
, NameLength2
, PKTableName
, NameLength3
,
664 FKCatalogName
, NameLength4
, FKSchemaName
, NameLength5
, FKTableName
,
668 SQLRETURN
ForeignKeysW(SQLHSTMT StatementHandle
, SQLWCHAR
* PKCatalogName
, SQLSMALLINT NameLength1
,
669 SQLWCHAR
* PKSchemaName
, SQLSMALLINT NameLength2
, SQLWCHAR
* PKTableName
,
670 SQLSMALLINT NameLength3
, SQLWCHAR
* FKCatalogName
, SQLSMALLINT NameLength4
,
671 SQLWCHAR
* FKSchemaName
, SQLSMALLINT NameLength5
, SQLWCHAR
* FKTableName
,
672 SQLSMALLINT NameLength6
) const override
674 return ODBCFunc(ODBC3SQLFunctionId::ForeignKeysW
, StatementHandle
, PKCatalogName
,
675 NameLength1
, PKSchemaName
, NameLength2
, PKTableName
, NameLength3
,
676 FKCatalogName
, NameLength4
, FKSchemaName
, NameLength5
, FKTableName
,
680 SQLRETURN
PrimaryKeys(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
681 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLCHAR
* TableName
,
682 SQLSMALLINT NameLength3
) const override
684 return ODBCFunc(ODBC3SQLFunctionId::PrimaryKeys
, StatementHandle
, CatalogName
, NameLength1
,
685 SchemaName
, NameLength2
, TableName
, NameLength3
);
688 SQLRETURN
PrimaryKeysW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
689 SQLWCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLWCHAR
* TableName
,
690 SQLSMALLINT NameLength3
) const override
692 return ODBCFunc(ODBC3SQLFunctionId::PrimaryKeysW
, StatementHandle
, CatalogName
, NameLength1
,
693 SchemaName
, NameLength2
, TableName
, NameLength3
);
696 SQLRETURN
ProcedureColumns(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
,
697 SQLSMALLINT NameLength1
, SQLCHAR
* SchemaName
,
698 SQLSMALLINT NameLength2
, SQLCHAR
* ProcName
, SQLSMALLINT NameLength3
,
699 SQLCHAR
* ColumnName
, SQLSMALLINT NameLength4
) const override
701 return ODBCFunc(ODBC3SQLFunctionId::ProcedureColumns
, StatementHandle
, CatalogName
,
702 NameLength1
, SchemaName
, NameLength2
, ProcName
, NameLength3
, ColumnName
,
706 SQLRETURN
ProcedureColumnsW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
,
707 SQLSMALLINT NameLength1
, SQLWCHAR
* SchemaName
,
708 SQLSMALLINT NameLength2
, SQLWCHAR
* ProcName
, SQLSMALLINT NameLength3
,
709 SQLWCHAR
* ColumnName
, SQLSMALLINT NameLength4
) const override
711 return ODBCFunc(ODBC3SQLFunctionId::ProcedureColumnsW
, StatementHandle
, CatalogName
,
712 NameLength1
, SchemaName
, NameLength2
, ProcName
, NameLength3
, ColumnName
,
716 SQLRETURN
Procedures(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
717 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLCHAR
* ProcName
,
718 SQLSMALLINT NameLength3
) const override
720 return ODBCFunc(ODBC3SQLFunctionId::Procedures
, StatementHandle
, CatalogName
, NameLength1
,
721 SchemaName
, NameLength2
, ProcName
, NameLength3
);
724 SQLRETURN
ProceduresW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
725 SQLWCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLWCHAR
* ProcName
,
726 SQLSMALLINT NameLength3
) const override
728 return ODBCFunc(ODBC3SQLFunctionId::ProceduresW
, StatementHandle
, CatalogName
, NameLength1
,
729 SchemaName
, NameLength2
, ProcName
, NameLength3
);
732 SQLRETURN
SpecialColumns(SQLHSTMT StatementHandle
, SQLUSMALLINT IdentifierType
,
733 SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
, SQLCHAR
* SchemaName
,
734 SQLSMALLINT NameLength2
, SQLCHAR
* TableName
, SQLSMALLINT NameLength3
,
735 SQLUSMALLINT Scope
, SQLUSMALLINT Nullable
) const override
737 return ODBCFunc(ODBC3SQLFunctionId::SpecialColumns
, StatementHandle
, IdentifierType
,
738 CatalogName
, NameLength1
, SchemaName
, NameLength2
, TableName
, NameLength3
,
742 SQLRETURN
SpecialColumnsW(SQLHSTMT StatementHandle
, SQLUSMALLINT IdentifierType
,
743 SQLWCHAR
* CatalogName
, SQLSMALLINT NameLength1
, SQLWCHAR
* SchemaName
,
744 SQLSMALLINT NameLength2
, SQLWCHAR
* TableName
, SQLSMALLINT NameLength3
,
745 SQLUSMALLINT Scope
, SQLUSMALLINT Nullable
) const override
747 return ODBCFunc(ODBC3SQLFunctionId::SpecialColumnsW
, StatementHandle
, IdentifierType
,
748 CatalogName
, NameLength1
, SchemaName
, NameLength2
, TableName
, NameLength3
,
752 SQLRETURN
Statistics(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
753 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLCHAR
* TableName
,
754 SQLSMALLINT NameLength3
, SQLUSMALLINT Unique
,
755 SQLUSMALLINT Reserved
) const override
757 return ODBCFunc(ODBC3SQLFunctionId::Statistics
, StatementHandle
, CatalogName
, NameLength1
,
758 SchemaName
, NameLength2
, TableName
, NameLength3
, Unique
, Reserved
);
761 SQLRETURN
StatisticsW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
762 SQLWCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLWCHAR
* TableName
,
763 SQLSMALLINT NameLength3
, SQLUSMALLINT Unique
,
764 SQLUSMALLINT Reserved
) const override
766 return ODBCFunc(ODBC3SQLFunctionId::StatisticsW
, StatementHandle
, CatalogName
, NameLength1
,
767 SchemaName
, NameLength2
, TableName
, NameLength3
, Unique
, Reserved
);
770 SQLRETURN
TablePrivileges(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
,
771 SQLSMALLINT NameLength1
, SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
,
772 SQLCHAR
* TableName
, SQLSMALLINT NameLength3
) const override
774 return ODBCFunc(ODBC3SQLFunctionId::TablePrivileges
, StatementHandle
, CatalogName
,
775 NameLength1
, SchemaName
, NameLength2
, TableName
, NameLength3
);
778 SQLRETURN
TablePrivilegesW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
,
779 SQLSMALLINT NameLength1
, SQLWCHAR
* SchemaName
, SQLSMALLINT NameLength2
,
780 SQLWCHAR
* TableName
, SQLSMALLINT NameLength3
) const override
782 return ODBCFunc(ODBC3SQLFunctionId::TablePrivilegesW
, StatementHandle
, CatalogName
,
783 NameLength1
, SchemaName
, NameLength2
, TableName
, NameLength3
);
786 SQLRETURN
Tables(SQLHSTMT StatementHandle
, SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
787 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLCHAR
* TableName
,
788 SQLSMALLINT NameLength3
, SQLCHAR
* TableType
,
789 SQLSMALLINT NameLength4
) const override
791 return ODBCFunc(ODBC3SQLFunctionId::Tables
, StatementHandle
, CatalogName
, NameLength1
,
792 SchemaName
, NameLength2
, TableName
, NameLength3
, TableType
, NameLength4
);
795 SQLRETURN
TablesW(SQLHSTMT StatementHandle
, SQLWCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
796 SQLWCHAR
* SchemaName
, SQLSMALLINT NameLength2
, SQLWCHAR
* TableName
,
797 SQLSMALLINT NameLength3
, SQLWCHAR
* TableType
,
798 SQLSMALLINT NameLength4
) const override
800 return ODBCFunc(ODBC3SQLFunctionId::TablesW
, StatementHandle
, CatalogName
, NameLength1
,
801 SchemaName
, NameLength2
, TableName
, NameLength3
, TableType
, NameLength4
);
804 SQLRETURN
FreeStmt(SQLHSTMT StatementHandle
, SQLUSMALLINT Option
) const override
806 return ODBCFunc(ODBC3SQLFunctionId::FreeStmt
, StatementHandle
, Option
);
809 SQLRETURN
CloseCursor(SQLHSTMT StatementHandle
) const override
811 return ODBCFunc(ODBC3SQLFunctionId::CloseCursor
, StatementHandle
);
814 SQLRETURN
Cancel(SQLHSTMT StatementHandle
) const override
816 return ODBCFunc(ODBC3SQLFunctionId::Cancel
, StatementHandle
);
819 SQLRETURN
EndTran(SQLSMALLINT HandleType
, SQLHANDLE Handle
,
820 SQLSMALLINT CompletionType
) const override
822 return ODBCFunc(ODBC3SQLFunctionId::EndTran
, HandleType
, Handle
, CompletionType
);
825 SQLRETURN
Disconnect(SQLHDBC ConnectionHandle
) const override
827 return ODBCFunc(ODBC3SQLFunctionId::Disconnect
, ConnectionHandle
);
830 SQLRETURN
FreeHandle(SQLSMALLINT HandleType
, SQLHANDLE Handle
) const override
832 return ODBCFunc(ODBC3SQLFunctionId::FreeHandle
, HandleType
, Handle
);
835 SQLRETURN
GetCursorName(SQLHSTMT StatementHandle
, SQLCHAR
* CursorName
, SQLSMALLINT BufferLength
,
836 SQLSMALLINT
* NameLength2
) const override
838 return ODBCFunc(ODBC3SQLFunctionId::GetCursorName
, StatementHandle
, CursorName
,
839 BufferLength
, NameLength2
);
842 SQLRETURN
GetCursorNameW(SQLHSTMT StatementHandle
, SQLWCHAR
* CursorName
, SQLSMALLINT BufferLength
,
843 SQLSMALLINT
* NameLength2
) const override
845 return ODBCFunc(ODBC3SQLFunctionId::GetCursorNameW
, StatementHandle
, CursorName
,
846 BufferLength
, NameLength2
);
849 SQLRETURN
NativeSql(SQLHDBC ConnectionHandle
, SQLCHAR
* InStatementText
, SQLINTEGER TextLength1
,
850 SQLCHAR
* OutStatementText
, SQLINTEGER BufferLength
,
851 SQLINTEGER
* TextLength2Ptr
) const override
853 return ODBCFunc(ODBC3SQLFunctionId::NativeSql
, ConnectionHandle
, InStatementText
,
854 TextLength1
, OutStatementText
, BufferLength
, TextLength2Ptr
);
857 SQLRETURN
NativeSqlW(SQLHDBC ConnectionHandle
, SQLWCHAR
* InStatementText
, SQLINTEGER TextLength1
,
858 SQLWCHAR
* OutStatementText
, SQLINTEGER BufferLength
,
859 SQLINTEGER
* TextLength2Ptr
) const override
861 return ODBCFunc(ODBC3SQLFunctionId::NativeSqlW
, ConnectionHandle
, InStatementText
,
862 TextLength1
, OutStatementText
, BufferLength
, TextLength2Ptr
);
866 virtual SQLHANDLE
EnvironmentHandle() override
;
869 template <typename
... Args
> static SQLRETURN
ODBCFunc(ODBC3SQLFunctionId id
, Args
... args
)
871 assert(id
> ODBC3SQLFunctionId::FIRST
&& id
< ODBC3SQLFunctionId::LAST
);
872 assert(pODBC3SQLFunctions
[static_cast<size_t>(id
)]);
873 using Func_t
= SQLRETURN(SQL_API
*)(Args
...);
874 return (*reinterpret_cast<Func_t
>(pODBC3SQLFunctions
[static_cast<size_t>(id
)]))(args
...);
877 SQLHANDLE m_pDriverHandle
= SQL_NULL_HANDLE
;
880 // ODBC Environment (common for all Connections):
881 SQLHANDLE
ORealOdbcDriver::EnvironmentHandle()
883 // Is (for this instance) already an Environment made?
884 if (m_pDriverHandle
== SQL_NULL_HANDLE
)
887 SQLHANDLE h
= SQL_NULL_HANDLE
;
888 // allocate Environment
889 // load ODBC-DLL now:
890 if (!LoadLibrary_ODBC3(aPath
)
891 || AllocHandle(SQL_HANDLE_ENV
, SQL_NULL_HANDLE
, &h
) != SQL_SUCCESS
)
892 dbtools::throwSQLException(aPath
, OUString(), *this, 1000);
894 // Save in global Structure
896 SetEnvAttr(h
, SQL_ATTR_ODBC_VERSION
, reinterpret_cast<SQLPOINTER
>(SQL_OV_ODBC3
),
898 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
901 return m_pDriverHandle
;
905 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
906 connectivity_odbc_ORealOdbcDriver_get_implementation(css::uno::XComponentContext
* context
,
907 css::uno::Sequence
<css::uno::Any
> const&)
909 return cppu::acquire(new ORealOdbcDriver(context
));
912 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */