| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 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/. |
| 8 | * |
| 9 | * This file incorporates work covered by the following license notice: |
| 10 | * |
| 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 . |
| 18 | */ |
| 19 | #pragma once |
| 20 | |
| 21 | #include <com/sun/star/sdbc/SQLWarning.hpp> |
| 22 | #include <com/sun/star/sdbcx/XTablesSupplier.hpp> |
| 23 | #include <com/sun/star/beans/PropertyValue.hpp> |
| 24 | #include <map> |
| 25 | #include <string_view> |
| 26 | #include <connectivity/CommonTools.hxx> |
| 27 | #include <unotools/weakref.hxx> |
| 28 | #include <OTypeInfo.hxx> |
| 29 | #include <TConnection.hxx> |
| 30 | #include <ado/Awrapado.hxx> |
| 31 | #include <ado/ACatalog.hxx> |
| 32 | |
| 33 | namespace connectivity::ado |
| 34 | { |
| 35 | struct OExtendedTypeInfo |
| 36 | { |
| 37 | ::connectivity::OTypeInfo aSimpleType; // the general type info |
| 38 | DataTypeEnum eType; |
| 39 | |
| 40 | OUString getDBName() const { return aSimpleType.aTypeName; } |
| 41 | }; |
| 42 | |
| 43 | class WpADOConnection; |
| 44 | class ODriver; |
| 45 | typedef std::multimap<DataTypeEnum, OExtendedTypeInfo*> OTypeInfoMap; |
| 46 | typedef connectivity::OMetaConnection OConnection_BASE; |
| 47 | |
| 48 | |
| 49 | class OConnection : public OConnection_BASE |
| 50 | { |
| 51 | protected: |
| 52 | |
| 53 | // Data attributes |
| 54 | |
| 55 | OTypeInfoMap m_aTypeInfo; // vector containing an entry |
| 56 | // for each row returned by |
| 57 | // DatabaseMetaData.getTypeInfo. |
| 58 | unotools::WeakReference<OCatalog> m_xCatalog; |
| 59 | ODriver* m_pDriver; |
| 60 | private: |
| 61 | WpADOConnection m_aAdoConnection; |
| 62 | sal_Int32 m_nEngineType; |
| 63 | bool m_bClosed; |
| 64 | bool m_bAutocommit; |
| 65 | |
| 66 | protected: |
| 67 | /// @throws css::sdbc::SQLException |
| 68 | void buildTypeInfo(); |
| 69 | public: |
| 70 | /// @throws css::sdbc::SQLException |
| 71 | /// @throws css::uno::RuntimeException |
| 72 | OConnection(ODriver* _pDriver); |
| 73 | // OConnection(const SQLHANDLE _pConnectionHandle); |
| 74 | ~OConnection() override; |
| 75 | void construct(std::u16string_view url,const css::uno::Sequence< css::beans::PropertyValue >& info); |
| 76 | |
| 77 | //XUnoTunnel |
| 78 | virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; |
| 79 | static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); |
| 80 | // XServiceInfo |
| 81 | DECLARE_SERVICE_INFO(); |
| 82 | // OComponentHelper |
| 83 | virtual void SAL_CALL disposing() override; |
| 84 | |
| 85 | // XConnection |
| 86 | virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; |
| 87 | virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; |
| 88 | virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; |
| 89 | virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override; |
| 90 | virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override; |
| 91 | virtual sal_Bool SAL_CALL getAutoCommit( ) override; |
| 92 | virtual void SAL_CALL commit( ) override; |
| 93 | virtual void SAL_CALL rollback( ) override; |
| 94 | virtual sal_Bool SAL_CALL isClosed( ) override; |
| 95 | virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; |
| 96 | virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override; |
| 97 | virtual sal_Bool SAL_CALL isReadOnly( ) override; |
| 98 | virtual void SAL_CALL setCatalog( const OUString& catalog ) override; |
| 99 | virtual OUString SAL_CALL getCatalog( ) override; |
| 100 | virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override; |
| 101 | virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override; |
| 102 | virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override; |
| 103 | virtual void SAL_CALL setTypeMap( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; |
| 104 | // XCloseable |
| 105 | virtual void SAL_CALL close( ) override; |
| 106 | // XWarningsSupplier |
| 107 | virtual css::uno::Any SAL_CALL getWarnings( ) override; |
| 108 | virtual void SAL_CALL clearWarnings( ) override; |
| 109 | |
| 110 | WpADOConnection& getConnection() { return m_aAdoConnection; } |
| 111 | void setCatalog(OCatalog* _pCatalog) { m_xCatalog = _pCatalog; } |
| 112 | |
| 113 | const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo;} |
| 114 | OCatalog* getAdoCatalog() const |
| 115 | { |
| 116 | return m_xCatalog.get().get(); |
| 117 | } |
| 118 | |
| 119 | sal_Int32 getEngineType() const { return m_nEngineType; } |
| 120 | ODriver* getDriver() const { return m_pDriver; } |
| 121 | |
| 122 | static const OExtendedTypeInfo* getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo, |
| 123 | DataTypeEnum _nType, |
| 124 | const OUString& _sTypeName, |
| 125 | sal_Int32 _nPrecision, |
| 126 | sal_Int32 _nScale, |
| 127 | bool& _brForceToType); |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |