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/beans/PropertyValue.hpp> 23 #include <connectivity/odbc.hxx> 24 #include <odbc/odbcbasedllapi.hxx> 25 #include <connectivity/CommonTools.hxx> 26 #include <TConnection.hxx> 27 #include <OTypeInfo.hxx> 28 #include <odbc/OTools.hxx> 29 #include <cppuhelper/weakref.hxx> 30 #include <AutoRetrievingBase.hxx> 31 #include <osl/module.h> 32 #include <rtl/ref.hxx> 33 34 35 #include <map> 36 37 namespace connectivity::odbc 38 { 39 class ODBCDriver; 40 41 typedef connectivity::OMetaConnection OConnection_BASE; 42 typedef std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; 43 44 class OOO_DLLPUBLIC_ODBCBASE OConnection final : 45 public OConnection_BASE, 46 public OAutoRetrievingBase 47 { 48 // Data attributes 49 50 std::map< SQLHANDLE, rtl::Reference<OConnection>> m_aConnections; // holds all connections which are need for several statements 51 52 53 OUString m_sUser; // the user name 54 rtl::Reference<ODBCDriver> 55 m_xDriver; // Pointer to the owning 56 // driver object 57 58 SQLHANDLE m_aConnectionHandle; 59 SQLHANDLE m_pDriverHandleCopy; // performance reason 60 sal_Int32 m_nStatementCount; 61 bool m_bClosed; 62 bool m_bUseCatalog; // should we use the catalog on filebased databases 63 bool m_bUseOldDateFormat; 64 bool m_bIgnoreDriverPrivileges; 65 bool m_bPreventGetVersionColumns; // #i60273# 66 bool m_bReadOnly; 67 68 69 SQLRETURN OpenConnection(const OUString& aConnectStr,sal_Int32 nTimeOut, bool bSilent); 70 71 public: 72 oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const; 73 /// @throws css::sdbc::SQLException 74 SQLRETURN Construct( const OUString& url,const css::uno::Sequence< css::beans::PropertyValue >& info); 75 76 OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver); 77 // OConnection(const SQLHANDLE _pConnectionHandle); 78 virtual ~OConnection() override; 79 80 // OComponentHelper 81 virtual void SAL_CALL disposing() override; 82 83 // XServiceInfo 84 DECLARE_SERVICE_INFO(); 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 getConnection()110 SQLHANDLE getConnection() { return m_aConnectionHandle; } 111 112 // should we use the catalog on filebased databases isCatalogUsed() const113 bool isCatalogUsed() const { return m_bUseCatalog; } isIgnoreDriverPrivilegesEnabled() const114 bool isIgnoreDriverPrivilegesEnabled() const { return m_bIgnoreDriverPrivileges; } preventGetVersionColumns() const115 bool preventGetVersionColumns() const { return m_bPreventGetVersionColumns; } useOldDateFormat() const116 bool useOldDateFormat() const { return m_bUseOldDateFormat; } getDriver() const117 ODBCDriver* getDriver() const { return m_xDriver.get();} 118 119 SQLHANDLE createStatementHandle(); 120 // close and free the handle and set it to SQL_NULLHANDLE 121 void freeStatementHandle(SQLHANDLE& _pHandle); 122 }; 123 124 } 125 126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 127