LibreOffice Module connectivity (master) 1
NStatement.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
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>
30#include <comphelper/uno3.hxx>
32#include <com/sun/star/lang/XServiceInfo.hpp>
36#include <com/sun/star/util/XCancellable.hpp>
39
40#include "EApi.h"
41#include "NConnection.hxx"
42
43#include <vector>
44
45namespace connectivity::evoab
46{
47 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier
48 , css::sdbc::XCloseable
50
51 struct FieldSort
52 {
53 sal_Int32 nField;
55
56 FieldSort( const sal_Int32 _nField, const bool _bAscending ) : nField( _nField ), bAscending( _bAscending ) { }
57 };
58 typedef std::vector< FieldSort > SortDescriptor;
59
61 {
65 };
66
68 {
69 private:
71 public:
73 : mpQuery(nullptr)
74 {
75 }
77 : mpQuery(rhs.mpQuery)
78 {
79 if (mpQuery)
81 }
83 : mpQuery(rhs.mpQuery)
84 {
85 rhs.mpQuery = nullptr;
86 }
87 void reset(EBookQuery* pQuery)
88 {
89 if (mpQuery)
91 mpQuery = pQuery;
92 if (mpQuery)
94 }
96 {
97 if (this != &rhs)
98 reset(rhs.mpQuery);
99 return *this;
100 }
102 {
103 if (mpQuery)
105 mpQuery = rhs.mpQuery;
106 rhs.mpQuery = nullptr;
107 return *this;
108 }
110 {
111 if (mpQuery)
113 }
115 {
116 return mpQuery;
117 }
118 };
119
121 {
122 private:
124
125 public:
126 OUString sTable;
130
132 : sTable()
135 , aSortOrder()
136 {
137 }
138
139 EBookQuery* getQuery() const { return aQuery.getQuery(); }
140 void setQuery(EBookQuery* pQuery) { aQuery.reset(pQuery); }
141 };
142
143 //************ Class: OCommonStatement
144 // is a base class for the normal statement and for the prepared statement
145
149 ,public ::comphelper::OPropertyArrayUsageHelper< OCommonStatement >
150 {
151 private:
152 css::uno::WeakReference< css::sdbc::XResultSet> m_xResultSet; // The last ResultSet created
157
158 // <properties>
161 sal_Int32 m_nMaxRows;
163 sal_Int32 m_nFetchSize;
168 // </properties>
169
170 protected:
171
172 void disposeResultSet();
173
174 // OPropertyArrayUsageHelper
175 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override;
176 // OPropertySetHelper
177 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
178
179 virtual ~OCommonStatement() override;
180
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;
186
187 public:
188
189 // other methods
191
192 using OCommonStatement_IBase::operator css::uno::Reference< css::uno::XInterface >;
193
194 protected:
195 explicit OCommonStatement( OEvoabConnection* _pConnection );
196
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;
206
207 // XPropertySet
208 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
209
210 // XWarningsSupplier
211 virtual css::uno::Any SAL_CALL getWarnings( ) override;
212 virtual void SAL_CALL clearWarnings( ) override;
213
214 // XCloseable
215 virtual void SAL_CALL close( ) override;
216
217 protected:
223 impl_getEBookQuery_throw( const OUString& _rSql );
224
225 css::uno::Reference< css::sdbc::XResultSet >
226 impl_executeQuery_throw( const OUString& _rSql );
227
228 css::uno::Reference< css::sdbc::XResultSet >
229 impl_executeQuery_throw( const QueryData& _rData );
230
231 css::uno::Reference< css::sdbc::XConnection >
232 impl_getConnection() { return css::uno::Reference< css::sdbc::XConnection >( m_xConnection ); }
233
234 OUString
235 impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode& _rColumnRef );
236 };
237
238 typedef ::cppu::ImplHelper2 < css::lang::XServiceInfo
239 , css::sdbc::XStatement
242 ,public OStatement_IBase
243 {
244 protected:
245 virtual ~OStatement() override {}
246
247 public:
248 explicit OStatement( OEvoabConnection* _pConnection)
249 :OCommonStatement( _pConnection)
250 {
251 }
252
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;
257
258 // XTypeProvider
259 DECLARE_XTYPEPROVIDER()
260
261 // XServiceInfo
263
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 ;
269 };
270}
271
272
273/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
EAPI_EXTERN EBookQuery *(* e_book_query_ref)(EBookQuery *q)
Definition: EApi.h:115
EAPI_EXTERN void(* e_book_query_unref)(EBookQuery *q)
Definition: EApi.h:116
void EBookQuery
Definition: EApi.h:81
Parser for SQL92.
Definition: sqlparse.hxx:110
EBookQueryWrapper(EBookQueryWrapper &&rhs) noexcept
Definition: NStatement.hxx:82
EBookQueryWrapper(const EBookQueryWrapper &rhs)
Definition: NStatement.hxx:76
void reset(EBookQuery *pQuery)
Definition: NStatement.hxx:87
EBookQueryWrapper & operator=(EBookQueryWrapper &&rhs)
Definition: NStatement.hxx:101
EBookQueryWrapper & operator=(const EBookQueryWrapper &rhs)
Definition: NStatement.hxx:95
void orderByAnalysis(const OSQLParseNode *_pOrderByClause, SortDescriptor &_out_rSort)
Definition: NStatement.cxx:251
connectivity::OSQLParseTreeIterator m_aSQLIterator
Definition: NStatement.hxx:155
QueryData impl_getEBookQuery_throw(const OUString &_rSql)
will return the EBookQuery representing the statement WHERE condition, or throw
Definition: NStatement.cxx:587
virtual void SAL_CALL acquire() noexcept override
Definition: NStatement.cxx:576
css::uno::Reference< css::sdbc::XConnection > impl_getConnection()
Definition: NStatement.hxx:232
virtual css::uno::Any SAL_CALL getWarnings() override
Definition: NStatement.cxx:546
OUString impl_getColumnRefColumnName_throw(const ::connectivity::OSQLParseNode &_rColumnRef)
Definition: NStatement.cxx:217
css::uno::WeakReference< css::sdbc::XResultSet > m_xResultSet
Definition: NStatement.hxx:152
OEvoabConnection * getOwnConnection() const
Definition: NStatement.hxx:190
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
Definition: NStatement.cxx:570
rtl::Reference< OEvoabConnection > m_xConnection
Definition: NStatement.hxx:153
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: NStatement.cxx:635
virtual void SAL_CALL disposing() override
Definition: NStatement.cxx:170
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
Definition: NStatement.cxx:563
virtual void SAL_CALL close() override
Definition: NStatement.cxx:207
void parseSql(const OUString &sql, QueryData &_out_rQueryData)
Definition: NStatement.cxx:486
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: NStatement.cxx:189
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL release() noexcept override
Definition: NStatement.cxx:581
virtual void SAL_CALL clearWarnings() override
Definition: NStatement.cxx:556
EBookQuery * whereAnalysis(const OSQLParseNode *parseTree)
Definition: NStatement.cxx:291
OCommonStatement(OEvoabConnection *_pConnection)
Definition: NStatement.cxx:75
connectivity::OSQLParser m_aParser
Definition: NStatement.hxx:154
connectivity::OSQLParseNode * m_pParseTree
Definition: NStatement.hxx:156
css::uno::Reference< css::sdbc::XResultSet > impl_executeQuery_throw(const OUString &_rSql)
Definition: NStatement.cxx:622
OStatement(OEvoabConnection *_pConnection)
Definition: NStatement.hxx:248
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
Definition: NStatement.cxx:536
virtual void SAL_CALL release() noexcept override
virtual ~OStatement() override
Definition: NStatement.hxx:245
virtual sal_Int32 SAL_CALL executeUpdate(const OUString &sql) override
Definition: NStatement.cxx:672
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery(const OUString &sql) override
Definition: NStatement.cxx:663
virtual void SAL_CALL acquire() noexcept override
virtual sal_Bool SAL_CALL execute(const OUString &sql) override
Definition: NStatement.cxx:653
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Type
::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier, css::sdbc::XCloseable > OCommonStatement_IBase
Definition: NStatement.hxx:49
std::vector< FieldSort > SortDescriptor
Definition: NStatement.hxx:58
::cppu::ImplHelper2< css::lang::XServiceInfo, css::sdbc::XStatement > OStatement_IBase
Definition: NStatement.hxx:240
FieldSort(const sal_Int32 _nField, const bool _bAscending)
Definition: NStatement.hxx:56
rtl::Reference< connectivity::OSQLColumns > xSelectColumns
Definition: NStatement.hxx:128
EBookQuery * getQuery() const
Definition: NStatement.hxx:139
void setQuery(EBookQuery *pQuery)
Definition: NStatement.hxx:140
unsigned char sal_Bool