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 .
20 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_QUERYCONTROLLER_HXX
21 #define INCLUDED_DBACCESS_SOURCE_UI_INC_QUERYCONTROLLER_HXX
23 #include "JoinController.hxx"
24 #include "JoinTableView.hxx"
25 #include "querycontainerwindow.hxx"
26 #include "queryview.hxx"
27 #include "svx/ParseContext.hxx"
28 #include "TableFieldDescription.hxx"
30 #include <com/sun/star/io/XObjectInputStream.hpp>
31 #include <com/sun/star/io/XObjectOutputStream.hpp>
32 #include <com/sun/star/sdb/CommandType.hpp>
33 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
34 #include <com/sun/star/sdbc/XConnection.hpp>
35 #include <com/sun/star/sdbcx/XAlterView.hpp>
37 #include <comphelper/proparrhlp.hxx>
38 #include <comphelper/propertycontainer.hxx>
39 #include <comphelper/uno3.hxx>
40 #include <connectivity/sqliterator.hxx>
41 #include <connectivity/sqlnode.hxx>
42 #include <connectivity/sqlparse.hxx>
43 #include <svl/undo.hxx>
47 class NamedValueCollection
;
52 class OQueryContainerWindow
;
54 typedef ::comphelper::OPropertyContainer OQueryController_PBase
;
55 typedef ::comphelper::OPropertyArrayUsageHelper
< OQueryController
> OQueryController_PABase
;
56 class OQueryController
:public OJoinController
57 ,public OQueryController_PBase
58 ,public OQueryController_PABase
60 OTableFields m_vTableFieldDesc
;
61 OTableFields m_vUnUsedFieldsDesc
; // contains fields which aren't visible and don't have any criteria
63 css::uno::Sequence
< css::beans::PropertyValue
> m_aFieldInformation
;
65 ::svxform::OSystemParseContext
* m_pParseContext
;
66 ::connectivity::OSQLParser m_aSqlParser
;
67 ::connectivity::OSQLParseTreeIterator
* m_pSqlIterator
;
69 css::uno::Reference
< css::sdb::XSQLQueryComposer
> m_xComposer
;
70 /// if we're editing an existing view, this is non-NULL
71 css::uno::Reference
< css::sdbcx::XAlterView
> m_xAlterView
;
73 OUString m_sStatement
; // contains the current sql statement
74 OUString m_sUpdateCatalogName
; // catalog for update data
75 OUString m_sUpdateSchemaName
; // schema for update data
76 OUString m_sUpdateTableName
; // table for update data
78 m_sName
; // name of the query
80 sal_Int64 m_nLimit
; // the limit of the query result (All==-1)
82 sal_Int32 m_nVisibleRows
; // which rows the selection browse should show
83 sal_Int32 m_nSplitPos
; // the position of the splitter
84 sal_Int32 m_nCommandType
; // the type of the object we're designing
85 bool m_bGraphicalDesign
; // are we in the graphical design mode (sal_True) or in the text design (sal_False)?
86 bool m_bDistinct
; // true when you want "select distinct" otherwise false
87 bool m_bEscapeProcessing
;// is true when we shouldn't parse the statement
90 /** returns the container of queries, views, or command definitions, depending on what object type
93 Not allowed to be called if we design an independent SQL command.
95 css::uno::Reference
< css::container::XNameAccess
>
96 getObjectContainer() const;
98 inline bool editingView() const { return m_nCommandType
== css::sdb::CommandType::TABLE
; }
99 inline bool editingQuery() const { return m_nCommandType
== css::sdb::CommandType::QUERY
; }
100 inline bool editingCommand() const { return m_nCommandType
== css::sdb::CommandType::COMMAND
; }
102 bool askForNewName( const css::uno::Reference
< css::container::XNameAccess
>& _xElements
,
104 // creates the querycomposer
105 void setQueryComposer();
106 void deleteIterator();
108 bool doSaveAsDoc(bool _bSaveAs
);
110 void saveViewSettings( ::comphelper::NamedValueCollection
& o_rViewSettings
, const bool i_includingCriteria
) const;
111 void loadViewSettings( const ::comphelper::NamedValueCollection
& o_rViewSettings
);
112 OUString
translateStatement( bool _bFireStatementChange
= true );
114 void execute_QueryPropDlg();
117 // all the features which should be handled by this class
118 virtual void describeSupportedFeatures() override
;
119 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
120 virtual FeatureState
GetState(sal_uInt16 nId
) const override
;
122 virtual void Execute(sal_uInt16 nId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
124 virtual void reconnect( bool _bUI
) override
;
125 virtual OUString
getPrivateTitle( ) const override
;
127 OQueryContainerWindow
* getContainer() const { return static_cast< OQueryContainerWindow
* >( getView() ); }
130 OQueryController(const css::uno::Reference
< css::uno::XComponentContext
>& _rM
);
132 virtual ~OQueryController();
133 OTableFields
& getTableFieldDesc() { return m_vTableFieldDesc
; }
134 OTableFields
& getUnUsedFields() { return m_vUnUsedFieldsDesc
; }
138 virtual void impl_onModifyChanged() override
;
140 // should the statement be parsed by our own sql parser
141 bool isEscapeProcessing() const { return m_bEscapeProcessing
; }
142 bool isGraphicalDesign() const { return m_bGraphicalDesign
; }
143 bool isDistinct() const { return m_bDistinct
; }
144 sal_Int64
getLimit() const { return m_nLimit
; }
146 const OUString
& getStatement() const { return m_sStatement
; }
147 sal_Int32
getSplitPos() const { return m_nSplitPos
;}
148 sal_Int32
getVisibleRows() const { return m_nVisibleRows
; }
150 void setDistinct(bool _bDistinct
) { m_bDistinct
= _bDistinct
;}
151 void setLimit(const sal_Int64 _nLimit
) { m_nLimit
= _nLimit
;}
152 void setSplitPos(sal_Int32 _nSplitPos
) { m_nSplitPos
= _nSplitPos
;}
153 void setVisibleRows(sal_Int32 _nVisibleRows
) { m_nVisibleRows
= _nVisibleRows
;}
155 sal_Int32
getColWidth(sal_uInt16 _nColPos
) const;
157 const css::uno::Sequence
< css::beans::PropertyValue
>&
158 getFieldInformation() const { return m_aFieldInformation
; }
160 ::connectivity::OSQLParser
& getParser() { return m_aSqlParser
; }
161 ::connectivity::OSQLParseTreeIterator
& getParseIterator() { return *m_pSqlIterator
; }
163 virtual bool Construct(vcl::Window
* pParent
) override
;
165 DECLARE_XINTERFACE( )
166 DECLARE_XTYPEPROVIDER( )
168 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw(css::uno::RuntimeException
, std::exception
) override
;
169 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
172 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw(css::uno::RuntimeException
, std::exception
) override
;
174 // css::lang::XComponent
175 virtual void SAL_CALL
disposing() override
;
177 virtual OUString SAL_CALL
getImplementationName() throw(css::uno::RuntimeException
, std::exception
) override
;
178 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(css::uno::RuntimeException
, std::exception
) override
;
179 // need by registration
180 static OUString
getImplementationName_Static() throw( css::uno::RuntimeException
);
181 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static() throw( css::uno::RuntimeException
);
182 static css::uno::Reference
< css::uno::XInterface
>
183 SAL_CALL
Create(const css::uno::Reference
< css::lang::XMultiServiceFactory
>&);
186 virtual css::uno::Any SAL_CALL
getViewData() throw( css::uno::RuntimeException
, std::exception
) override
;
187 virtual void SAL_CALL
restoreViewData(const css::uno::Any
& Data
) throw( css::uno::RuntimeException
, std::exception
) override
;
190 virtual void onLoadedMenu(const css::uno::Reference
< css::frame::XLayoutManager
>& _xLayoutManager
) override
;
191 // OPropertyArrayUsageHelper
192 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const override
;
194 // OPropertySetHelper
195 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
196 css::uno::Any
& rConvertedValue
,
197 css::uno::Any
& rOldValue
,
199 const css::uno::Any
& rValue
200 ) throw (css::lang::IllegalArgumentException
) override
;
201 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
203 const css::uno::Any
& rValue
204 ) throw (css::uno::Exception
, std::exception
) override
;
205 virtual void SAL_CALL
getFastPropertyValue(
206 css::uno::Any
& rValue
,
210 virtual OJoinDesignView
* getJoinView() override
;
211 // ask the user if the design should be saved when it is modified
212 virtual short saveModified() override
;
213 virtual void reset() override
;
214 virtual void impl_initialize() override
;
216 void impl_reset( const bool i_bIgnoreQuerySettings
= false );
217 /// tells the user that we needed to switch to SQL view automatically
218 void impl_showAutoSQLViewError( const css::uno::Any
& _rErrorDetails
);
220 /** switches to the graphical or SQL view mode, as determined by m_bGraphicalDesign
222 void impl_setViewMode( ::dbtools::SQLExceptionInfo
* _pErrorInfo
);
224 /// sets m_sStatement, and notifies our respective property change listeners
225 void setStatement_fireEvent( const OUString
& _rNewStatement
, bool _bFireStatementChange
= true );
226 /// sets the m_bEscapeProcessing member, and notifies our respective property change listeners
227 void setEscapeProcessing_fireEvent( const bool _bEscapeProcessing
);
229 // OJoinController overridables
230 virtual bool allowViews() const override
;
231 virtual bool allowQueries() const override
;
234 DECL_LINK_TYPED( OnExecuteAddTable
, void*, void );
237 using OQueryController_PBase::getFastPropertyValue
;
240 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_QUERYCONTROLLER_HXX
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */