1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _CONNECTIVITY_EVOAB_STATEMENT_HXX_ 25cdf0e10cSrcweir #define _CONNECTIVITY_EVOAB_STATEMENT_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/sdbc/XStatement.hpp> 28cdf0e10cSrcweir #include <com/sun/star/sdbc/XWarningsSupplier.hpp> 29cdf0e10cSrcweir #include <com/sun/star/sdbc/XMultipleResults.hpp> 30cdf0e10cSrcweir #include <com/sun/star/sdbc/XCloseable.hpp> 31cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp> 32cdf0e10cSrcweir #include <comphelper/proparrhlp.hxx> 33cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 34cdf0e10cSrcweir #include <comphelper/uno3.hxx> 35cdf0e10cSrcweir #include "connectivity/CommonTools.hxx" 36cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 37cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx> 38cdf0e10cSrcweir #include "connectivity/sqliterator.hxx" 39cdf0e10cSrcweir #include "connectivity/sqlparse.hxx" 40cdf0e10cSrcweir #include <connectivity/FValue.hxx> 41cdf0e10cSrcweir #include "OSubComponent.hxx" 42cdf0e10cSrcweir #include <com/sun/star/util/XCancellable.hpp> 43cdf0e10cSrcweir #include <cppuhelper/compbase5.hxx> 44cdf0e10cSrcweir #include <comphelper/propertycontainer.hxx> 45cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include "EApi.h" 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <list> 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace connectivity 52cdf0e10cSrcweir { 53cdf0e10cSrcweir namespace evoab 54cdf0e10cSrcweir { 55cdf0e10cSrcweir class OEvoabResultSet; 56cdf0e10cSrcweir class OEvoabConnection; 57cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::sdbc::XWarningsSupplier 58cdf0e10cSrcweir , ::com::sun::star::sdbc::XCloseable 59cdf0e10cSrcweir > OCommonStatement_IBase; 60cdf0e10cSrcweir 61cdf0e10cSrcweir struct FieldSort 62cdf0e10cSrcweir { 63cdf0e10cSrcweir sal_Int32 nField; 64cdf0e10cSrcweir bool bAscending; 65cdf0e10cSrcweir FieldSortconnectivity::evoab::FieldSort66cdf0e10cSrcweir FieldSort() : nField(0), bAscending( true ) { } FieldSortconnectivity::evoab::FieldSort67cdf0e10cSrcweir FieldSort( const sal_Int32 _nField, const bool _bAscending ) : nField( _nField ), bAscending( _bAscending ) { } 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir typedef ::std::vector< FieldSort > SortDescriptor; 70cdf0e10cSrcweir 71cdf0e10cSrcweir enum QueryFilterType 72cdf0e10cSrcweir { 73cdf0e10cSrcweir eFilterAlwaysFalse, 74cdf0e10cSrcweir eFilterNone, 75cdf0e10cSrcweir eFilterOther 76cdf0e10cSrcweir }; 77cdf0e10cSrcweir 78cdf0e10cSrcweir struct QueryData 79cdf0e10cSrcweir { 80cdf0e10cSrcweir private: 81cdf0e10cSrcweir EBookQuery* pQuery; 82cdf0e10cSrcweir 83cdf0e10cSrcweir public: 84cdf0e10cSrcweir ::rtl::OUString sTable; 85cdf0e10cSrcweir QueryFilterType eFilterType; 86cdf0e10cSrcweir ::vos::ORef< ::connectivity::OSQLColumns > xSelectColumns; 87cdf0e10cSrcweir SortDescriptor aSortOrder; 88cdf0e10cSrcweir QueryDataconnectivity::evoab::QueryData89cdf0e10cSrcweir QueryData() 90cdf0e10cSrcweir :pQuery( NULL ) 91cdf0e10cSrcweir ,sTable() 92cdf0e10cSrcweir ,eFilterType( eFilterOther ) 93cdf0e10cSrcweir ,xSelectColumns() 94cdf0e10cSrcweir ,aSortOrder() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir } 97cdf0e10cSrcweir QueryDataconnectivity::evoab::QueryData98cdf0e10cSrcweir QueryData( const QueryData& _rhs ) 99cdf0e10cSrcweir :pQuery( NULL ) 100cdf0e10cSrcweir ,sTable() 101cdf0e10cSrcweir ,eFilterType( eFilterType ) 102cdf0e10cSrcweir ,xSelectColumns() 103cdf0e10cSrcweir ,aSortOrder() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir *this = _rhs; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir operator =connectivity::evoab::QueryData108cdf0e10cSrcweir QueryData& operator=( const QueryData& _rhs ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir if ( this == &_rhs ) 111cdf0e10cSrcweir return *this; 112cdf0e10cSrcweir 113cdf0e10cSrcweir setQuery( _rhs.pQuery ); 114cdf0e10cSrcweir sTable = _rhs.sTable; 115cdf0e10cSrcweir eFilterType = _rhs.eFilterType; 116cdf0e10cSrcweir xSelectColumns = _rhs.xSelectColumns; 117cdf0e10cSrcweir aSortOrder = _rhs.aSortOrder; 118cdf0e10cSrcweir 119cdf0e10cSrcweir return *this; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir ~QueryDataconnectivity::evoab::QueryData122cdf0e10cSrcweir ~QueryData() 123cdf0e10cSrcweir { 124cdf0e10cSrcweir setQuery( NULL ); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir getQueryconnectivity::evoab::QueryData127cdf0e10cSrcweir EBookQuery* getQuery() const { return pQuery; } 128cdf0e10cSrcweir setQueryconnectivity::evoab::QueryData129cdf0e10cSrcweir void setQuery( EBookQuery* _pQuery ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if ( pQuery ) 132cdf0e10cSrcweir e_book_query_unref( pQuery ); 133cdf0e10cSrcweir pQuery = _pQuery; 134cdf0e10cSrcweir if ( pQuery ) 135cdf0e10cSrcweir e_book_query_ref( pQuery ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir }; 138cdf0e10cSrcweir 139cdf0e10cSrcweir //************************************************************** 140cdf0e10cSrcweir //************ Class: OCommonStatement 141cdf0e10cSrcweir // is a base class for the normal statement and for the prepared statement 142cdf0e10cSrcweir //************************************************************** 143cdf0e10cSrcweir class OCommonStatement; 144cdf0e10cSrcweir typedef OSubComponent< OCommonStatement, OCommonStatement_IBase > OStatement_CBase; 145cdf0e10cSrcweir 146cdf0e10cSrcweir class OCommonStatement :public comphelper::OBaseMutex 147cdf0e10cSrcweir ,public OCommonStatement_IBase 148cdf0e10cSrcweir ,public ::comphelper::OPropertyContainer 149cdf0e10cSrcweir ,public ::comphelper::OPropertyArrayUsageHelper< OCommonStatement > 150cdf0e10cSrcweir ,public OStatement_CBase 151cdf0e10cSrcweir { 152cdf0e10cSrcweir friend class OSubComponent< OCommonStatement, OCommonStatement_IBase >; 153cdf0e10cSrcweir 154cdf0e10cSrcweir private: 155cdf0e10cSrcweir ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet> m_xResultSet; // The last ResultSet created 156cdf0e10cSrcweir OEvoabResultSet *m_pResultSet; 157cdf0e10cSrcweir OEvoabConnection *m_pConnection; 158cdf0e10cSrcweir connectivity::OSQLParser m_aParser; 159cdf0e10cSrcweir connectivity::OSQLParseTreeIterator m_aSQLIterator; 160cdf0e10cSrcweir connectivity::OSQLParseNode *m_pParseTree; 161cdf0e10cSrcweir 162cdf0e10cSrcweir // <properties> 163cdf0e10cSrcweir ::rtl::OUString m_aCursorName; 164cdf0e10cSrcweir sal_Int32 m_nMaxFieldSize; 165cdf0e10cSrcweir sal_Int32 m_nMaxRows; 166cdf0e10cSrcweir sal_Int32 m_nQueryTimeOut; 167cdf0e10cSrcweir sal_Int32 m_nFetchSize; 168cdf0e10cSrcweir sal_Int32 m_nResultSetType; 169cdf0e10cSrcweir sal_Int32 m_nFetchDirection; 170cdf0e10cSrcweir sal_Int32 m_nResultSetConcurrency; 171cdf0e10cSrcweir sal_Bool m_bEscapeProcessing; 172cdf0e10cSrcweir // </properties> 173cdf0e10cSrcweir 174cdf0e10cSrcweir ::cppu::OBroadcastHelper& rBHelper; 175cdf0e10cSrcweir 176cdf0e10cSrcweir protected: 177cdf0e10cSrcweir 178cdf0e10cSrcweir void disposeResultSet(); 179cdf0e10cSrcweir 180cdf0e10cSrcweir // OPropertyArrayUsageHelper 181cdf0e10cSrcweir virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const; 182cdf0e10cSrcweir // OPropertySetHelper 183cdf0e10cSrcweir virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); 184cdf0e10cSrcweir 185cdf0e10cSrcweir virtual ~OCommonStatement(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir protected: 188cdf0e10cSrcweir void reset () throw( ::com::sun::star::sdbc::SQLException); 189cdf0e10cSrcweir void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException); 190cdf0e10cSrcweir void parseSql( const ::rtl::OUString& sql, QueryData& _out_rQueryData ); 191cdf0e10cSrcweir EBookQuery *whereAnalysis( const OSQLParseNode* parseTree ); 192cdf0e10cSrcweir void orderByAnalysis( const OSQLParseNode* _pOrderByClause, SortDescriptor& _out_rSort ); 193cdf0e10cSrcweir rtl::OUString getTableName(); 194cdf0e10cSrcweir EBookQuery *createTrue(); 195cdf0e10cSrcweir EBookQuery *createTest( const ::rtl::OUString &aColumnName, 196cdf0e10cSrcweir EBookQueryTest eTest, 197cdf0e10cSrcweir const ::rtl::OUString &aMatch ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir public: 200cdf0e10cSrcweir 201cdf0e10cSrcweir // other methods getOwnConnection() const202cdf0e10cSrcweir OEvoabConnection* getOwnConnection() const { return m_pConnection;} 203cdf0e10cSrcweir 204cdf0e10cSrcweir using OCommonStatement_IBase::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >; 205cdf0e10cSrcweir 206cdf0e10cSrcweir protected: 207cdf0e10cSrcweir OCommonStatement( OEvoabConnection* _pConnection ); 208cdf0e10cSrcweir 209cdf0e10cSrcweir // OComponentHelper 210cdf0e10cSrcweir virtual void SAL_CALL disposing(void); 211cdf0e10cSrcweir // XInterface 212cdf0e10cSrcweir virtual void SAL_CALL release() throw(); 213cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(); 214cdf0e10cSrcweir // XInterface 215cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 216cdf0e10cSrcweir //XTypeProvider 217cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); 218cdf0e10cSrcweir 219cdf0e10cSrcweir // XPropertySet 220cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 221cdf0e10cSrcweir 222cdf0e10cSrcweir // XWarningsSupplier 223cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 224cdf0e10cSrcweir virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 225cdf0e10cSrcweir 226cdf0e10cSrcweir // XCloseable 227cdf0e10cSrcweir virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 228cdf0e10cSrcweir 229cdf0e10cSrcweir protected: 230cdf0e10cSrcweir /** will return the EBookQuery representing the stamement's WHERE condition, or throw 231cdf0e10cSrcweir 232cdf0e10cSrcweir Also, all statement dependent members (such as the parser/iterator) will be inited afterwards. 233cdf0e10cSrcweir */ 234cdf0e10cSrcweir QueryData 235cdf0e10cSrcweir impl_getEBookQuery_throw( const ::rtl::OUString& _rSql ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > 238cdf0e10cSrcweir impl_executeQuery_throw( const ::rtl::OUString& _rSql ); 239cdf0e10cSrcweir 240cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > 241cdf0e10cSrcweir impl_executeQuery_throw( const QueryData& _rData ); 242cdf0e10cSrcweir 243cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > impl_getConnection()244cdf0e10cSrcweir impl_getConnection() { return ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >( (::com::sun::star::sdbc::XConnection*)m_pConnection ); } 245cdf0e10cSrcweir 246cdf0e10cSrcweir ::rtl::OUString 247cdf0e10cSrcweir impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode& _rColumnRef ); 248cdf0e10cSrcweir }; 249cdf0e10cSrcweir 250cdf0e10cSrcweir typedef ::cppu::ImplHelper2 < ::com::sun::star::lang::XServiceInfo 251cdf0e10cSrcweir , ::com::sun::star::sdbc::XStatement 252cdf0e10cSrcweir > OStatement_IBase; 253cdf0e10cSrcweir class OStatement :public OCommonStatement 254cdf0e10cSrcweir ,public OStatement_IBase 255cdf0e10cSrcweir { 256cdf0e10cSrcweir protected: ~OStatement()257cdf0e10cSrcweir virtual ~OStatement(){} 258cdf0e10cSrcweir 259cdf0e10cSrcweir public: OStatement(OEvoabConnection * _pConnection)260cdf0e10cSrcweir OStatement( OEvoabConnection* _pConnection) 261cdf0e10cSrcweir :OCommonStatement( _pConnection) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir // XInterface 266cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 267cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(); 268cdf0e10cSrcweir virtual void SAL_CALL release() throw(); 269cdf0e10cSrcweir 270cdf0e10cSrcweir // XTypeProvider 271cdf0e10cSrcweir DECLARE_XTYPEPROVIDER() 272cdf0e10cSrcweir 273cdf0e10cSrcweir // XServiceInfo 274cdf0e10cSrcweir DECLARE_SERVICE_INFO(); 275cdf0e10cSrcweir 276cdf0e10cSrcweir // XStatement 277cdf0e10cSrcweir 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) ; 278cdf0e10cSrcweir virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 279cdf0e10cSrcweir virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; 280cdf0e10cSrcweir 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) ; 281cdf0e10cSrcweir }; 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir #endif // CONNECTIVITY_SSTATEMENT_HXX 285