1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _CONNECTIVITY_ODBC_OCONNECTION_HXX_ 24 #define _CONNECTIVITY_ODBC_OCONNECTION_HXX_ 25 26 #include <com/sun/star/sdbc/SQLWarning.hpp> 27 #include <com/sun/star/beans/PropertyValue.hpp> 28 #include "odbc/OFunctiondefs.hxx" 29 #include "odbc/odbcbasedllapi.hxx" 30 #include "OSubComponent.hxx" 31 #include "connectivity/CommonTools.hxx" 32 #include "TConnection.hxx" 33 #include "OTypeInfo.hxx" 34 #include <cppuhelper/weakref.hxx> 35 #include "AutoRetrievingBase.hxx" 36 #include <osl/module.h> 37 38 39 #include <map> 40 41 namespace connectivity 42 { 43 namespace odbc 44 { 45 46 class OStatement_Base; 47 class ODBCDriver; 48 class ODatabaseMetaData; 49 50 typedef connectivity::OMetaConnection OConnection_BASE; 51 typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; 52 53 class OOO_DLLPUBLIC_ODBCBASE OConnection : 54 public OConnection_BASE, 55 public connectivity::OSubComponent<OConnection, OConnection_BASE>, 56 public OAutoRetrievingBase 57 { 58 friend class connectivity::OSubComponent<OConnection, OConnection_BASE>; 59 60 protected: 61 //==================================================================== 62 // Data attributes 63 //==================================================================== 64 ::std::map< SQLHANDLE,OConnection*> m_aConnections; // holds all connectionas which are need for serveral statements 65 TTypeInfoVector m_aTypeInfo; // vector containing an entry 66 // for each row returned by 67 // DatabaseMetaData.getTypeInfo. 68 69 70 ::com::sun::star::sdbc::SQLWarning m_aLastWarning; // Last SQLWarning generated by 71 // an operation 72 ::rtl::OUString m_sUser; // the user name 73 ODBCDriver* m_pDriver; // Pointer to the owning 74 // driver object 75 76 SQLHANDLE m_aConnectionHandle; 77 SQLHANDLE m_pDriverHandleCopy; // performance reason 78 sal_Int32 m_nStatementCount; 79 sal_Bool m_bClosed; 80 sal_Bool m_bUseCatalog; // should we use the catalog on filebased databases 81 sal_Bool m_bUseOldDateFormat; 82 sal_Bool m_bParameterSubstitution; 83 sal_Bool m_bIgnoreDriverPrivileges; 84 sal_Bool m_bPreventGetVersionColumns; // #i60273# 85 sal_Bool m_bReadOnly; 86 87 88 SQLRETURN OpenConnection(const ::rtl::OUString& aConnectStr,sal_Int32 nTimeOut, sal_Bool bSilent); 89 90 virtual OConnection* cloneConnection(); // creates a new connection 91 92 public: 93 oslGenericFunction getOdbcFunction(sal_Int32 _nIndex) const; 94 virtual SQLRETURN Construct( const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException); 95 96 OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver); 97 // OConnection(const SQLHANDLE _pConnectionHandle); 98 virtual ~OConnection(); 99 100 void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException); 101 102 // OComponentHelper 103 virtual void SAL_CALL disposing(void); 104 // XInterface 105 virtual void SAL_CALL release() throw(); 106 107 // XServiceInfo 108 DECLARE_SERVICE_INFO(); 109 // XConnection 110 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 111 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 112 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 113 virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 114 virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 115 virtual sal_Bool SAL_CALL getAutoCommit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 116 virtual void SAL_CALL commit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 117 virtual void SAL_CALL rollback( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 118 virtual sal_Bool SAL_CALL isClosed( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 119 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 120 virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 121 virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 122 virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 123 virtual ::rtl::OUString SAL_CALL getCatalog( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 124 virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 125 virtual sal_Int32 SAL_CALL getTransactionIsolation( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 126 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 127 virtual void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 128 // XCloseable 129 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 130 // XWarningsSupplier 131 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 132 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 133 // getConnection()134 SQLHANDLE getConnection() { return m_aConnectionHandle; } 135 136 // should we use the catalog on filebased databases isCatalogUsed() const137 inline sal_Bool isCatalogUsed() const { return m_bUseCatalog; } isParameterSubstitutionEnabled() const138 inline sal_Bool isParameterSubstitutionEnabled() const { return m_bParameterSubstitution; } isIgnoreDriverPrivilegesEnabled() const139 inline sal_Bool isIgnoreDriverPrivilegesEnabled() const { return m_bIgnoreDriverPrivileges; } preventGetVersionColumns() const140 inline sal_Bool preventGetVersionColumns() const { return m_bPreventGetVersionColumns; } useOldDateFormat() const141 inline sal_Bool useOldDateFormat() const { return m_bUseOldDateFormat; } getDriverHandle() const142 inline SQLHANDLE getDriverHandle() const { return m_pDriverHandleCopy;} getDriver() const143 inline ODBCDriver* getDriver() const { return m_pDriver;} getUserName() const144 inline ::rtl::OUString getUserName() const { return m_sUser; } 145 146 SQLHANDLE createStatementHandle(); 147 // close and free the handle and set it to SQL_NULLHANDLE 148 void freeStatementHandle(SQLHANDLE& _pHandle); 149 150 void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException); getTypeInfo() const151 const TTypeInfoVector& getTypeInfo() const { return m_aTypeInfo; } 152 }; 153 } 154 } 155 #endif // _CONNECTIVITY_ODBC_OCONNECTION_HXX_ 156 157