1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _CONNECTIVITY_ODBC_OSTATEMENT_HXX_ 29 #define _CONNECTIVITY_ODBC_OSTATEMENT_HXX_ 30 31 #include <com/sun/star/sdbc/XStatement.hpp> 32 #include <com/sun/star/sdbc/XWarningsSupplier.hpp> 33 #include <com/sun/star/sdbc/XMultipleResults.hpp> 34 #include <com/sun/star/sdbc/XBatchExecution.hpp> 35 #include <com/sun/star/sdbc/XCloseable.hpp> 36 #include <com/sun/star/sdbc/SQLWarning.hpp> 37 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp> 38 #include <com/sun/star/util/XCancellable.hpp> 39 #include <comphelper/proparrhlp.hxx> 40 #include <cppuhelper/compbase6.hxx> 41 #include <comphelper/uno3.hxx> 42 #include "connectivity/CommonTools.hxx" 43 #include "odbc/OFunctions.hxx" 44 #include "odbc/OConnection.hxx" 45 #include "odbc/odbcbasedllapi.hxx" 46 #include <list> 47 #include <com/sun/star/lang/XServiceInfo.hpp> 48 #include <comphelper/broadcasthelper.hxx> 49 50 namespace connectivity 51 { 52 namespace odbc 53 { 54 55 typedef ::cppu::WeakComponentImplHelper6< ::com::sun::star::sdbc::XStatement, 56 ::com::sun::star::sdbc::XWarningsSupplier, 57 ::com::sun::star::util::XCancellable, 58 ::com::sun::star::sdbc::XCloseable, 59 ::com::sun::star::sdbc::XGeneratedResultSet, 60 ::com::sun::star::sdbc::XMultipleResults> OStatement_BASE; 61 62 class OResultSet; 63 //************************************************************** 64 //************ Class: java.sql.Statement 65 //************************************************************** 66 class OOO_DLLPUBLIC_ODBCBASE OStatement_Base : 67 public comphelper::OBaseMutex, 68 public OStatement_BASE, 69 public ::cppu::OPropertySetHelper, 70 public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base> 71 72 { 73 ::com::sun::star::sdbc::SQLWarning m_aLastWarning; 74 protected: 75 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet> m_xResultSet; // The last ResultSet created 76 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement> m_xGeneratedStatement; 77 // for this Statement 78 79 ::std::list< ::rtl::OUString> m_aBatchList; 80 ::rtl::OUString m_sSqlStatement; 81 82 OConnection* m_pConnection;// The owning Connection object 83 SQLHANDLE m_aStatementHandle; 84 SQLUSMALLINT* m_pRowStatusArray; 85 ::cppu::OBroadcastHelper& rBHelper; 86 87 protected: 88 89 sal_Int32 getQueryTimeOut() const; 90 sal_Int32 getMaxFieldSize() const; 91 sal_Int32 getMaxRows() const; 92 sal_Int32 getResultSetConcurrency() const; 93 sal_Int32 getResultSetType() const; 94 sal_Int32 getFetchDirection() const; 95 sal_Int32 getFetchSize() const; 96 ::rtl::OUString getCursorName() const; 97 sal_Bool isUsingBookmarks() const; 98 sal_Bool getEscapeProcessing() const; 99 sal_Int32 getStmtOption (short fOption) const; 100 101 void setQueryTimeOut(sal_Int32 _par0) ; 102 void setMaxFieldSize(sal_Int32 _par0) ; 103 void setMaxRows(sal_Int32 _par0) ; 104 void setFetchDirection(sal_Int32 _par0) ; 105 void setFetchSize(sal_Int32 _par0) ; 106 void setCursorName(const ::rtl::OUString &_par0); 107 void setEscapeProcessing( const sal_Bool _bEscapeProc ); 108 109 virtual void setResultSetConcurrency(sal_Int32 _par0) ; 110 virtual void setResultSetType(sal_Int32 _par0) ; 111 virtual void setUsingBookmarks(sal_Bool _bUseBookmark) ; 112 113 void reset () throw( ::com::sun::star::sdbc::SQLException); 114 void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException); 115 void setWarning (const ::com::sun::star::sdbc::SQLWarning &ex) throw( ::com::sun::star::sdbc::SQLException); 116 sal_Bool lockIfNecessary (const ::rtl::OUString& sql) throw( ::com::sun::star::sdbc::SQLException); 117 sal_Int32 getColumnCount () throw( ::com::sun::star::sdbc::SQLException); 118 119 //-------------------------------------------------------------------- 120 // getResultSet 121 // getResultSet returns the current result as a ResultSet. It 122 // returns NULL if the current result is not a ResultSet. 123 //-------------------------------------------------------------------- 124 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > getResultSet (sal_Bool checkCount) throw( ::com::sun::star::sdbc::SQLException); 125 /** 126 creates the driver specific resultset (factory) 127 */ 128 virtual OResultSet* createResulSet(); 129 130 SQLLEN getRowCount () throw( ::com::sun::star::sdbc::SQLException); 131 132 133 void disposeResultSet(); 134 135 // OPropertyArrayUsageHelper 136 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 137 // OPropertySetHelper 138 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); 139 virtual sal_Bool SAL_CALL convertFastPropertyValue( 140 ::com::sun::star::uno::Any & rConvertedValue, 141 ::com::sun::star::uno::Any & rOldValue, 142 sal_Int32 nHandle, 143 const ::com::sun::star::uno::Any& rValue ) 144 throw (::com::sun::star::lang::IllegalArgumentException); 145 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 146 sal_Int32 nHandle, 147 const ::com::sun::star::uno::Any& rValue 148 ) 149 throw (::com::sun::star::uno::Exception); 150 virtual void SAL_CALL getFastPropertyValue( 151 ::com::sun::star::uno::Any& rValue, 152 sal_Int32 nHandle 153 ) const; 154 virtual ~OStatement_Base(); 155 156 public: 157 OStatement_Base(OConnection* _pConnection ); 158 using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >; 159 160 inline oslGenericFunction getOdbcFunction(sal_Int32 _nIndex) const 161 { 162 return m_pConnection->getOdbcFunction(_nIndex); 163 } 164 // OComponentHelper 165 virtual void SAL_CALL disposing(void); 166 // XInterface 167 virtual void SAL_CALL release() throw(); 168 virtual void SAL_CALL acquire() throw(); 169 // XInterface 170 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 171 //XTypeProvider 172 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); 173 174 // XPropertySet 175 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 176 // XStatement 177 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 178 virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 179 virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 180 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 181 // XWarningsSupplier 182 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 183 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 184 // XCancellable 185 virtual void SAL_CALL cancel( ) throw(::com::sun::star::uno::RuntimeException); 186 // XCloseable 187 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 188 // XMultipleResults 189 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 190 virtual sal_Int32 SAL_CALL getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 191 virtual sal_Bool SAL_CALL getMoreResults( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 192 //XGeneratedResultSet 193 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getGeneratedValues( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 194 195 // other methods 196 SQLHANDLE getConnectionHandle() { return m_pConnection->getConnection(); } 197 OConnection* getOwnConnection() const { return m_pConnection;} 198 /** getCursorProperties return the properties for a specific cursor type 199 @param _nCursorType the CursorType 200 @param bFirst when true the first property set is returned 201 202 @return the cursor properties 203 */ 204 SQLUINTEGER getCursorProperties(SQLINTEGER _nCursorType,sal_Bool bFirst); 205 206 protected: 207 using OPropertySetHelper::getFastPropertyValue; 208 }; 209 210 class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2 : 211 public OStatement_Base 212 ,public ::connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE> 213 214 { 215 friend class OSubComponent<OStatement_BASE2, OStatement_BASE>; 216 public: 217 OStatement_BASE2(OConnection* _pConnection ) : OStatement_Base(_pConnection ), 218 ::connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){} 219 // OComponentHelper 220 virtual void SAL_CALL disposing(void); 221 // XInterface 222 virtual void SAL_CALL release() throw(); 223 }; 224 225 class OOO_DLLPUBLIC_ODBCBASE OStatement : 226 public OStatement_BASE2, 227 public ::com::sun::star::sdbc::XBatchExecution, 228 public ::com::sun::star::lang::XServiceInfo 229 { 230 protected: 231 virtual ~OStatement(){} 232 public: 233 // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird: 234 OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){} 235 DECLARE_SERVICE_INFO(); 236 237 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 238 virtual void SAL_CALL acquire() throw(); 239 virtual void SAL_CALL release() throw(); 240 // XBatchExecution 241 virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 242 virtual void SAL_CALL clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 243 virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 244 }; 245 } 246 } 247 #endif // _CONNECTIVITY_ODBC_OSTATEMENT_HXX_ 248 249