1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NStatement.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CONNECTIVITY_EVOAB_STATEMENT_HXX_
32 #define _CONNECTIVITY_EVOAB_STATEMENT_HXX_
34 #include <com/sun/star/sdbc/XStatement.hpp>
35 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
36 #include <com/sun/star/sdbc/XMultipleResults.hpp>
37 #include <com/sun/star/sdbc/XCloseable.hpp>
38 #include <com/sun/star/sdbc/SQLWarning.hpp>
39 #include <comphelper/proparrhlp.hxx>
40 #include <cppuhelper/compbase2.hxx>
41 #include <comphelper/uno3.hxx>
42 #include "connectivity/CommonTools.hxx"
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <comphelper/broadcasthelper.hxx>
45 #include "connectivity/sqliterator.hxx"
46 #include "connectivity/sqlparse.hxx"
47 #include <connectivity/FValue.hxx>
48 #include "OSubComponent.hxx"
49 #include <com/sun/star/util/XCancellable.hpp>
50 #include <cppuhelper/compbase5.hxx>
51 #include <comphelper/propertycontainer.hxx>
52 #include <com/sun/star/lang/XServiceInfo.hpp>
58 namespace connectivity
62 class OEvoabResultSet
;
63 class OEvoabConnection
;
64 typedef ::cppu::WeakComponentImplHelper2
< ::com::sun::star::sdbc::XWarningsSupplier
65 , ::com::sun::star::sdbc::XCloseable
66 > OCommonStatement_IBase
;
73 FieldSort() : nField(0), bAscending( true ) { }
74 FieldSort( const sal_Int32 _nField
, const bool _bAscending
) : nField( _nField
), bAscending( _bAscending
) { }
76 typedef ::std::vector
< FieldSort
> SortDescriptor
;
91 ::rtl::OUString sTable
;
92 QueryFilterType eFilterType
;
93 ::vos::ORef
< ::connectivity::OSQLColumns
> xSelectColumns
;
94 SortDescriptor aSortOrder
;
99 ,eFilterType( eFilterOther
)
105 QueryData( const QueryData
& _rhs
)
108 ,eFilterType( eFilterType
)
115 QueryData
& operator=( const QueryData
& _rhs
)
120 setQuery( _rhs
.pQuery
);
121 sTable
= _rhs
.sTable
;
122 eFilterType
= _rhs
.eFilterType
;
123 xSelectColumns
= _rhs
.xSelectColumns
;
124 aSortOrder
= _rhs
.aSortOrder
;
134 EBookQuery
* getQuery() const { return pQuery
; }
136 void setQuery( EBookQuery
* _pQuery
)
139 e_book_query_unref( pQuery
);
142 e_book_query_ref( pQuery
);
146 //**************************************************************
147 //************ Class: OCommonStatement
148 // is a base class for the normal statement and for the prepared statement
149 //**************************************************************
150 class OCommonStatement
;
151 typedef OSubComponent
< OCommonStatement
, OCommonStatement_IBase
> OStatement_CBase
;
153 class OCommonStatement
:public comphelper::OBaseMutex
154 ,public OCommonStatement_IBase
155 ,public ::comphelper::OPropertyContainer
156 ,public ::comphelper::OPropertyArrayUsageHelper
< OCommonStatement
>
157 ,public OStatement_CBase
159 friend class OSubComponent
< OCommonStatement
, OCommonStatement_IBase
>;
162 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xResultSet
; // The last ResultSet created
163 OEvoabResultSet
*m_pResultSet
;
164 OEvoabConnection
*m_pConnection
;
165 connectivity::OSQLParser m_aParser
;
166 connectivity::OSQLParseTreeIterator m_aSQLIterator
;
167 connectivity::OSQLParseNode
*m_pParseTree
;
170 ::rtl::OUString m_aCursorName
;
171 sal_Int32 m_nMaxFieldSize
;
172 sal_Int32 m_nMaxRows
;
173 sal_Int32 m_nQueryTimeOut
;
174 sal_Int32 m_nFetchSize
;
175 sal_Int32 m_nResultSetType
;
176 sal_Int32 m_nFetchDirection
;
177 sal_Int32 m_nResultSetConcurrency
;
178 sal_Bool m_bEscapeProcessing
;
181 ::cppu::OBroadcastHelper
& rBHelper
;
185 void disposeResultSet();
187 // OPropertyArrayUsageHelper
188 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper() const;
189 // OPropertySetHelper
190 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
192 virtual ~OCommonStatement();
195 void reset () throw( ::com::sun::star::sdbc::SQLException
);
196 void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException
);
197 void parseSql( const ::rtl::OUString
& sql
, QueryData
& _out_rQueryData
);
198 EBookQuery
*whereAnalysis( const OSQLParseNode
* parseTree
);
199 void orderByAnalysis( const OSQLParseNode
* _pOrderByClause
, SortDescriptor
& _out_rSort
);
200 rtl::OUString
getTableName();
201 EBookQuery
*createTrue();
202 EBookQuery
*createTest( const ::rtl::OUString
&aColumnName
,
203 EBookQueryTest eTest
,
204 const ::rtl::OUString
&aMatch
);
209 OEvoabConnection
* getOwnConnection() const { return m_pConnection
;}
211 using OCommonStatement_IBase::operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>;
214 OCommonStatement( OEvoabConnection
* _pConnection
);
217 virtual void SAL_CALL
disposing(void);
219 virtual void SAL_CALL
release() throw();
220 virtual void SAL_CALL
acquire() throw();
222 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
224 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
);
227 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
);
230 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
231 virtual void SAL_CALL
clearWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
234 virtual void SAL_CALL
close( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
237 /** will return the EBookQuery representing the stamement's WHERE condition, or throw
239 Also, all statement dependent members (such as the parser/iterator) will be inited afterwards.
242 impl_getEBookQuery_throw( const ::rtl::OUString
& _rSql
);
244 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>
245 impl_executeQuery_throw( const ::rtl::OUString
& _rSql
);
247 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>
248 impl_executeQuery_throw( const QueryData
& _rData
);
250 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>
251 impl_getConnection() { return ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>( (::com::sun::star::sdbc::XConnection
*)m_pConnection
); }
254 impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode
& _rColumnRef
);
257 typedef ::cppu::ImplHelper2
< ::com::sun::star::lang::XServiceInfo
258 , ::com::sun::star::sdbc::XStatement
260 class OStatement
:public OCommonStatement
261 ,public OStatement_IBase
264 virtual ~OStatement(){}
267 OStatement( OEvoabConnection
* _pConnection
)
268 :OCommonStatement( _pConnection
)
273 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
274 virtual void SAL_CALL
acquire() throw();
275 virtual void SAL_CALL
release() throw();
278 DECLARE_XTYPEPROVIDER()
281 DECLARE_SERVICE_INFO();
284 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
) ;
285 virtual sal_Int32 SAL_CALL
executeUpdate( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
286 virtual sal_Bool SAL_CALL
execute( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
287 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
) ;
291 #endif // CONNECTIVITY_SSTATEMENT_HXX