1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <com/sun/star/sdbc/XStatement.hpp>
23 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
24 #include <com/sun/star/sdbc/XMultipleResults.hpp>
25 #include <com/sun/star/sdbc/XCloseable.hpp>
26 #include <com/sun/star/sdbc/SQLWarning.hpp>
27 #include <comphelper/proparrhlp.hxx>
28 #include <cppuhelper/implbase2.hxx>
29 #include <cppuhelper/basemutex.hxx>
30 #include <comphelper/uno3.hxx>
31 #include <connectivity/CommonTools.hxx>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <connectivity/sqliterator.hxx>
34 #include <connectivity/sqlparse.hxx>
35 #include <connectivity/FValue.hxx>
36 #include <com/sun/star/util/XCancellable.hpp>
37 #include <cppuhelper/compbase.hxx>
38 #include <comphelper/propertycontainer.hxx>
39 #include <unotools/weakref.hxx>
42 #include "NConnection.hxx"
46 namespace connectivity::evoab
48 class OEvoabResultSet
;
50 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XWarningsSupplier
51 , css::sdbc::XCloseable
52 > OCommonStatement_IBase
;
59 FieldSort( const sal_Int32 _nField
, const bool _bAscending
) : nField( _nField
), bAscending( _bAscending
) { }
61 typedef std::vector
< FieldSort
> SortDescriptor
;
70 class EBookQueryWrapper
79 EBookQueryWrapper(const EBookQueryWrapper
& rhs
)
80 : mpQuery(rhs
.mpQuery
)
83 e_book_query_ref(mpQuery
);
85 EBookQueryWrapper(EBookQueryWrapper
&& rhs
) noexcept
86 : mpQuery(rhs
.mpQuery
)
88 rhs
.mpQuery
= nullptr;
90 void reset(EBookQuery
* pQuery
)
93 e_book_query_unref(mpQuery
);
96 e_book_query_ref(mpQuery
);
98 EBookQueryWrapper
& operator=(const EBookQueryWrapper
& rhs
)
104 EBookQueryWrapper
& operator=(EBookQueryWrapper
&& rhs
)
107 e_book_query_unref(mpQuery
);
108 mpQuery
= rhs
.mpQuery
;
109 rhs
.mpQuery
= nullptr;
115 e_book_query_unref(mpQuery
);
117 EBookQuery
* getQuery() const
126 EBookQueryWrapper aQuery
;
130 QueryFilterType eFilterType
;
131 rtl::Reference
<connectivity::OSQLColumns
> xSelectColumns
;
132 SortDescriptor aSortOrder
;
136 , eFilterType( eFilterOther
)
142 EBookQuery
* getQuery() const { return aQuery
.getQuery(); }
143 void setQuery(EBookQuery
* pQuery
) { aQuery
.reset(pQuery
); }
146 //************ Class: OCommonStatement
147 // is a base class for the normal statement and for the prepared statement
149 class OCommonStatement
:public cppu::BaseMutex
150 ,public OCommonStatement_IBase
151 ,public ::comphelper::OPropertyContainer
152 ,public ::comphelper::OPropertyArrayUsageHelper
< OCommonStatement
>
155 unotools::WeakReference
< OEvoabResultSet
> m_xResultSet
; // The last ResultSet created
156 rtl::Reference
<OEvoabConnection
> m_xConnection
;
157 connectivity::OSQLParser m_aParser
;
158 connectivity::OSQLParseTreeIterator m_aSQLIterator
;
159 connectivity::OSQLParseNode
*m_pParseTree
;
162 OUString m_aCursorName
;
163 sal_Int32 m_nMaxFieldSize
;
164 sal_Int32 m_nMaxRows
;
165 sal_Int32 m_nQueryTimeOut
;
166 sal_Int32 m_nFetchSize
;
167 sal_Int32 m_nResultSetType
;
168 sal_Int32 m_nFetchDirection
;
169 sal_Int32 m_nResultSetConcurrency
;
170 bool m_bEscapeProcessing
;
175 void disposeResultSet();
177 // OPropertyArrayUsageHelper
178 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper() const override
;
179 // OPropertySetHelper
180 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
182 virtual ~OCommonStatement() override
;
185 void parseSql( const OUString
& sql
, QueryData
& _out_rQueryData
);
186 EBookQuery
*whereAnalysis( const OSQLParseNode
* parseTree
);
187 void orderByAnalysis( const OSQLParseNode
* _pOrderByClause
, SortDescriptor
& _out_rSort
);
188 OUString
getTableName() const;
193 OEvoabConnection
* getOwnConnection() const { return m_xConnection
.get(); }
195 using OCommonStatement_IBase::operator css::uno::Reference
< css::uno::XInterface
>;
198 explicit OCommonStatement( OEvoabConnection
* _pConnection
);
201 virtual void SAL_CALL
disposing() override
;
203 virtual void SAL_CALL
release() noexcept override
;
204 virtual void SAL_CALL
acquire() noexcept override
;
206 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
208 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
211 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
214 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
215 virtual void SAL_CALL
clearWarnings( ) override
;
218 virtual void SAL_CALL
close( ) override
;
221 /** will return the EBookQuery representing the statement WHERE condition, or throw
223 Also, all statement dependent members (such as the parser/iterator) will be inited afterwards.
226 impl_getEBookQuery_throw( const OUString
& _rSql
);
228 css::uno::Reference
< css::sdbc::XResultSet
>
229 impl_executeQuery_throw( const OUString
& _rSql
);
231 css::uno::Reference
< css::sdbc::XResultSet
>
232 impl_executeQuery_throw( const QueryData
& _rData
);
234 css::uno::Reference
< css::sdbc::XConnection
>
235 impl_getConnection() { return css::uno::Reference
< css::sdbc::XConnection
>( m_xConnection
); }
238 impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode
& _rColumnRef
);
241 typedef ::cppu::ImplHelper2
< css::lang::XServiceInfo
242 , css::sdbc::XStatement
244 class OStatement
:public OCommonStatement
245 ,public OStatement_IBase
248 virtual ~OStatement() override
{}
251 explicit OStatement( OEvoabConnection
* _pConnection
)
252 :OCommonStatement( _pConnection
)
257 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
258 virtual void SAL_CALL
acquire() noexcept override
;
259 virtual void SAL_CALL
release() noexcept override
;
262 DECLARE_XTYPEPROVIDER()
265 DECLARE_SERVICE_INFO();
268 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
executeQuery( const OUString
& sql
) override
;
269 virtual sal_Int32 SAL_CALL
executeUpdate( const OUString
& sql
) override
;
270 virtual sal_Bool SAL_CALL
execute( const OUString
& sql
) override
;
271 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( ) override
;
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */