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>
41 #include "NConnection.hxx"
45 namespace connectivity::evoab
47 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XWarningsSupplier
48 , css::sdbc::XCloseable
49 > OCommonStatement_IBase
;
56 FieldSort( const sal_Int32 _nField
, const bool _bAscending
) : nField( _nField
), bAscending( _bAscending
) { }
58 typedef std::vector
< FieldSort
> SortDescriptor
;
67 class EBookQueryWrapper
76 EBookQueryWrapper(const EBookQueryWrapper
& rhs
)
77 : mpQuery(rhs
.mpQuery
)
80 e_book_query_ref(mpQuery
);
82 EBookQueryWrapper(EBookQueryWrapper
&& rhs
) noexcept
83 : mpQuery(rhs
.mpQuery
)
85 rhs
.mpQuery
= nullptr;
87 void reset(EBookQuery
* pQuery
)
90 e_book_query_unref(mpQuery
);
93 e_book_query_ref(mpQuery
);
95 EBookQueryWrapper
& operator=(const EBookQueryWrapper
& rhs
)
101 EBookQueryWrapper
& operator=(EBookQueryWrapper
&& rhs
)
104 e_book_query_unref(mpQuery
);
105 mpQuery
= rhs
.mpQuery
;
106 rhs
.mpQuery
= nullptr;
112 e_book_query_unref(mpQuery
);
114 EBookQuery
* getQuery() const
123 EBookQueryWrapper aQuery
;
127 QueryFilterType eFilterType
;
128 rtl::Reference
<connectivity::OSQLColumns
> xSelectColumns
;
129 SortDescriptor aSortOrder
;
133 , eFilterType( eFilterOther
)
139 EBookQuery
* getQuery() const { return aQuery
.getQuery(); }
140 void setQuery(EBookQuery
* pQuery
) { aQuery
.reset(pQuery
); }
143 //************ Class: OCommonStatement
144 // is a base class for the normal statement and for the prepared statement
146 class OCommonStatement
:public cppu::BaseMutex
147 ,public OCommonStatement_IBase
148 ,public ::comphelper::OPropertyContainer
149 ,public ::comphelper::OPropertyArrayUsageHelper
< OCommonStatement
>
152 css::uno::WeakReference
< css::sdbc::XResultSet
> m_xResultSet
; // The last ResultSet created
153 rtl::Reference
<OEvoabConnection
> m_xConnection
;
154 connectivity::OSQLParser m_aParser
;
155 connectivity::OSQLParseTreeIterator m_aSQLIterator
;
156 connectivity::OSQLParseNode
*m_pParseTree
;
159 OUString m_aCursorName
;
160 sal_Int32 m_nMaxFieldSize
;
161 sal_Int32 m_nMaxRows
;
162 sal_Int32 m_nQueryTimeOut
;
163 sal_Int32 m_nFetchSize
;
164 sal_Int32 m_nResultSetType
;
165 sal_Int32 m_nFetchDirection
;
166 sal_Int32 m_nResultSetConcurrency
;
167 bool m_bEscapeProcessing
;
172 void disposeResultSet();
174 // OPropertyArrayUsageHelper
175 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper() const override
;
176 // OPropertySetHelper
177 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
179 virtual ~OCommonStatement() override
;
182 void parseSql( const OUString
& sql
, QueryData
& _out_rQueryData
);
183 EBookQuery
*whereAnalysis( const OSQLParseNode
* parseTree
);
184 void orderByAnalysis( const OSQLParseNode
* _pOrderByClause
, SortDescriptor
& _out_rSort
);
185 OUString
getTableName() const;
190 OEvoabConnection
* getOwnConnection() const { return m_xConnection
.get(); }
192 using OCommonStatement_IBase::operator css::uno::Reference
< css::uno::XInterface
>;
195 explicit OCommonStatement( OEvoabConnection
* _pConnection
);
198 virtual void SAL_CALL
disposing() override
;
200 virtual void SAL_CALL
release() noexcept override
;
201 virtual void SAL_CALL
acquire() noexcept override
;
203 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
205 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
208 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
211 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
212 virtual void SAL_CALL
clearWarnings( ) override
;
215 virtual void SAL_CALL
close( ) override
;
218 /** will return the EBookQuery representing the statement WHERE condition, or throw
220 Also, all statement dependent members (such as the parser/iterator) will be inited afterwards.
223 impl_getEBookQuery_throw( const OUString
& _rSql
);
225 css::uno::Reference
< css::sdbc::XResultSet
>
226 impl_executeQuery_throw( const OUString
& _rSql
);
228 css::uno::Reference
< css::sdbc::XResultSet
>
229 impl_executeQuery_throw( const QueryData
& _rData
);
231 css::uno::Reference
< css::sdbc::XConnection
>
232 impl_getConnection() { return css::uno::Reference
< css::sdbc::XConnection
>( m_xConnection
); }
235 impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode
& _rColumnRef
);
238 typedef ::cppu::ImplHelper2
< css::lang::XServiceInfo
239 , css::sdbc::XStatement
241 class OStatement
:public OCommonStatement
242 ,public OStatement_IBase
245 virtual ~OStatement() override
{}
248 explicit OStatement( OEvoabConnection
* _pConnection
)
249 :OCommonStatement( _pConnection
)
254 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
255 virtual void SAL_CALL
acquire() noexcept override
;
256 virtual void SAL_CALL
release() noexcept override
;
259 DECLARE_XTYPEPROVIDER()
262 DECLARE_SERVICE_INFO();
265 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
executeQuery( const OUString
& sql
) override
;
266 virtual sal_Int32 SAL_CALL
executeUpdate( const OUString
& sql
) override
;
267 virtual sal_Bool SAL_CALL
execute( const OUString
& sql
) override
;
268 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( ) override
;
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */