bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / evoab2 / NStatement.hxx
bloba348c5335d56d64b77718670765a6d1181886856
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
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>
40 #include "EApi.h"
41 #include "NConnection.hxx"
43 #include <vector>
45 namespace connectivity::evoab
47 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier
48 , css::sdbc::XCloseable
49 > OCommonStatement_IBase;
51 struct FieldSort
53 sal_Int32 nField;
54 bool bAscending;
56 FieldSort( const sal_Int32 _nField, const bool _bAscending ) : nField( _nField ), bAscending( _bAscending ) { }
58 typedef std::vector< FieldSort > SortDescriptor;
60 enum QueryFilterType
62 eFilterAlwaysFalse,
63 eFilterNone,
64 eFilterOther
67 class EBookQueryWrapper
69 private:
70 EBookQuery* mpQuery;
71 public:
72 EBookQueryWrapper()
73 : mpQuery(nullptr)
76 EBookQueryWrapper(const EBookQueryWrapper& rhs)
77 : mpQuery(rhs.mpQuery)
79 if (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)
89 if (mpQuery)
90 e_book_query_unref(mpQuery);
91 mpQuery = pQuery;
92 if (mpQuery)
93 e_book_query_ref(mpQuery);
95 EBookQueryWrapper& operator=(const EBookQueryWrapper& rhs)
97 if (this != &rhs)
98 reset(rhs.mpQuery);
99 return *this;
101 EBookQueryWrapper& operator=(EBookQueryWrapper&& rhs)
103 if (mpQuery)
104 e_book_query_unref(mpQuery);
105 mpQuery = rhs.mpQuery;
106 rhs.mpQuery = nullptr;
107 return *this;
109 ~EBookQueryWrapper()
111 if (mpQuery)
112 e_book_query_unref(mpQuery);
114 EBookQuery* getQuery() const
116 return mpQuery;
120 struct QueryData
122 private:
123 EBookQueryWrapper aQuery;
125 public:
126 OUString sTable;
127 QueryFilterType eFilterType;
128 rtl::Reference<connectivity::OSQLColumns> xSelectColumns;
129 SortDescriptor aSortOrder;
131 QueryData()
132 : sTable()
133 , eFilterType( eFilterOther )
134 , xSelectColumns()
135 , aSortOrder()
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 >
151 private:
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;
158 // <properties>
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;
168 // </properties>
170 protected:
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;
181 protected:
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;
187 public:
189 // other methods
190 OEvoabConnection* getOwnConnection() const { return m_xConnection.get(); }
192 using OCommonStatement_IBase::operator css::uno::Reference< css::uno::XInterface >;
194 protected:
195 explicit OCommonStatement( OEvoabConnection* _pConnection );
197 // OComponentHelper
198 virtual void SAL_CALL disposing() override;
199 // XInterface
200 virtual void SAL_CALL release() noexcept override;
201 virtual void SAL_CALL acquire() noexcept override;
202 // XInterface
203 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
204 //XTypeProvider
205 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
207 // XPropertySet
208 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
210 // XWarningsSupplier
211 virtual css::uno::Any SAL_CALL getWarnings( ) override;
212 virtual void SAL_CALL clearWarnings( ) override;
214 // XCloseable
215 virtual void SAL_CALL close( ) override;
217 protected:
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.
222 QueryData
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 ); }
234 OUString
235 impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode& _rColumnRef );
238 typedef ::cppu::ImplHelper2 < css::lang::XServiceInfo
239 , css::sdbc::XStatement
240 > OStatement_IBase;
241 class OStatement :public OCommonStatement
242 ,public OStatement_IBase
244 protected:
245 virtual ~OStatement() override {}
247 public:
248 explicit OStatement( OEvoabConnection* _pConnection)
249 :OCommonStatement( _pConnection)
253 // XInterface
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;
258 // XTypeProvider
259 DECLARE_XTYPEPROVIDER()
261 // XServiceInfo
262 DECLARE_SERVICE_INFO();
264 // XStatement
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: */