32#include <com/sun/star/sdbc/ColumnValue.hpp>
33#include <com/sun/star/sdbc/TransactionIsolation.hpp>
34#include <com/sun/star/sdbc/XRow.hpp>
35#include <com/sun/star/lang/DisposedException.hpp>
39#include <osl/file.hxx>
40#include <systools/win32/oleauto.hxx>
54OConnection::OConnection(
ODriver* _pDriver)
55 : m_xCatalog(nullptr),
64 sal::systools::COMReference<IClassFactory2> pIUnknown;
67 HRESULT
hr = pIUnknown->CreateInstanceLic(
nullptr,
75 OSL_ENSURE(
m_aAdoConnection,
"OConnection::OConnection: invalid ADO object!");
88 osl_atomic_increment( &m_refCount );
92 std::size_t nLen = url.find(
':');
93 nLen = url.find(
':',nLen == std::u16string_view::npos ? 0 : nLen+1);
94 std::u16string_view aDSN(url.substr(nLen == std::u16string_view::npos ? 0 : nLen+1));
98 sal_Int32 nTimeout = 20;
99 const PropertyValue *pIter = info.getConstArray();
100 const PropertyValue *pEnd = pIter + info.getLength();
101 for(;pIter != pEnd;++pIter)
103 if(pIter->Name ==
"Timeout")
104 pIter->Value >>= nTimeout;
105 else if(pIter->Name ==
"user")
106 pIter->Value >>= aUID;
107 else if(pIter->Name ==
"password")
108 pIter->Value >>= aPWD;
124 OTools::putValue(aProps, std::u16string_view(u
"Jet OLEDB:ODBC Parsing"),
true);
127 if(!aVar.isNull() && !aVar.isEmpty())
137 catch(
const Exception& )
139 osl_atomic_decrement( &m_refCount );
142 osl_atomic_decrement( &m_refCount );
147 ::osl::MutexGuard aGuard(
m_aMutex );
157 ::osl::MutexGuard aGuard(
m_aMutex );
168 ::osl::MutexGuard aGuard(
m_aMutex );
179 ::osl::MutexGuard aGuard(
m_aMutex );
200 ::osl::MutexGuard aGuard(
m_aMutex );
213 ::osl::MutexGuard aGuard(
m_aMutex );
222 ::osl::MutexGuard aGuard(
m_aMutex );
231 ::osl::MutexGuard aGuard(
m_aMutex );
240 ::osl::MutexGuard aGuard(
m_aMutex );
247 ::osl::MutexGuard aGuard(
m_aMutex );
263 ::osl::MutexGuard aGuard(
m_aMutex );
273 ::osl::MutexGuard aGuard(
m_aMutex );
282 ::osl::MutexGuard aGuard(
m_aMutex );
291 ::osl::MutexGuard aGuard(
m_aMutex );
299 ::osl::MutexGuard aGuard(
m_aMutex );
303 IsolationLevelEnum eIso;
306 case TransactionIsolation::NONE:
307 eIso = adXactUnspecified;
309 case TransactionIsolation::READ_UNCOMMITTED:
310 eIso = adXactReadUncommitted;
312 case TransactionIsolation::READ_COMMITTED:
313 eIso = adXactReadCommitted;
315 case TransactionIsolation::REPEATABLE_READ:
316 eIso = adXactRepeatableRead;
318 case TransactionIsolation::SERIALIZABLE:
319 eIso = adXactSerializable;
322 OSL_FAIL(
"OConnection::setTransactionIsolation invalid level");
331 ::osl::MutexGuard aGuard(
m_aMutex );
338 case adXactUnspecified:
339 nRet = TransactionIsolation::NONE;
341 case adXactReadUncommitted:
342 nRet = TransactionIsolation::READ_UNCOMMITTED;
344 case adXactReadCommitted:
345 nRet = TransactionIsolation::READ_COMMITTED;
347 case adXactRepeatableRead:
348 nRet = TransactionIsolation::REPEATABLE_READ;
350 case adXactSerializable:
351 nRet = TransactionIsolation::SERIALIZABLE;
354 OSL_FAIL(
"OConnection::setTransactionIsolation invalid level");
362 ::osl::MutexGuard aGuard(
m_aMutex );
378 ::osl::MutexGuard aGuard(
m_aMutex );
397 ::osl::MutexGuard aGuard(
m_aMutex );
402 pRecordset->AddRef();
403 VARIANT_BOOL bIsAtBOF;
404 pRecordset->get_BOF(&bIsAtBOF);
407 if ( bIsAtBOF == VARIANT_TRUE )
408 bOk = SUCCEEDED(pRecordset->MoveNext());
413 static const char s_sVarChar[] =
"VarChar";
421 aInfo->
eType = adVarWChar;
447 while ( SUCCEEDED(pRecordset->MoveNext()) );
449 pRecordset->Release();
460 m_xMetaData = css::uno::WeakReference< css::sdbc::XDatabaseMetaData>();
461 m_xCatalog = css::uno::WeakReference< css::sdbcx::XTablesSupplier>();
467 delete rEntry.second;
488 const OUString& _sTypeName,
489 sal_Int32 _nPrecision,
491 bool& _brForceToType)
494 _brForceToType =
false;
496 std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
497 OTypeInfoMap::const_iterator aIter = aPair.first;
498 if(aIter != _rTypeInfo.end())
500 for(;aIter != aPair.second;++aIter)
504 if ( ( !_sTypeName.getLength()
514 if (aIter == aPair.second)
516 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
519 if ( (aIter->second->aSimpleType.aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
520 && (aIter->second->aSimpleType.nPrecision >= _nPrecision)
521 && (aIter->second->aSimpleType.nMaximumScale >= _nScale)
537 if (aIter == aPair.second)
543 pTypeInfo = aPair.first->second;
544 _brForceToType =
true;
547 pTypeInfo = aIter->second;
549 else if ( _sTypeName.getLength() )
553 OTypeInfoMap::const_iterator aFind = std::find_if(_rTypeInfo.begin(), _rTypeInfo.end(),
554 [&aCase, &_sTypeName] (
const OTypeInfoMap::value_type& typeInfo) {
555 return aCase(typeInfo.second->getDBName(), _sTypeName);
558 if(aFind != _rTypeInfo.end())
559 pTypeInfo = aFind->second;
IMPLEMENT_SERVICE_INFO(OConnection,"com.sun.star.sdbcx.AConnection","com.sun.star.sdbc.Connection")
const css::uno::Sequence< sal_Int8 > & getSeq() const
static void ThrowException(ADOConnection *_pAdoCon, const css::uno::Reference< css::uno::XInterface > &_xInterface)
static const CLSID CLSID_ADOCONNECTION_21
static const IID IID_ADOCONNECTION_21
static sal_Int32 MapADOType2Jdbc(DataTypeEnum eType)
static WpADOField getField(ADORecordset *_pRecordSet, sal_Int32 _nColumnIndex)
static sal::systools::BStr & GetKeyStr()
virtual sal_Int32 SAL_CALL getTransactionIsolation() override
virtual void SAL_CALL setCatalog(const OUString &catalog) override
virtual void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
virtual void SAL_CALL setTransactionIsolation(sal_Int32 level) override
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
void construct(std::u16string_view url, const css::uno::Sequence< css::beans::PropertyValue > &info)
virtual void SAL_CALL rollback() override
virtual OUString SAL_CALL nativeSQL(const OUString &sql) override
virtual void SAL_CALL close() override
virtual sal_Bool SAL_CALL isClosed() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
WpADOConnection m_aAdoConnection
static css::uno::Sequence< sal_Int8 > getUnoTunnelId()
css::uno::WeakReference< css::sdbcx::XTablesSupplier > m_xCatalog
virtual void SAL_CALL clearWarnings() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
virtual sal_Bool SAL_CALL getAutoCommit() override
virtual void SAL_CALL setReadOnly(sal_Bool readOnly) override
static const OExtendedTypeInfo * getTypeInfoFromType(const OTypeInfoMap &_rTypeInfo, DataTypeEnum _nType, const OUString &_sTypeName, sal_Int32 _nPrecision, sal_Int32 _nScale, bool &_brForceToType)
virtual void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual sal_Bool SAL_CALL isReadOnly() override
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
virtual OUString SAL_CALL getCatalog() override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual void SAL_CALL commit() override
bool put_Mode(const ConnectModeEnum &eNum)
sal_Int32 get_State() const
OUString GetDefaultDatabase() const
WpADOProperties get_Properties() const
bool Open(std::u16string_view ConnectionString, std::u16string_view UserID, std::u16string_view Password, long Options)
ADORecordset * getTypeInfo(DataTypeEnum _eType=adEmpty)
void PutCommandTimeout(sal_Int32 nRet)
bool put_IsolationLevel(const IsolationLevelEnum &eNum)
IsolationLevelEnum get_IsolationLevel() const
ConnectModeEnum get_Mode() const
bool PutDefaultDatabase(std::u16string_view _bstr)
void get_Value(OLEVariant &aValVar) const
sal_Int64 getSomethingImpl(const css::uno::Sequence< sal_Int8 > &rId, T *pThis, FallbackToGetSomethingOf< Base >={})
std::multimap< DataTypeEnum, OExtendedTypeInfo * > OTypeInfoMap
void checkDisposed(bool _bThrow)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
::connectivity::OTypeInfo aSimpleType