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 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> m_aFieldInformation
;
65 ::svxform::OSystemParseContext
* m_pParseContext
;
66 ::connectivity::OSQLParser m_aSqlParser
;
67 ::connectivity::OSQLParseTreeIterator
* m_pSqlIterator
;
69 ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XSQLQueryComposer
> m_xComposer
;
70 /// if we're editing an existing view, this is non-NULL
71 ::com::sun::star::uno::Reference
< ::com::sun::star::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_bViewAlias
; // show the alias row in the design view
88 bool m_bViewTable
; // show the table row in the design view
89 bool m_bViewFunction
; // show the function row in the design view
90 bool m_bEscapeProcessing
;// is true when we shouldn't parse the statement
93 /** returns the container of queries, views, or command definitions, depending on what object type
96 Not allowed to be called if we design an independent SQL command.
98 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>
99 getObjectContainer() const;
101 inline bool editingView() const { return m_nCommandType
== ::com::sun::star::sdb::CommandType::TABLE
; }
102 inline bool editingQuery() const { return m_nCommandType
== ::com::sun::star::sdb::CommandType::QUERY
; }
103 inline bool editingCommand() const { return m_nCommandType
== ::com::sun::star::sdb::CommandType::COMMAND
; }
105 bool askForNewName( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& _xElements
,
107 // creates the querycomposer
108 void setQueryComposer();
109 void deleteIterator();
111 bool doSaveAsDoc(bool _bSaveAs
);
113 void saveViewSettings( ::comphelper::NamedValueCollection
& o_rViewSettings
, const bool i_includingCriteria
) const;
114 void loadViewSettings( const ::comphelper::NamedValueCollection
& o_rViewSettings
);
115 OUString
translateStatement( bool _bFireStatementChange
= true );
117 OUString
getDefaultName() const;
119 void execute_QueryPropDlg();
122 // all the features which should be handled by this class
123 virtual void describeSupportedFeatures() SAL_OVERRIDE
;
124 // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
125 virtual FeatureState
GetState(sal_uInt16 nId
) const SAL_OVERRIDE
;
127 virtual void Execute(sal_uInt16 nId
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
) SAL_OVERRIDE
;
129 virtual void reconnect( bool _bUI
) SAL_OVERRIDE
;
130 virtual OUString
getPrivateTitle( ) const SAL_OVERRIDE
;
132 OQueryContainerWindow
* getContainer() const { return static_cast< OQueryContainerWindow
* >( getView() ); }
135 OQueryController(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rM
);
137 virtual ~OQueryController();
138 OTableFields
& getTableFieldDesc() { return m_vTableFieldDesc
; }
139 OTableFields
& getUnUsedFields() { return m_vUnUsedFieldsDesc
; }
143 virtual void impl_onModifyChanged() SAL_OVERRIDE
;
145 // should the statement be parsed by our own sql parser
146 bool isEscapeProcessing() const { return m_bEscapeProcessing
; }
147 bool isGraphicalDesign() const { return m_bGraphicalDesign
; }
148 bool isDistinct() const { return m_bDistinct
; }
149 sal_Int64
getLimit() const { return m_nLimit
; }
151 OUString
getStatement() const { return m_sStatement
; }
152 sal_Int32
getSplitPos() const { return m_nSplitPos
;}
153 sal_Int32
getVisibleRows() const { return m_nVisibleRows
; }
155 void setDistinct(bool _bDistinct
) { m_bDistinct
= _bDistinct
;}
156 void setLimit(const sal_Int64 _nLimit
) { m_nLimit
= _nLimit
;}
157 void setSplitPos(sal_Int32 _nSplitPos
) { m_nSplitPos
= _nSplitPos
;}
158 void setVisibleRows(sal_Int32 _nVisibleRows
) { m_nVisibleRows
= _nVisibleRows
;}
160 sal_Int32
getColWidth(sal_uInt16 _nColPos
) const;
162 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>&
163 getFieldInformation() const { return m_aFieldInformation
; }
165 ::connectivity::OSQLParser
& getParser() { return m_aSqlParser
; }
166 ::connectivity::OSQLParseTreeIterator
& getParseIterator() { return *m_pSqlIterator
; }
168 virtual bool Construct(vcl::Window
* pParent
) SAL_OVERRIDE
;
170 DECLARE_XINTERFACE( )
171 DECLARE_XTYPEPROVIDER( )
173 virtual com::sun::star::uno::Reference
<com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
174 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() SAL_OVERRIDE
;
177 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
179 // ::com::sun::star::lang::XComponent
180 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
182 virtual OUString SAL_CALL
getImplementationName() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
183 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
184 // need by registration
185 static OUString
getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException
);
186 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_Static() throw( ::com::sun::star::uno::RuntimeException
);
187 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
188 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
191 virtual ::com::sun::star::uno::Any SAL_CALL
getViewData() throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
192 virtual void SAL_CALL
restoreViewData(const ::com::sun::star::uno::Any
& Data
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
195 virtual void onLoadedMenu(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XLayoutManager
>& _xLayoutManager
) SAL_OVERRIDE
;
196 // OPropertyArrayUsageHelper
197 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const SAL_OVERRIDE
;
199 // OPropertySetHelper
200 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
201 ::com::sun::star::uno::Any
& rConvertedValue
,
202 ::com::sun::star::uno::Any
& rOldValue
,
204 const ::com::sun::star::uno::Any
& rValue
205 ) throw (::com::sun::star::lang::IllegalArgumentException
) SAL_OVERRIDE
;
206 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
208 const ::com::sun::star::uno::Any
& rValue
209 ) throw (::com::sun::star::uno::Exception
, std::exception
) SAL_OVERRIDE
;
210 virtual void SAL_CALL
getFastPropertyValue(
211 ::com::sun::star::uno::Any
& rValue
,
213 ) const SAL_OVERRIDE
;
215 virtual OJoinDesignView
* getJoinView() SAL_OVERRIDE
;
216 // ask the user if the design should be saved when it is modified
217 virtual short saveModified() SAL_OVERRIDE
;
218 virtual void reset() SAL_OVERRIDE
;
219 virtual void impl_initialize() SAL_OVERRIDE
;
221 void impl_reset( const bool i_bIgnoreQuerySettings
= false );
222 /// tells the user that we needed to switch to SQL view automatically
223 void impl_showAutoSQLViewError( const ::com::sun::star::uno::Any
& _rErrorDetails
);
225 /** switches to the graphical or SQL view mode, as determined by m_bGraphicalDesign
227 bool impl_setViewMode( ::dbtools::SQLExceptionInfo
* _pErrorInfo
);
229 /// sets m_sStatement, and notifies our respective property change listeners
230 void setStatement_fireEvent( const OUString
& _rNewStatement
, bool _bFireStatementChange
= true );
231 /// sets the m_bEscapeProcessing member, and notifies our respective property change listeners
232 void setEscapeProcessing_fireEvent( const bool _bEscapeProcessing
);
234 // OJoinController overridables
235 virtual bool allowViews() const SAL_OVERRIDE
;
236 virtual bool allowQueries() const SAL_OVERRIDE
;
239 DECL_LINK( OnExecuteAddTable
, void* );
242 using OQueryController_PBase::getFastPropertyValue
;
245 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_QUERYCONTROLLER_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */