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 "JoinController.hxx"
23 #include "querycontainerwindow.hxx"
24 #include <svx/ParseContext.hxx>
25 #include "TableFieldDescription.hxx"
27 #include <com/sun/star/sdb/CommandType.hpp>
28 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
29 #include <com/sun/star/sdbcx/XAlterView.hpp>
31 #include <comphelper/proparrhlp.hxx>
32 #include <comphelper/propertycontainer.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <connectivity/sqliterator.hxx>
35 #include <connectivity/sqlparse.hxx>
39 class NamedValueCollection
;
44 class OQueryContainerWindow
;
46 typedef ::comphelper::OPropertyContainer OQueryController_PBase
;
47 typedef ::comphelper::OPropertyArrayUsageHelper
< OQueryController
> OQueryController_PABase
;
48 class OQueryController
:public OJoinController
49 ,public OQueryController_PBase
50 ,public OQueryController_PABase
52 OTableFields m_vTableFieldDesc
;
53 OTableFields m_vUnUsedFieldsDesc
; // contains fields which aren't visible and don't have any criteria
55 css::uno::Sequence
< css::beans::PropertyValue
> m_aFieldInformation
;
57 std::unique_ptr
<::svxform::OSystemParseContext
> m_pParseContext
;
58 ::connectivity::OSQLParser m_aSqlParser
;
59 std::unique_ptr
<::connectivity::OSQLParseTreeIterator
> m_pSqlIterator
;
61 css::uno::Reference
< css::sdb::XSQLQueryComposer
> m_xComposer
;
62 /// if we're editing an existing view, this is non-NULL
63 css::uno::Reference
< css::sdbcx::XAlterView
> m_xAlterView
;
65 OUString m_sStatement
; // contains the current sql statement
66 OUString m_sUpdateCatalogName
; // catalog for update data
67 OUString m_sUpdateSchemaName
; // schema for update data
69 m_sName
; // name of the query
71 sal_Int64 m_nLimit
; // the limit of the query result (All==-1)
73 sal_Int32 m_nVisibleRows
; // which rows the selection browse should show
74 sal_Int32 m_nSplitPos
; // the position of the splitter
75 sal_Int32 m_nCommandType
; // the type of the object we're designing
76 bool m_bGraphicalDesign
; // are we in the graphical design mode (sal_True) or in the text design (sal_False)?
77 bool m_bDistinct
; // true when you want "select distinct" otherwise false
78 bool m_bEscapeProcessing
;// is true when we shouldn't parse the statement
81 /** returns the container of queries, views, or command definitions, depending on what object type
84 Not allowed to be called if we design an independent SQL command.
86 css::uno::Reference
< css::container::XNameAccess
>
87 getObjectContainer() const;
89 bool editingView() const { return m_nCommandType
== css::sdb::CommandType::TABLE
; }
90 bool editingQuery() const { return m_nCommandType
== css::sdb::CommandType::QUERY
; }
91 bool editingCommand() const { return m_nCommandType
== css::sdb::CommandType::COMMAND
; }
93 bool askForNewName( const css::uno::Reference
< css::container::XNameAccess
>& _xElements
,
95 // creates the querycomposer
96 void setQueryComposer();
97 void deleteIterator();
99 bool doSaveAsDoc(bool _bSaveAs
);
101 void saveViewSettings( ::comphelper::NamedValueCollection
& o_rViewSettings
, const bool i_includingCriteria
) const;
102 void loadViewSettings( const ::comphelper::NamedValueCollection
& o_rViewSettings
);
103 OUString
translateStatement( bool _bFireStatementChange
= true );
105 void execute_QueryPropDlg();
108 // all the features which should be handled by this class
109 virtual void describeSupportedFeatures() override
;
110 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
111 virtual FeatureState
GetState(sal_uInt16 nId
) const override
;
113 virtual void Execute(sal_uInt16 nId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
115 virtual void reconnect( bool _bUI
) override
;
116 virtual OUString
getPrivateTitle( ) const override
;
118 OQueryContainerWindow
* getContainer() const { return static_cast< OQueryContainerWindow
* >( getView() ); }
121 OQueryController(const css::uno::Reference
< css::uno::XComponentContext
>& _rM
);
123 virtual ~OQueryController() override
;
124 OTableFields
& getTableFieldDesc() { return m_vTableFieldDesc
; }
125 OTableFields
& getUnUsedFields() { return m_vUnUsedFieldsDesc
; }
129 virtual void impl_onModifyChanged() override
;
131 // should the statement be parsed by our own sql parser
132 bool isEscapeProcessing() const { return m_bEscapeProcessing
; }
133 bool isGraphicalDesign() const { return m_bGraphicalDesign
; }
134 bool isDistinct() const { return m_bDistinct
; }
135 sal_Int64
getLimit() const { return m_nLimit
; }
137 const OUString
& getStatement() const { return m_sStatement
; }
138 sal_Int32
getSplitPos() const { return m_nSplitPos
;}
139 sal_Int32
getVisibleRows() const { return m_nVisibleRows
; }
141 void setDistinct(bool _bDistinct
) { m_bDistinct
= _bDistinct
;}
142 void setLimit(const sal_Int64 _nLimit
) { m_nLimit
= _nLimit
;}
143 void setSplitPos(sal_Int32 _nSplitPos
) { m_nSplitPos
= _nSplitPos
;}
144 void setVisibleRows(sal_Int32 _nVisibleRows
) { m_nVisibleRows
= _nVisibleRows
;}
146 sal_Int32
getColWidth(sal_uInt16 _nColPos
) const;
148 const css::uno::Sequence
< css::beans::PropertyValue
>&
149 getFieldInformation() const { return m_aFieldInformation
; }
151 ::connectivity::OSQLParser
& getParser() { return m_aSqlParser
; }
152 ::connectivity::OSQLParseTreeIterator
& getParseIterator() { return *m_pSqlIterator
; }
154 virtual bool Construct(vcl::Window
* pParent
) override
;
156 DECLARE_XINTERFACE( )
157 DECLARE_XTYPEPROVIDER( )
159 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
160 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
163 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
165 // css::lang::XComponent
166 virtual void SAL_CALL
disposing() override
;
168 virtual OUString SAL_CALL
getImplementationName() override
;
169 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
172 virtual css::uno::Any SAL_CALL
getViewData() override
;
173 virtual void SAL_CALL
restoreViewData(const css::uno::Any
& Data
) override
;
176 virtual void onLoadedMenu(const css::uno::Reference
< css::frame::XLayoutManager
>& _xLayoutManager
) override
;
177 // OPropertyArrayUsageHelper
178 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const override
;
180 // OPropertySetHelper
181 virtual void SAL_CALL
getFastPropertyValue(
182 css::uno::Any
& rValue
,
186 virtual OJoinDesignView
* getJoinView() override
;
187 // ask the user if the design should be saved when it is modified
188 virtual short saveModified() override
;
189 virtual void reset() override
;
190 virtual void impl_initialize(const ::comphelper::NamedValueCollection
& rArguments
) override
;
192 void impl_reset( const bool i_bIgnoreQuerySettings
= false );
193 /// tells the user that we needed to switch to SQL view automatically
194 void impl_showAutoSQLViewError( const css::uno::Any
& _rErrorDetails
);
196 /** switches to the graphical or SQL view mode, as determined by m_bGraphicalDesign
198 void impl_setViewMode( ::dbtools::SQLExceptionInfo
* _pErrorInfo
);
200 /// sets m_sStatement, and notifies our respective property change listeners
201 void setStatement_fireEvent( const OUString
& _rNewStatement
, bool _bFireStatementChange
= true );
202 /// sets the m_bEscapeProcessing member, and notifies our respective property change listeners
203 void setEscapeProcessing_fireEvent( const bool _bEscapeProcessing
);
205 // OJoinController overridables
206 virtual bool allowViews() const override
;
207 virtual bool allowQueries() const override
;
210 DECL_LINK( OnExecuteAddTable
, void*, void );
213 using OQueryController_PBase::getFastPropertyValue
;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */