LibreOffice Module dbaccess (master) 1
SingleSelectQueryComposer.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#pragma once
20
21#include <com/sun/star/sdb/XParametersSupplier.hpp>
22#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
23#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
24#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
26#include <com/sun/star/script/XTypeConverter.hpp>
30#include <apitools.hxx>
32#include <comphelper/uno3.hxx>
35#include <svx/ParseContext.hxx>
36
37namespace com::sun::star::util {
38 class XNumberFormatsSupplier;
39 class XNumberFormatter;
40}
41
42namespace dbaccess
43{
44 typedef ::cppu::ImplHelper5< css::sdb::XSingleSelectQueryComposer,
45 css::sdb::XParametersSupplier,
46 css::sdbcx::XColumnsSupplier,
47 css::sdbcx::XTablesSupplier,
48 css::lang::XServiceInfo > OSingleSelectQueryComposer_BASE;
49
50 class OPrivateColumns;
51 class OPrivateTables;
52
54 ,public OSubComponent
56 ,public ::comphelper::OPropertyArrayUsageHelper < OSingleSelectQueryComposer >
58 {
60 {
61 Where = 0, // the 0 is important, as it will be used as index into arrays
65
67 };
68 static void incSQLPart( SQLPart& e ) { e = static_cast<SQLPart>(1 + static_cast<size_t>(e)); }
70 {
75 };
76 typedef std::function<const ::connectivity::OSQLParseNode*(::connectivity::OSQLParseTreeIterator *)>
80 ::connectivity::OSQLParseTreeIterator m_aSqlIterator; // the iterator for the complete statement
81 ::connectivity::OSQLParseTreeIterator m_aAdditiveIterator; // the iterator for the "additive statement" (means without the clauses of the elementary statement)
82 std::vector<std::unique_ptr<OPrivateColumns>>
83 m_aColumnsCollection; // used for columns and parameters of old queries
84 std::vector<std::unique_ptr<OPrivateTables>>
86
87 std::vector< OUString > m_aElementaryParts; // the filter/groupby/having/order of the elementary statement
88
89 css::uno::Reference< css::sdbc::XConnection> m_xConnection;
90 css::uno::Reference< css::sdbc::XDatabaseMetaData> m_xMetaData;
91 css::uno::Reference< css::container::XNameAccess> m_xConnectionTables;
92 css::uno::Reference< css::container::XNameAccess> m_xConnectionQueries;
93 css::uno::Reference< css::util::XNumberFormatsSupplier > m_xNumberFormatsSupplier;
94 css::uno::Reference< css::uno::XComponentContext> m_aContext;
95 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
96
97 std::vector<std::unique_ptr<OPrivateColumns>> m_aCurrentColumns;
98 std::unique_ptr<OPrivateTables> m_pTables; // currently used tables
99
100 OUString m_aPureSelectSQL; // the pure select statement, without filter/order/groupby/having
102 OUString m_sCommand;
103 css::lang::Locale m_aLocale;
104 sal_Int32 m_nBoolCompareMode; // how to compare bool values
105 sal_Int32 m_nCommandType;
106
107 // <properties>
108 OUString m_sOriginal;
109 // </properties>
110
111
113 std::vector< std::vector < css::beans::PropertyValue > >& rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;
115 std::vector < css::beans::PropertyValue > & rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;
117 std::vector < css::beans::PropertyValue > & rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;
119 std::vector < css::beans::PropertyValue > & rFilters, const css::uno::Reference< css::util::XNumberFormatter > & xFormatter) const;
120
121 static OUString getColumnName(::connectivity::OSQLParseNode const * pColumnRef, ::connectivity::OSQLParseTreeIterator const & _rIterator);
122 OUString getTableAlias(const css::uno::Reference< css::beans::XPropertySet >& column ) const;
123 static sal_Int32 getPredicateType(::connectivity::OSQLParseNode const * _pPredicate);
124 // clears all Columns,Parameters and tables and insert it to their vectors
126 // clears the columns collection given by EColumnType
127 void clearColumns( const EColumnType _eType );
128
133 OUString getStatementPart( TGetParseNode const & _aGetFunctor, ::connectivity::OSQLParseTreeIterator& _rIterator );
134 void setQuery_Impl( const OUString& command );
135
136 void setConditionByColumn( const css::uno::Reference< css::beans::XPropertySet >& column
137 , bool andCriteria
138 , std::function<bool(OSingleSelectQueryComposer *, const OUString&)> const & _aSetFunctor
139 ,sal_Int32 filterOperator);
140
148 css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >
149 getStructuredCondition( TGetParseNode const & _aGetFunctor );
150
151 css::uno::Reference< css::container::XIndexAccess >
152 setCurrentColumns( EColumnType _eType, const ::rtl::Reference< ::connectivity::OSQLColumns >& _rCols );
153
154 //helper methods for mem_fun_t
155 bool implSetFilter(const OUString& _sFilter) { setFilter(_sFilter); return true;}
156 bool implSetHavingClause(const OUString& _sFilter) { setHavingClause(_sFilter); return true;}
157
169 OUString getSQLPart( SQLPart _ePart, ::connectivity::OSQLParseTreeIterator& _rIterator, bool _bWithKeyword );
170
173 static OUString getKeyword( SQLPart _ePart );
174
177 void setSingleAdditiveClause( SQLPart _ePart, const OUString& _rClause );
178
181 OUString composeStatementFromParts( const std::vector< OUString >& _rParts );
182
191 OUString impl_getColumnRealName_throw(const css::uno::Reference< css::beans::XPropertySet >& column, bool bGroupBy);
192
199 OUString impl_getColumnNameOrderBy_throw(const css::uno::Reference< css::beans::XPropertySet >& column);
200
201 protected:
202 virtual ~OSingleSelectQueryComposer() override;
203 public:
204
205 OSingleSelectQueryComposer( const css::uno::Reference< css::container::XNameAccess>& _xTableSupplier,
206 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
207 const css::uno::Reference< css::uno::XComponentContext>& _rContext);
208
209
210 void SAL_CALL disposing() override;
211
212 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
213 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
214
215 // css::uno::XInterface
217
218 // XServiceInfo
220
221 virtual css::uno::Reference< css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
222 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
223 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override;
224
225
226 // css::sdb::XSingleSelectQueryComposer
227 virtual OUString SAL_CALL getElementaryQuery() override;
228 virtual void SAL_CALL setElementaryQuery( const OUString& _rElementary ) override;
229 virtual void SAL_CALL setFilter( const OUString& filter ) override;
230 virtual void SAL_CALL setStructuredFilter( const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& filter ) override;
231 virtual void SAL_CALL appendFilterByColumn( const css::uno::Reference< css::beans::XPropertySet >& column, sal_Bool andCriteria,sal_Int32 filterOperator ) override;
232 virtual void SAL_CALL appendGroupByColumn( const css::uno::Reference< css::beans::XPropertySet >& column ) override;
233 virtual void SAL_CALL setGroup( const OUString& group ) override;
234 virtual void SAL_CALL setHavingClause( const OUString& filter ) override;
235 virtual void SAL_CALL setStructuredHavingClause( const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& filter ) override;
236 virtual void SAL_CALL appendHavingClauseByColumn( const css::uno::Reference< css::beans::XPropertySet >& column, sal_Bool andCriteria,sal_Int32 filterOperator ) override;
237 virtual void SAL_CALL appendOrderByColumn( const css::uno::Reference< css::beans::XPropertySet >& column, sal_Bool ascending ) override;
238 virtual void SAL_CALL setOrder( const OUString& order ) override;
239
240 // XSingleSelectQueryAnalyzer
241 virtual OUString SAL_CALL getQuery( ) override;
242 virtual void SAL_CALL setQuery( const OUString& command ) override;
243 virtual void SAL_CALL setCommand( const OUString& command,sal_Int32 CommandType ) override;
244 virtual OUString SAL_CALL getFilter( ) override;
245 virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getStructuredFilter( ) override;
246 virtual OUString SAL_CALL getGroup( ) override;
247 virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getGroupColumns( ) override;
248 virtual OUString SAL_CALL getHavingClause( ) override;
249 virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getStructuredHavingClause( ) override;
250 virtual OUString SAL_CALL getOrder( ) override;
251 virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getOrderColumns( ) override;
252 virtual OUString SAL_CALL getQueryWithSubstitution( ) override;
253
254 // XColumnsSupplier
255 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getColumns( ) override;
256 // XTablesSupplier
257 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables( ) override;
258 // XParametersSupplier
259 virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getParameters( ) override;
260 };
261}
262
263/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setConditionByColumn(const css::uno::Reference< css::beans::XPropertySet > &column, bool andCriteria, std::function< bool(OSingleSelectQueryComposer *, const OUString &)> const &_aSetFunctor, sal_Int32 filterOperator)
OUString getTableAlias(const css::uno::Reference< css::beans::XPropertySet > &column) const
std::unique_ptr< OPrivateTables > m_pTables
OUString impl_getColumnNameOrderBy_throw(const css::uno::Reference< css::beans::XPropertySet > &column)
return the name of the column in the query for ORDER BY clause.
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual OUString SAL_CALL getGroup() override
std::vector< std::unique_ptr< OPrivateColumns > > m_aColumnsCollection
bool implSetFilter(const OUString &_sFilter)
OUString getStatementPart(TGetParseNode const &_aGetFunctor, ::connectivity::OSQLParseTreeIterator &_rIterator)
retrieves a particular part of a statement
css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter
OSingleSelectQueryComposer(const css::uno::Reference< css::container::XNameAccess > &_xTableSupplier, const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const css::uno::Reference< css::uno::XComponentContext > &_rContext)
::connectivity::OSQLParseTreeIterator m_aAdditiveIterator
css::uno::Reference< css::container::XNameAccess > m_xConnectionTables
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
OUString composeStatementFromParts(const std::vector< OUString > &_rParts)
composes a statement from m_aPureSelectSQL and the 4 usual clauses
virtual void SAL_CALL appendOrderByColumn(const css::uno::Reference< css::beans::XPropertySet > &column, sal_Bool ascending) override
::connectivity::OSQLParseTreeIterator m_aSqlIterator
virtual void SAL_CALL setElementaryQuery(const OUString &_rElementary) override
bool setANDCriteria(::connectivity::OSQLParseNode const *pCondition, ::connectivity::OSQLParseTreeIterator &_rIterator, std::vector< css::beans::PropertyValue > &rFilters, const css::uno::Reference< css::util::XNumberFormatter > &xFormatter) const
std::function< const ::connectivity::OSQLParseNode *(::connectivity::OSQLParseTreeIterator *)> TGetParseNode
bool setORCriteria(::connectivity::OSQLParseNode const *pCondition, ::connectivity::OSQLParseTreeIterator &_rIterator, std::vector< std::vector< css::beans::PropertyValue > > &rFilters, const css::uno::Reference< css::util::XNumberFormatter > &xFormatter) const
virtual void SAL_CALL setStructuredHavingClause(const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > &filter) override
virtual OUString SAL_CALL getHavingClause() override
std::vector< std::unique_ptr< OPrivateTables > > m_aTablesCollection
virtual OUString SAL_CALL getFilter() override
virtual void SAL_CALL setOrder(const OUString &order) override
css::uno::Reference< css::sdbc::XConnection > m_xConnection
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables() override
virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getStructuredFilter() override
virtual OUString SAL_CALL getOrder() override
bool setComparisonPredicate(::connectivity::OSQLParseNode const *pCondition, ::connectivity::OSQLParseTreeIterator const &_rIterator, std::vector< css::beans::PropertyValue > &rFilters, const css::uno::Reference< css::util::XNumberFormatter > &xFormatter) const
css::uno::Reference< css::container::XNameAccess > m_xConnectionQueries
virtual void SAL_CALL appendFilterByColumn(const css::uno::Reference< css::beans::XPropertySet > &column, sal_Bool andCriteria, sal_Int32 filterOperator) override
virtual void SAL_CALL setFilter(const OUString &filter) override
css::uno::Reference< css::container::XIndexAccess > setCurrentColumns(EColumnType _eType, const ::rtl::Reference< ::connectivity::OSQLColumns > &_rCols)
virtual void SAL_CALL setHavingClause(const OUString &filter) override
virtual void SAL_CALL setQuery(const OUString &command) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual OUString SAL_CALL getElementaryQuery() override
::svxform::OSystemParseContext m_aParseContext
virtual void SAL_CALL appendGroupByColumn(const css::uno::Reference< css::beans::XPropertySet > &column) override
virtual OUString SAL_CALL getQueryWithSubstitution() override
virtual void SAL_CALL setGroup(const OUString &group) override
virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getStructuredHavingClause() override
virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getGroupColumns() override
virtual void SAL_CALL setCommand(const OUString &command, sal_Int32 CommandType) override
OUString getSQLPart(SQLPart _ePart, ::connectivity::OSQLParseTreeIterator &_rIterator, bool _bWithKeyword)
returns the part of the select statement
css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > getStructuredCondition(TGetParseNode const &_aGetFunctor)
getStructuredCondition returns the structured condition for the where or having clause
bool setLikePredicate(::connectivity::OSQLParseNode const *pCondition, ::connectivity::OSQLParseTreeIterator const &_rIterator, std::vector< css::beans::PropertyValue > &rFilters, const css::uno::Reference< css::util::XNumberFormatter > &xFormatter) const
static OUString getKeyword(SQLPart _ePart)
retrieves the keyword for the given SQLPart
css::uno::Reference< css::uno::XComponentContext > m_aContext
void setSingleAdditiveClause(SQLPart _ePart, const OUString &_rClause)
sets a single "additive" clause, means a filter/groupby/having/order clause
css::uno::Reference< css::util::XNumberFormatsSupplier > m_xNumberFormatsSupplier
OUString impl_getColumnRealName_throw(const css::uno::Reference< css::beans::XPropertySet > &column, bool bGroupBy)
return the name of the column in the source table.
virtual OUString SAL_CALL getQuery() override
virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getParameters() override
bool implSetHavingClause(const OUString &_sFilter)
std::vector< std::unique_ptr< OPrivateColumns > > m_aCurrentColumns
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getColumns() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getOrderColumns() override
static OUString getColumnName(::connectivity::OSQLParseNode const *pColumnRef, ::connectivity::OSQLParseTreeIterator const &_rIterator)
virtual void SAL_CALL setStructuredFilter(const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > &filter) override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
static sal_Int32 getPredicateType(::connectivity::OSQLParseNode const *_pPredicate)
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual void SAL_CALL appendHavingClauseByColumn(const css::uno::Reference< css::beans::XPropertySet > &column, sal_Bool andCriteria, sal_Int32 filterOperator) override
::cppu::ImplHelper5< css::sdb::XSingleSelectQueryComposer, css::sdb::XParametersSupplier, css::sdbcx::XColumnsSupplier, css::sdbcx::XTablesSupplier, css::lang::XServiceInfo > OSingleSelectQueryComposer_BASE
unsigned char sal_Bool
#define DECLARE_XINTERFACE()