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