xref: /AOO41X/main/dbaccess/source/ui/querydesign/querycontroller.cxx (revision 96de54900b79e13b861fbc62cbf36018b54e21b7)
1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "adtabdlg.hxx"
28cdf0e10cSrcweir #include "browserids.hxx"
29cdf0e10cSrcweir #include "dbu_qry.hrc"
30cdf0e10cSrcweir #include "dbu_reghelper.hxx"
31cdf0e10cSrcweir #include "dbustrings.hrc"
32cdf0e10cSrcweir #include "defaultobjectnamecheck.hxx"
33cdf0e10cSrcweir #include "dlgsave.hxx"
34cdf0e10cSrcweir #include "localresaccess.hxx"
35cdf0e10cSrcweir #include "QTableWindow.hxx"
36cdf0e10cSrcweir #include "QTableWindowData.hxx"
37cdf0e10cSrcweir #include "querycontainerwindow.hxx"
38cdf0e10cSrcweir #include "querycontroller.hxx"
39cdf0e10cSrcweir #include "QueryDesignView.hxx"
40cdf0e10cSrcweir #include "QueryTableView.hxx"
41cdf0e10cSrcweir #include "QueryTextView.hxx"
42cdf0e10cSrcweir #include "queryview.hxx"
43cdf0e10cSrcweir #include "QueryViewSwitch.hxx"
44cdf0e10cSrcweir #include "sqlmessage.hxx"
45cdf0e10cSrcweir #include "TableConnectionData.hxx"
46cdf0e10cSrcweir #include "TableFieldDescription.hxx"
47cdf0e10cSrcweir #include "UITools.hxx"
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /** === begin UNO includes === **/
50cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
51cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
52cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
53cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
54cdf0e10cSrcweir #include <com/sun/star/frame/XLoadEventListener.hpp>
55cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
56cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
57cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
58cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
59cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
60cdf0e10cSrcweir #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
61cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
62cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
63cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
64cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
65cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
66cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDrop.hpp>
67cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
68cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
69cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
70cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
71cdf0e10cSrcweir #include <com/sun/star/util/VetoException.hpp>
72cdf0e10cSrcweir #include <com/sun/star/frame/XUntitledNumbers.hpp>
73cdf0e10cSrcweir /** === end UNO includes === **/
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #include <comphelper/basicio.hxx>
76cdf0e10cSrcweir #include <comphelper/extract.hxx>
77cdf0e10cSrcweir #include <comphelper/property.hxx>
78cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
79cdf0e10cSrcweir #include <comphelper/streamsection.hxx>
80cdf0e10cSrcweir #include <comphelper/types.hxx>
81cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
82cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
83cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
84cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
85cdf0e10cSrcweir #include <svtools/localresaccess.hxx>
86cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
87cdf0e10cSrcweir #include <tools/diagnose_ex.h>
88cdf0e10cSrcweir #include <vcl/msgbox.hxx>
89cdf0e10cSrcweir #include <vcl/svapp.hxx>
90cdf0e10cSrcweir #include <vos/mutex.hxx>
91cdf0e10cSrcweir 
92cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OQueryControl()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OQueryController > aAutoRegistration;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir namespace dbaui
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
99cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
100cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
101cdf0e10cSrcweir     using namespace ::com::sun::star::util;
102cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     class OViewController : public OQueryController
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         //------------------------------------------------------------------------------
107cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( RuntimeException )
108cdf0e10cSrcweir         {
109cdf0e10cSrcweir 	        return getImplementationName_Static();
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir         //-------------------------------------------------------------------------
112cdf0e10cSrcweir         virtual Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(RuntimeException)
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir 	        return getSupportedServiceNames_Static();
115cdf0e10cSrcweir         }
116cdf0e10cSrcweir     public:
117cdf0e10cSrcweir         OViewController(const Reference< XMultiServiceFactory >& _rM) : OQueryController(_rM){}
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         // need by registration
120cdf0e10cSrcweir 	    static ::rtl::OUString getImplementationName_Static() throw( RuntimeException )
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir 	        return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.OViewDesign");
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir 	    static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( RuntimeException )
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             Sequence< ::rtl::OUString> aSupported(1);
127cdf0e10cSrcweir 	        aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ViewDesign");
128cdf0e10cSrcweir 	        return aSupported;
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir 	    static Reference< XInterface > SAL_CALL Create(const Reference< XMultiServiceFactory >& _rM)
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             return *(new OViewController(_rM));
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir     };
135cdf0e10cSrcweir }
136cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OViewControl()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OViewController > aAutoRegistration;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir namespace dbaui
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	using namespace ::connectivity;
144cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
145cdf0e10cSrcweir 	namespace
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		// -----------------------------------------------------------------------------
148cdf0e10cSrcweir 		void insertParseTree(SvTreeListBox* _pBox,::connectivity::OSQLParseNode* _pNode,SvLBoxEntry* _pParent = NULL)
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			::rtl::OUString rString;
151cdf0e10cSrcweir 			if (!_pNode->isToken())
152cdf0e10cSrcweir 			{
153cdf0e10cSrcweir 				// Regelnamen als rule: ...
154cdf0e10cSrcweir 				rString = ::rtl::OUString::createFromAscii("RULE_ID: ");
155cdf0e10cSrcweir 				rString += ::rtl::OUString::valueOf( (sal_Int32)_pNode->getRuleID());
156cdf0e10cSrcweir 				rString+= ::rtl::OUString::createFromAscii("(");
157cdf0e10cSrcweir 				rString += OSQLParser::RuleIDToStr(_pNode->getRuleID());
158cdf0e10cSrcweir 				rString+= ::rtl::OUString::createFromAscii(")");
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 				_pParent = _pBox->InsertEntry(rString,_pParent);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 				// einmal auswerten wieviel Subtrees dieser Knoten besitzt
164cdf0e10cSrcweir 				sal_uInt32 nStop = _pNode->count();
165cdf0e10cSrcweir 				// hol dir den ersten Subtree
166cdf0e10cSrcweir 				for(sal_uInt32 i=0;i<nStop;++i)
167cdf0e10cSrcweir 					insertParseTree(_pBox,_pNode->getChild(i),_pParent);
168cdf0e10cSrcweir 			}
169cdf0e10cSrcweir 			else
170cdf0e10cSrcweir 			{
171cdf0e10cSrcweir 				// ein Token gefunden
172cdf0e10cSrcweir 				// tabs fuer das Einruecken entsprechend nLevel
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 				switch (_pNode->getNodeType())
175cdf0e10cSrcweir 				{
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 				case SQL_NODE_KEYWORD:
178cdf0e10cSrcweir 					{
179cdf0e10cSrcweir 						rString+= ::rtl::OUString::createFromAscii("SQL_KEYWORD:");
180cdf0e10cSrcweir 						::rtl::OString sT = OSQLParser::TokenIDToStr(_pNode->getTokenID());
181cdf0e10cSrcweir 						rString += ::rtl::OUString(sT,sT.getLength(),RTL_TEXTENCODING_UTF8);
182cdf0e10cSrcweir 					 break;}
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 				case SQL_NODE_COMPARISON:
185cdf0e10cSrcweir 					{rString+= ::rtl::OUString::createFromAscii("SQL_COMPARISON:");
186cdf0e10cSrcweir 					rString += _pNode->getTokenValue();	// haenge Nodevalue an
187cdf0e10cSrcweir 							// und beginne neu Zeile
188cdf0e10cSrcweir 					break;}
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 				case SQL_NODE_NAME:
191cdf0e10cSrcweir 					{rString+= ::rtl::OUString::createFromAscii("SQL_NAME:");
192cdf0e10cSrcweir 					 rString+= ::rtl::OUString::createFromAscii("\"");
193cdf0e10cSrcweir 					 rString += _pNode->getTokenValue();
194cdf0e10cSrcweir 					 rString+= ::rtl::OUString::createFromAscii("\"");
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 					 break;}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 				case SQL_NODE_STRING:
199cdf0e10cSrcweir 					{rString += ::rtl::OUString::createFromAscii("SQL_STRING:'");
200cdf0e10cSrcweir 					 rString += _pNode->getTokenValue();
201cdf0e10cSrcweir 					 break;}
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 				case SQL_NODE_INTNUM:
204cdf0e10cSrcweir 					{rString += ::rtl::OUString::createFromAscii("SQL_INTNUM:");
205cdf0e10cSrcweir 					 rString += _pNode->getTokenValue();
206cdf0e10cSrcweir 					 break;}
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 				case SQL_NODE_APPROXNUM:
209cdf0e10cSrcweir 					{rString += ::rtl::OUString::createFromAscii("SQL_APPROXNUM:");
210cdf0e10cSrcweir 					 rString += _pNode->getTokenValue();
211cdf0e10cSrcweir 					 break;}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 				case SQL_NODE_PUNCTUATION:
214cdf0e10cSrcweir 					{rString += ::rtl::OUString::createFromAscii("SQL_PUNCTUATION:");
215cdf0e10cSrcweir 					rString += _pNode->getTokenValue();	// haenge Nodevalue an
216cdf0e10cSrcweir 					break;}
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 				case SQL_NODE_AMMSC:
219cdf0e10cSrcweir 					{rString += ::rtl::OUString::createFromAscii("SQL_AMMSC:");
220cdf0e10cSrcweir 					rString += _pNode->getTokenValue();	// haenge Nodevalue an
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 					break;}
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 				default:
225cdf0e10cSrcweir 					OSL_ASSERT("OSQLParser::ShowParseTree: unzulaessiger NodeType");
226cdf0e10cSrcweir 					rString += _pNode->getTokenValue();
227cdf0e10cSrcweir 				}
228cdf0e10cSrcweir 				_pBox->InsertEntry(rString,_pParent);
229cdf0e10cSrcweir 			}
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 	}
232cdf0e10cSrcweir #endif // OSL_DEBUG_LEVEL
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     namespace
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir 		// -----------------------------------------------------------------------------
237cdf0e10cSrcweir         String lcl_getObjectResourceString( sal_uInt16 _nResId, sal_Int32 _nCommandType )
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir             String sMessageText = String( ModuleRes( _nResId ) );
240cdf0e10cSrcweir             String sObjectType;
241cdf0e10cSrcweir             {
242cdf0e10cSrcweir                 LocalResourceAccess aLocalRes( RSC_QUERY_OBJECT_TYPE, RSC_RESOURCE );
243cdf0e10cSrcweir                 sObjectType = String( ModuleRes( (sal_uInt16)( _nCommandType + 1 ) ) );
244cdf0e10cSrcweir             }
245cdf0e10cSrcweir             sMessageText.SearchAndReplace( String::CreateFromAscii( "$object$" ), sObjectType );
246cdf0e10cSrcweir             return sMessageText;
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir using namespace ::com::sun::star::uno;
251cdf0e10cSrcweir using namespace ::com::sun::star::io;
252cdf0e10cSrcweir using namespace ::com::sun::star::beans;
253cdf0e10cSrcweir using namespace ::com::sun::star::frame;
254cdf0e10cSrcweir using namespace ::com::sun::star::util;
255cdf0e10cSrcweir using namespace ::com::sun::star::lang;
256cdf0e10cSrcweir using namespace ::com::sun::star::container;
257cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
258cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
259cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
260cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
261cdf0e10cSrcweir using namespace ::com::sun::star::awt;
262cdf0e10cSrcweir using namespace ::dbtools;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir using namespace ::comphelper;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir namespace
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	void ensureToolbars( OQueryController& _rController, sal_Bool _bDesign )
269cdf0e10cSrcweir     {
270cdf0e10cSrcweir         Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager = _rController.getLayoutManager( _rController.getFrame() );
271cdf0e10cSrcweir 		if ( xLayoutManager.is() )
272cdf0e10cSrcweir 		{
273cdf0e10cSrcweir 			xLayoutManager->lock();
274cdf0e10cSrcweir 			static ::rtl::OUString s_sDesignToolbar(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/designobjectbar"));
275cdf0e10cSrcweir 			static ::rtl::OUString s_sSqlToolbar(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/sqlobjectbar"));
276cdf0e10cSrcweir 			if ( _bDesign )
277cdf0e10cSrcweir 			{
278cdf0e10cSrcweir 				xLayoutManager->destroyElement( s_sSqlToolbar );
279cdf0e10cSrcweir 				xLayoutManager->createElement( s_sDesignToolbar );
280cdf0e10cSrcweir 			}
281cdf0e10cSrcweir 			else
282cdf0e10cSrcweir 			{
283cdf0e10cSrcweir 				xLayoutManager->destroyElement( s_sDesignToolbar );
284cdf0e10cSrcweir 				xLayoutManager->createElement( s_sSqlToolbar );
285cdf0e10cSrcweir 			}
286cdf0e10cSrcweir 			xLayoutManager->unlock();
287cdf0e10cSrcweir             xLayoutManager->doLayout();
288cdf0e10cSrcweir 		}
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir //------------------------------------------------------------------------------
293cdf0e10cSrcweir ::rtl::OUString SAL_CALL OQueryController::getImplementationName() throw( RuntimeException )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	return getImplementationName_Static();
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir //------------------------------------------------------------------------------
299cdf0e10cSrcweir ::rtl::OUString OQueryController::getImplementationName_Static() throw( RuntimeException )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.OQueryDesign");
302cdf0e10cSrcweir }
303cdf0e10cSrcweir //------------------------------------------------------------------------------
304cdf0e10cSrcweir Sequence< ::rtl::OUString> OQueryController::getSupportedServiceNames_Static(void) throw( RuntimeException )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir 	Sequence< ::rtl::OUString> aSupported(1);
307cdf0e10cSrcweir 	aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.QueryDesign");
308cdf0e10cSrcweir 	return aSupported;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir //-------------------------------------------------------------------------
311cdf0e10cSrcweir Sequence< ::rtl::OUString> SAL_CALL OQueryController::getSupportedServiceNames() throw(RuntimeException)
312cdf0e10cSrcweir {
313cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
314cdf0e10cSrcweir }
315cdf0e10cSrcweir // -------------------------------------------------------------------------
316cdf0e10cSrcweir Reference< XInterface > SAL_CALL OQueryController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
317cdf0e10cSrcweir {
318cdf0e10cSrcweir 	return *(new OQueryController(_rxFactory));
319cdf0e10cSrcweir }
320cdf0e10cSrcweir DBG_NAME(OQueryController);
321cdf0e10cSrcweir // -----------------------------------------------------------------------------
322cdf0e10cSrcweir OQueryController::OQueryController(const Reference< XMultiServiceFactory >& _rM)
323cdf0e10cSrcweir     :OJoinController(_rM)
324cdf0e10cSrcweir     ,OQueryController_PBase( getBroadcastHelper() )
325cdf0e10cSrcweir     ,m_pParseContext( new svxform::OSystemParseContext )
326cdf0e10cSrcweir     ,m_aSqlParser( _rM, m_pParseContext )
327cdf0e10cSrcweir 	,m_pSqlIterator(NULL)
328cdf0e10cSrcweir 	,m_nVisibleRows(0x400)
329cdf0e10cSrcweir 	,m_nSplitPos(-1)
330cdf0e10cSrcweir     ,m_nCommandType( CommandType::QUERY )
331cdf0e10cSrcweir     ,m_bGraphicalDesign(sal_False)
332cdf0e10cSrcweir 	,m_bDistinct(sal_False)
333cdf0e10cSrcweir 	,m_bViewAlias(sal_False)
334cdf0e10cSrcweir     ,m_bViewTable(sal_False)
335cdf0e10cSrcweir 	,m_bViewFunction(sal_False)
336cdf0e10cSrcweir 	,m_bEscapeProcessing(sal_True)
337cdf0e10cSrcweir {
338cdf0e10cSrcweir 	DBG_CTOR(OQueryController,NULL);
339cdf0e10cSrcweir 	InvalidateAll();
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	registerProperty( PROPERTY_ACTIVECOMMAND, PROPERTY_ID_ACTIVECOMMAND, PropertyAttribute::READONLY | PropertyAttribute::BOUND,
342cdf0e10cSrcweir 		&m_sStatement, ::getCppuType( &m_sStatement ) );
343cdf0e10cSrcweir 	registerProperty( PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::READONLY | PropertyAttribute::BOUND,
344cdf0e10cSrcweir 		&m_bEscapeProcessing, ::getCppuType( &m_bEscapeProcessing ) );
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir // -----------------------------------------------------------------------------
348cdf0e10cSrcweir OQueryController::~OQueryController()
349cdf0e10cSrcweir {
350cdf0e10cSrcweir 	DBG_DTOR(OQueryController,NULL);
351cdf0e10cSrcweir 	if ( !getBroadcastHelper().bDisposed && !getBroadcastHelper().bInDispose )
352cdf0e10cSrcweir 	{
353cdf0e10cSrcweir 		OSL_ENSURE(0,"Please check who doesn't dispose this component!");
354cdf0e10cSrcweir         // increment ref count to prevent double call of Dtor
355cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
356cdf0e10cSrcweir         dispose();
357cdf0e10cSrcweir 	}
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( OQueryController, OJoinController, OQueryController_PBase )
361cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( OQueryController, OJoinController, OQueryController_PBase )
362cdf0e10cSrcweir 
363cdf0e10cSrcweir //-------------------------------------------------------------------------
364cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL OQueryController::getPropertySetInfo() throw(RuntimeException)
365cdf0e10cSrcweir {
366cdf0e10cSrcweir 	Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
367cdf0e10cSrcweir 	return xInfo;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir //-------------------------------------------------------------------------
371cdf0e10cSrcweir sal_Bool SAL_CALL OQueryController::convertFastPropertyValue( Any& o_rConvertedValue, Any& o_rOldValue, sal_Int32 i_nHandle, const Any& i_rValue ) throw (IllegalArgumentException)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir     return OPropertyContainer::convertFastPropertyValue( o_rConvertedValue, o_rOldValue, i_nHandle, i_rValue );
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir //-------------------------------------------------------------------------
377cdf0e10cSrcweir void SAL_CALL OQueryController::setFastPropertyValue_NoBroadcast( sal_Int32 i_nHandle, const Any& i_rValue ) throw ( Exception )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     OPropertyContainer::setFastPropertyValue_NoBroadcast( i_nHandle, i_rValue );
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir //-------------------------------------------------------------------------
383cdf0e10cSrcweir void SAL_CALL OQueryController::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     switch ( i_nHandle )
386cdf0e10cSrcweir     {
387cdf0e10cSrcweir     case PROPERTY_ID_CURRENT_QUERY_DESIGN:
388cdf0e10cSrcweir     {
389cdf0e10cSrcweir         ::comphelper::NamedValueCollection aCurrentDesign;
390cdf0e10cSrcweir         aCurrentDesign.put( "GraphicalDesign", isGraphicalDesign() );
391cdf0e10cSrcweir         aCurrentDesign.put( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, m_bEscapeProcessing );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir         if ( isGraphicalDesign() )
394cdf0e10cSrcweir         {
395cdf0e10cSrcweir             getContainer()->SaveUIConfig();
396cdf0e10cSrcweir 	        saveViewSettings( aCurrentDesign, true );
397cdf0e10cSrcweir             aCurrentDesign.put( "Statement", m_sStatement );
398cdf0e10cSrcweir         }
399cdf0e10cSrcweir         else
400cdf0e10cSrcweir         {
401cdf0e10cSrcweir             aCurrentDesign.put( "Statement", getContainer()->getStatement() );
402cdf0e10cSrcweir         }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir         o_rValue <<= aCurrentDesign.getPropertyValues();
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir     break;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     default:
409cdf0e10cSrcweir         OPropertyContainer::getFastPropertyValue( o_rValue, i_nHandle );
410cdf0e10cSrcweir         break;
411cdf0e10cSrcweir     }
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir //-------------------------------------------------------------------------
415cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& OQueryController::getInfoHelper()
416cdf0e10cSrcweir {
417cdf0e10cSrcweir 	return *const_cast< OQueryController* >( this )->getArrayHelper();
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir //--------------------------------------------------------------------
421cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OQueryController::createArrayHelper( ) const
422cdf0e10cSrcweir {
423cdf0e10cSrcweir 	Sequence< Property > aProps;
424cdf0e10cSrcweir 	describeProperties( aProps );
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     // one additional property:
427cdf0e10cSrcweir     const sal_Int32 nLength = aProps.getLength();
428cdf0e10cSrcweir     aProps.realloc( nLength + 1 );
429cdf0e10cSrcweir     aProps[ nLength ] = Property(
430cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ),
431cdf0e10cSrcweir         PROPERTY_ID_CURRENT_QUERY_DESIGN,
432cdf0e10cSrcweir         ::cppu::UnoType< Sequence< PropertyValue > >::get(),
433cdf0e10cSrcweir         PropertyAttribute::READONLY
434cdf0e10cSrcweir     );
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     ::std::sort(
437cdf0e10cSrcweir         aProps.getArray(),
438cdf0e10cSrcweir         aProps.getArray() + aProps.getLength(),
439cdf0e10cSrcweir         ::comphelper::PropertyCompareByName()
440cdf0e10cSrcweir     );
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 	return new ::cppu::OPropertyArrayHelper(aProps);
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir // -----------------------------------------------------------------------------
446cdf0e10cSrcweir void OQueryController::deleteIterator()
447cdf0e10cSrcweir {
448cdf0e10cSrcweir 	if(m_pSqlIterator)
449cdf0e10cSrcweir 	{
450cdf0e10cSrcweir 		delete m_pSqlIterator->getParseTree();
451cdf0e10cSrcweir 		m_pSqlIterator->dispose();
452cdf0e10cSrcweir 		delete m_pSqlIterator;
453cdf0e10cSrcweir 		m_pSqlIterator = NULL;
454cdf0e10cSrcweir 	}
455cdf0e10cSrcweir }
456cdf0e10cSrcweir // -----------------------------------------------------------------------------
457cdf0e10cSrcweir void OQueryController::disposing()
458cdf0e10cSrcweir {
459cdf0e10cSrcweir     OQueryController_PBase::disposing();
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 	deleteIterator();
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	delete m_pParseContext;
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	clearFields();
466cdf0e10cSrcweir 	OTableFields().swap(m_vUnUsedFieldsDesc);
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	::comphelper::disposeComponent(m_xComposer);
469cdf0e10cSrcweir 	OJoinController::disposing();
470cdf0e10cSrcweir     OQueryController_PBase::disposing();
471cdf0e10cSrcweir }
472cdf0e10cSrcweir // -----------------------------------------------------------------------------
473cdf0e10cSrcweir void OQueryController::clearFields()
474cdf0e10cSrcweir {
475cdf0e10cSrcweir 	OTableFields().swap(m_vTableFieldDesc);
476cdf0e10cSrcweir }
477cdf0e10cSrcweir // -----------------------------------------------------------------------------
478cdf0e10cSrcweir FeatureState OQueryController::GetState(sal_uInt16 _nId) const
479cdf0e10cSrcweir {
480cdf0e10cSrcweir 	FeatureState aReturn;
481cdf0e10cSrcweir 	aReturn.bEnabled = sal_True;
482cdf0e10cSrcweir 		// (disabled automatically)
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 	switch (_nId)
485cdf0e10cSrcweir 	{
486cdf0e10cSrcweir         case ID_BROWSER_EDITDOC:
487cdf0e10cSrcweir             if ( editingCommand() )
488cdf0e10cSrcweir                 aReturn.bEnabled = sal_False;
489cdf0e10cSrcweir             else if ( editingView() && !m_xAlterView.is() )
490cdf0e10cSrcweir                 aReturn.bEnabled = sal_False;
491cdf0e10cSrcweir             else
492cdf0e10cSrcweir                 aReturn = OJoinController::GetState( _nId );
493cdf0e10cSrcweir             break;
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 		case ID_BROWSER_ESACPEPROCESSING:
496cdf0e10cSrcweir 			aReturn.bChecked = !m_bEscapeProcessing;
497cdf0e10cSrcweir 			aReturn.bEnabled = ( m_pSqlIterator != NULL ) && !m_bGraphicalDesign;
498cdf0e10cSrcweir 			break;
499cdf0e10cSrcweir 		case SID_RELATION_ADD_RELATION:
500cdf0e10cSrcweir 			aReturn.bEnabled = isEditable() && m_bGraphicalDesign && m_vTableData.size() > 1;
501cdf0e10cSrcweir 			break;
502cdf0e10cSrcweir 		case ID_BROWSER_SAVEASDOC:
503cdf0e10cSrcweir 			aReturn.bEnabled = !editingCommand() && !editingView() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty()));
504cdf0e10cSrcweir 			break;
505cdf0e10cSrcweir 		case ID_BROWSER_SAVEDOC:
506cdf0e10cSrcweir 			aReturn.bEnabled = impl_isModified() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty()));
507cdf0e10cSrcweir 			break;
508cdf0e10cSrcweir 		case SID_PRINTDOCDIRECT:
509cdf0e10cSrcweir 			break;
510cdf0e10cSrcweir 		case ID_BROWSER_CUT:
511cdf0e10cSrcweir 			aReturn.bEnabled = isEditable() && getContainer() && getContainer()->isCutAllowed();
512cdf0e10cSrcweir 			break;
513cdf0e10cSrcweir 		case ID_BROWSER_COPY:
514cdf0e10cSrcweir 			aReturn.bEnabled = getContainer() && getContainer()->isCopyAllowed();
515cdf0e10cSrcweir 			break;
516cdf0e10cSrcweir 		case ID_BROWSER_PASTE:
517cdf0e10cSrcweir 			aReturn.bEnabled = isEditable() && getContainer() && getContainer()->isPasteAllowed();
518cdf0e10cSrcweir 			break;
519cdf0e10cSrcweir 		case ID_BROWSER_SQL:
520cdf0e10cSrcweir 			aReturn.bEnabled = m_bEscapeProcessing && m_pSqlIterator;
521cdf0e10cSrcweir 			aReturn.bChecked = m_bGraphicalDesign;
522cdf0e10cSrcweir 			break;
523cdf0e10cSrcweir 		case SID_BROWSER_CLEAR_QUERY:
524cdf0e10cSrcweir 			aReturn.bEnabled = isEditable() && (m_sStatement.getLength() || !m_vTableData.empty());
525cdf0e10cSrcweir 			break;
526cdf0e10cSrcweir 		case SID_QUERY_VIEW_FUNCTIONS:
527cdf0e10cSrcweir 		case SID_QUERY_VIEW_TABLES:
528cdf0e10cSrcweir 		case SID_QUERY_VIEW_ALIASES:
529cdf0e10cSrcweir 			aReturn.bChecked = getContainer() && getContainer()->isSlotEnabled(_nId);
530cdf0e10cSrcweir 			aReturn.bEnabled = m_bGraphicalDesign;
531cdf0e10cSrcweir 			break;
532cdf0e10cSrcweir 		case SID_QUERY_DISTINCT_VALUES:
533cdf0e10cSrcweir 			aReturn.bEnabled = m_bGraphicalDesign && isEditable();
534cdf0e10cSrcweir 			aReturn.bChecked = m_bDistinct;
535cdf0e10cSrcweir 			break;
536cdf0e10cSrcweir 		case ID_BROWSER_QUERY_EXECUTE:
537cdf0e10cSrcweir 			aReturn.bEnabled = sal_True;
538cdf0e10cSrcweir 			break;
539cdf0e10cSrcweir 		case SID_DB_QUERY_PREVIEW:
540cdf0e10cSrcweir 			aReturn.bEnabled = sal_True;
541cdf0e10cSrcweir 			aReturn.bChecked = getContainer() && getContainer()->getPreviewFrame().is();
542cdf0e10cSrcweir 			break;
543cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
544cdf0e10cSrcweir 		case ID_EDIT_QUERY_SQL:
545cdf0e10cSrcweir 			break;
546cdf0e10cSrcweir 		case ID_EDIT_QUERY_DESIGN:
547cdf0e10cSrcweir 			break;
548cdf0e10cSrcweir #endif
549cdf0e10cSrcweir 		case ID_BROWSER_ADDTABLE:
550cdf0e10cSrcweir 			if ( !m_bGraphicalDesign )
551cdf0e10cSrcweir 			{
552cdf0e10cSrcweir 				aReturn.bEnabled = sal_False;
553cdf0e10cSrcweir 				break;
554cdf0e10cSrcweir 			}
555cdf0e10cSrcweir 			// run through
556cdf0e10cSrcweir 		default:
557cdf0e10cSrcweir 			aReturn = OJoinController::GetState(_nId);
558cdf0e10cSrcweir 			break;
559cdf0e10cSrcweir 	}
560cdf0e10cSrcweir 	return aReturn;
561cdf0e10cSrcweir }
562cdf0e10cSrcweir // -----------------------------------------------------------------------------
563cdf0e10cSrcweir void OQueryController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
564cdf0e10cSrcweir {
565cdf0e10cSrcweir 	switch(_nId)
566cdf0e10cSrcweir 	{
567cdf0e10cSrcweir 		case ID_BROWSER_ESACPEPROCESSING:
568cdf0e10cSrcweir             setEscapeProcessing_fireEvent( !m_bEscapeProcessing );
569cdf0e10cSrcweir             if ( !editingView() )
570cdf0e10cSrcweir 			    setModified(sal_True);
571cdf0e10cSrcweir 			InvalidateFeature(ID_BROWSER_SQL);
572cdf0e10cSrcweir 			break;
573cdf0e10cSrcweir 		case ID_BROWSER_SAVEASDOC:
574cdf0e10cSrcweir 		case ID_BROWSER_SAVEDOC:
575cdf0e10cSrcweir 			doSaveAsDoc(ID_BROWSER_SAVEASDOC == _nId);
576cdf0e10cSrcweir 			break;
577cdf0e10cSrcweir 		case SID_RELATION_ADD_RELATION:
578cdf0e10cSrcweir 			{
579cdf0e10cSrcweir 				OJoinDesignView* pView = getJoinView();
580cdf0e10cSrcweir 				if( pView )
581cdf0e10cSrcweir 					static_cast<OQueryTableView*>(pView->getTableView())->createNewConnection();
582cdf0e10cSrcweir 			}
583cdf0e10cSrcweir 			break;
584cdf0e10cSrcweir 		case SID_PRINTDOCDIRECT:
585cdf0e10cSrcweir 			break;
586cdf0e10cSrcweir 		case ID_BROWSER_CUT:
587cdf0e10cSrcweir 			getContainer()->cut();
588cdf0e10cSrcweir 			break;
589cdf0e10cSrcweir 		case ID_BROWSER_COPY:
590cdf0e10cSrcweir 			getContainer()->copy();
591cdf0e10cSrcweir 			break;
592cdf0e10cSrcweir 		case ID_BROWSER_PASTE:
593cdf0e10cSrcweir 			getContainer()->paste();
594cdf0e10cSrcweir 			break;
595cdf0e10cSrcweir 		case ID_BROWSER_SQL:
596cdf0e10cSrcweir         {
597cdf0e10cSrcweir 			if ( !getContainer()->checkStatement() )
598cdf0e10cSrcweir                 break;
599cdf0e10cSrcweir             SQLExceptionInfo aError;
600cdf0e10cSrcweir 			try
601cdf0e10cSrcweir 			{
602cdf0e10cSrcweir                 ::rtl::OUString aErrorMsg;
603cdf0e10cSrcweir                 setStatement_fireEvent( getContainer()->getStatement() );
604cdf0e10cSrcweir 				if(!m_sStatement.getLength() && m_pSqlIterator)
605cdf0e10cSrcweir 				{
606cdf0e10cSrcweir 					// change the view of the data
607cdf0e10cSrcweir 					delete m_pSqlIterator->getParseTree();
608cdf0e10cSrcweir 					m_pSqlIterator->setParseTree(NULL);
609cdf0e10cSrcweir 					m_bGraphicalDesign = !m_bGraphicalDesign;
610cdf0e10cSrcweir 					impl_setViewMode( &aError );
611cdf0e10cSrcweir 				}
612cdf0e10cSrcweir 				else
613cdf0e10cSrcweir 				{
614cdf0e10cSrcweir                     ::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree(aErrorMsg,m_sStatement,m_bGraphicalDesign);
615cdf0e10cSrcweir 					if ( pNode )
616cdf0e10cSrcweir 					{
617cdf0e10cSrcweir 						delete m_pSqlIterator->getParseTree();
618cdf0e10cSrcweir 						m_pSqlIterator->setParseTree(pNode);
619cdf0e10cSrcweir 						m_pSqlIterator->traverseAll();
620cdf0e10cSrcweir 
621cdf0e10cSrcweir                         if ( m_pSqlIterator->hasErrors() )
622cdf0e10cSrcweir                         {
623cdf0e10cSrcweir                             aError = m_pSqlIterator->getErrors();
624cdf0e10cSrcweir                         }
625cdf0e10cSrcweir 						else
626cdf0e10cSrcweir 						{
627cdf0e10cSrcweir 							const OSQLTables& xTabs = m_pSqlIterator->getTables();
628cdf0e10cSrcweir 							if ( m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT || xTabs.begin() == xTabs.end() )
629cdf0e10cSrcweir 							{
630cdf0e10cSrcweir                                 aError = SQLException(
631cdf0e10cSrcweir                                     String( ModuleRes( STR_QRY_NOSELECT ) ),
632cdf0e10cSrcweir                                     NULL,
633cdf0e10cSrcweir                                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ),
634cdf0e10cSrcweir                                     1000,
635cdf0e10cSrcweir                                     Any()
636cdf0e10cSrcweir                                 );
637cdf0e10cSrcweir 							}
638cdf0e10cSrcweir 							else
639cdf0e10cSrcweir 							{
640cdf0e10cSrcweir 								// change the view of the data
641cdf0e10cSrcweir 								m_bGraphicalDesign = !m_bGraphicalDesign;
642cdf0e10cSrcweir                                 ::rtl::OUString sNewStatement;
643cdf0e10cSrcweir 								pNode->parseNodeToStr( sNewStatement, getConnection() );
644cdf0e10cSrcweir                                 setStatement_fireEvent( sNewStatement );
645cdf0e10cSrcweir 								getContainer()->SaveUIConfig();
646cdf0e10cSrcweir                                 m_vTableConnectionData.clear();
647cdf0e10cSrcweir 								impl_setViewMode( &aError );
648cdf0e10cSrcweir 							}
649cdf0e10cSrcweir 						}
650cdf0e10cSrcweir 					}
651cdf0e10cSrcweir 					else
652cdf0e10cSrcweir 					{
653cdf0e10cSrcweir                         aError = SQLException(
654cdf0e10cSrcweir                             String( ModuleRes( STR_QRY_SYNTAX ) ),
655cdf0e10cSrcweir                             NULL,
656cdf0e10cSrcweir                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ),
657cdf0e10cSrcweir                             1000,
658cdf0e10cSrcweir                             Any()
659cdf0e10cSrcweir                         );
660cdf0e10cSrcweir 					}
661cdf0e10cSrcweir 				}
662cdf0e10cSrcweir 			}
663cdf0e10cSrcweir 			catch(const SQLException& e)
664cdf0e10cSrcweir 			{
665cdf0e10cSrcweir                 aError = ::cppu::getCaughtException();
666cdf0e10cSrcweir 			}
667cdf0e10cSrcweir 			catch(const Exception&)
668cdf0e10cSrcweir 			{
669cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
670cdf0e10cSrcweir 			}
671cdf0e10cSrcweir 
672cdf0e10cSrcweir             if ( aError.isValid() )
673cdf0e10cSrcweir                 showError( aError );
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 			if(m_bGraphicalDesign)
676cdf0e10cSrcweir 			{
677cdf0e10cSrcweir 				InvalidateFeature(ID_BROWSER_ADDTABLE);
678cdf0e10cSrcweir 				InvalidateFeature(SID_RELATION_ADD_RELATION);
679cdf0e10cSrcweir 			}
680cdf0e10cSrcweir         }
681cdf0e10cSrcweir         break;
682cdf0e10cSrcweir 		case SID_BROWSER_CLEAR_QUERY:
683cdf0e10cSrcweir 			{
684cdf0e10cSrcweir 				GetUndoManager().EnterListAction( String( ModuleRes(STR_QUERY_UNDO_TABWINDELETE) ), String() );
685cdf0e10cSrcweir 				getContainer()->clear();
686cdf0e10cSrcweir 				GetUndoManager().LeaveListAction();
687cdf0e10cSrcweir 
688cdf0e10cSrcweir                 setStatement_fireEvent( ::rtl::OUString() );
689cdf0e10cSrcweir 				if(m_bGraphicalDesign)
690cdf0e10cSrcweir 					InvalidateFeature(ID_BROWSER_ADDTABLE);
691cdf0e10cSrcweir 			}
692cdf0e10cSrcweir 			//	InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
693cdf0e10cSrcweir 			break;
694cdf0e10cSrcweir 		case SID_QUERY_VIEW_FUNCTIONS:
695cdf0e10cSrcweir 		case SID_QUERY_VIEW_TABLES:
696cdf0e10cSrcweir 		case SID_QUERY_VIEW_ALIASES:
697cdf0e10cSrcweir 			getContainer()->setSlotEnabled(_nId,!getContainer()->isSlotEnabled(_nId));
698cdf0e10cSrcweir 			setModified(sal_True);
699cdf0e10cSrcweir 			break;
700cdf0e10cSrcweir 		case SID_QUERY_DISTINCT_VALUES:
701cdf0e10cSrcweir 			m_bDistinct = !m_bDistinct;
702cdf0e10cSrcweir 			setModified(sal_True);
703cdf0e10cSrcweir 			break;
704cdf0e10cSrcweir 		case ID_BROWSER_QUERY_EXECUTE:
705cdf0e10cSrcweir 			if ( getContainer()->checkStatement() )
706cdf0e10cSrcweir 				executeQuery();
707cdf0e10cSrcweir 			break;
708cdf0e10cSrcweir 		case SID_DB_QUERY_PREVIEW:
709cdf0e10cSrcweir 			try
710cdf0e10cSrcweir 			{
711cdf0e10cSrcweir                 Reference< ::com::sun::star::util::XCloseable > xCloseFrame( getContainer()->getPreviewFrame(), UNO_QUERY );
712cdf0e10cSrcweir 				if ( xCloseFrame.is() )
713cdf0e10cSrcweir 				{
714cdf0e10cSrcweir                     try
715cdf0e10cSrcweir                     {
716cdf0e10cSrcweir                         xCloseFrame->close( sal_True );
717cdf0e10cSrcweir                     }
718cdf0e10cSrcweir                     catch( const Exception& )
719cdf0e10cSrcweir                     {
720cdf0e10cSrcweir                     	OSL_ENSURE( sal_False, "OQueryController::Execute(SID_DB_QUERY_PREVIEW): *nobody* is expected to veto closing the preview frame!" );
721cdf0e10cSrcweir                     }
722cdf0e10cSrcweir 				}
723cdf0e10cSrcweir 				else
724cdf0e10cSrcweir 					Execute(ID_BROWSER_QUERY_EXECUTE,Sequence< PropertyValue >());
725cdf0e10cSrcweir 			}
726cdf0e10cSrcweir 			catch(Exception&)
727cdf0e10cSrcweir 			{
728cdf0e10cSrcweir 			}
729cdf0e10cSrcweir 			break;
730cdf0e10cSrcweir 		case ID_QUERY_ZOOM_IN:
731cdf0e10cSrcweir 			{
732cdf0e10cSrcweir //				m_aZoom *= Fraction(1,10);
733cdf0e10cSrcweir //				static_cast<OQueryViewSwitch*>(getView())->zoomTableView(m_aZoom);
734cdf0e10cSrcweir 			}
735cdf0e10cSrcweir 			break;
736cdf0e10cSrcweir 		case ID_QUERY_ZOOM_OUT:
737cdf0e10cSrcweir 			{
738cdf0e10cSrcweir //				if(m_aZoom != Fraction(1,1))
739cdf0e10cSrcweir //					m_aZoom /= Fraction(1,10);
740cdf0e10cSrcweir //				static_cast<OQueryViewSwitch*>(getView())->zoomTableView(m_aZoom);
741cdf0e10cSrcweir 			}
742cdf0e10cSrcweir 			break;
743cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
744cdf0e10cSrcweir 		case ID_EDIT_QUERY_DESIGN:
745cdf0e10cSrcweir 		case ID_EDIT_QUERY_SQL:
746cdf0e10cSrcweir 			{
747cdf0e10cSrcweir 				::rtl::OUString aErrorMsg;
748cdf0e10cSrcweir                 setStatement_fireEvent( getContainer()->getStatement() );
749cdf0e10cSrcweir 				::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree( aErrorMsg, m_sStatement, m_bGraphicalDesign );
750cdf0e10cSrcweir 				if ( pNode )
751cdf0e10cSrcweir 				{
752cdf0e10cSrcweir 					Window* pView = getView();
753cdf0e10cSrcweir 					ModalDialog* pWindow = new ModalDialog( pView, WB_STDMODAL | WB_SIZEMOVE | WB_CENTER );
754cdf0e10cSrcweir                     pWindow->SetSizePixel( ::Size( pView->GetSizePixel().Width() / 2, pView->GetSizePixel().Height() / 2 ) );
755cdf0e10cSrcweir 					SvTreeListBox* pTreeBox = new SvTreeListBox( pWindow, WB_BORDER | WB_HASLINES | WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HASLINESATROOT | WB_VSCROLL );
756cdf0e10cSrcweir                     pTreeBox->SetPosSizePixel( ::Point( 6, 6 ), ::Size( pWindow->GetSizePixel().Width() - 12, pWindow->GetSizePixel().Height() - 12 ));
757cdf0e10cSrcweir                     pTreeBox->SetNodeDefaultImages();
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 					if ( _nId == ID_EDIT_QUERY_DESIGN )
760cdf0e10cSrcweir 					{
761cdf0e10cSrcweir 						::connectivity::OSQLParseNode* pTemp = pNode ? pNode->getChild(3)->getChild(1) : NULL;
762cdf0e10cSrcweir 						// no where clause found
763cdf0e10cSrcweir 						if ( pTemp && !pTemp->isLeaf() )
764cdf0e10cSrcweir 						{
765cdf0e10cSrcweir 							::connectivity::OSQLParseNode * pCondition = pTemp->getChild(1);
766cdf0e10cSrcweir 							if ( pCondition ) // no where clause
767cdf0e10cSrcweir 							{
768cdf0e10cSrcweir 								::connectivity::OSQLParseNode::negateSearchCondition(pCondition);
769cdf0e10cSrcweir 								::connectivity::OSQLParseNode *pNodeTmp = pTemp->getChild(1);
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 								::connectivity::OSQLParseNode::disjunctiveNormalForm(pNodeTmp);
772cdf0e10cSrcweir 								pNodeTmp = pTemp->getChild(1);
773cdf0e10cSrcweir 								::connectivity::OSQLParseNode::absorptions(pNodeTmp);
774cdf0e10cSrcweir 								pNodeTmp = pTemp->getChild(1);
775cdf0e10cSrcweir                                 OSQLParseNode::compress(pNodeTmp);
776cdf0e10cSrcweir                                 pNodeTmp = pTemp->getChild(1);
777cdf0e10cSrcweir 							} // if ( pCondition ) // no where clause
778cdf0e10cSrcweir                             ::rtl::OUString sTemp;
779cdf0e10cSrcweir                             pNode->parseNodeToStr(sTemp,getConnection());
780cdf0e10cSrcweir                             getContainer()->setStatement(sTemp);
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 						}
783cdf0e10cSrcweir 					}
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 					insertParseTree(pTreeBox,pNode);
786cdf0e10cSrcweir 
787cdf0e10cSrcweir 					pTreeBox->Show();
788cdf0e10cSrcweir 					pWindow->Execute();
789cdf0e10cSrcweir 
790cdf0e10cSrcweir 					delete pTreeBox;
791cdf0e10cSrcweir 					delete pWindow;
792cdf0e10cSrcweir 					delete pNode;
793cdf0e10cSrcweir 				}
794cdf0e10cSrcweir 				break;
795cdf0e10cSrcweir 			}
796cdf0e10cSrcweir #endif
797cdf0e10cSrcweir 		default:
798cdf0e10cSrcweir 			OJoinController::Execute(_nId,aArgs);
799cdf0e10cSrcweir 			return; // else we would invalidate twice
800cdf0e10cSrcweir 	}
801cdf0e10cSrcweir 	InvalidateFeature(_nId);
802cdf0e10cSrcweir }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir // -----------------------------------------------------------------------------
805cdf0e10cSrcweir void OQueryController::impl_showAutoSQLViewError( const ::com::sun::star::uno::Any& _rErrorDetails )
806cdf0e10cSrcweir {
807cdf0e10cSrcweir     SQLContext aErrorContext;
808cdf0e10cSrcweir     aErrorContext.Message = lcl_getObjectResourceString( STR_ERROR_PARSING_STATEMENT, m_nCommandType );
809cdf0e10cSrcweir     aErrorContext.Context = *this;
810cdf0e10cSrcweir     aErrorContext.Details = lcl_getObjectResourceString( STR_INFO_OPENING_IN_SQL_VIEW, m_nCommandType );
811cdf0e10cSrcweir     aErrorContext.NextException = _rErrorDetails;
812cdf0e10cSrcweir     showError( aErrorContext );
813cdf0e10cSrcweir }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir // -----------------------------------------------------------------------------
816cdf0e10cSrcweir bool OQueryController::impl_setViewMode( ::dbtools::SQLExceptionInfo* _pErrorInfo )
817cdf0e10cSrcweir {
818cdf0e10cSrcweir     OSL_PRECOND( getContainer(), "OQueryController::impl_setViewMode: illegal call!" );
819cdf0e10cSrcweir 
820cdf0e10cSrcweir     bool wasModified = isModified();
821cdf0e10cSrcweir 
822cdf0e10cSrcweir     SQLExceptionInfo aError;
823cdf0e10cSrcweir     bool bSuccess = getContainer()->switchView( &aError );
824cdf0e10cSrcweir     if ( !bSuccess )
825cdf0e10cSrcweir 	{
826cdf0e10cSrcweir 		m_bGraphicalDesign = !m_bGraphicalDesign;
827cdf0e10cSrcweir         // restore old state
828cdf0e10cSrcweir 		getContainer()->switchView( NULL );
829cdf0e10cSrcweir             // don't pass &aError here, this would overwrite the error which the first switchView call
830cdf0e10cSrcweir             // returned in this location.
831cdf0e10cSrcweir         if ( _pErrorInfo )
832cdf0e10cSrcweir             *_pErrorInfo = aError;
833cdf0e10cSrcweir         else
834cdf0e10cSrcweir             showError( aError );
835cdf0e10cSrcweir 	}
836cdf0e10cSrcweir 	else
837cdf0e10cSrcweir     {
838cdf0e10cSrcweir         ensureToolbars( *this, m_bGraphicalDesign );
839cdf0e10cSrcweir     }
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     setModified( wasModified );
842cdf0e10cSrcweir     return bSuccess;
843cdf0e10cSrcweir }
844cdf0e10cSrcweir 
845cdf0e10cSrcweir // -----------------------------------------------------------------------------
846cdf0e10cSrcweir void OQueryController::impl_initialize()
847cdf0e10cSrcweir {
848cdf0e10cSrcweir 	OJoinController::impl_initialize();
849cdf0e10cSrcweir 
850cdf0e10cSrcweir     const NamedValueCollection& rArguments( getInitParams() );
851cdf0e10cSrcweir 
852cdf0e10cSrcweir     ::rtl::OUString sCommand;
853cdf0e10cSrcweir     m_nCommandType = CommandType::QUERY;
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     // �����������������������������������������������������������������������������������������������������������������
856cdf0e10cSrcweir     // � reading parameters
857cdf0e10cSrcweir     // �����������������������������������������������������������������������������������������������������������������
858cdf0e10cSrcweir     // legacy parameters first (later overwritten by regular parameters)
859cdf0e10cSrcweir     ::rtl::OUString sIndependentSQLCommand;
860cdf0e10cSrcweir     if ( rArguments.get_ensureType( "IndependentSQLCommand", sIndependentSQLCommand ) )
861cdf0e10cSrcweir     {
862cdf0e10cSrcweir         OSL_ENSURE( false, "OQueryController::impl_initialize: IndependentSQLCommand is regognized for compatibility only!" );
863cdf0e10cSrcweir         sCommand = sIndependentSQLCommand;
864cdf0e10cSrcweir         m_nCommandType = CommandType::COMMAND;
865cdf0e10cSrcweir     }
866cdf0e10cSrcweir 
867cdf0e10cSrcweir     ::rtl::OUString sCurrentQuery;
868cdf0e10cSrcweir     if ( rArguments.get_ensureType( "CurrentQuery", sCurrentQuery ) )
869cdf0e10cSrcweir     {
870cdf0e10cSrcweir         OSL_ENSURE( false, "OQueryController::impl_initialize: CurrentQuery is regognized for compatibility only!" );
871cdf0e10cSrcweir         sCommand = sCurrentQuery;
872cdf0e10cSrcweir         m_nCommandType = CommandType::QUERY;
873cdf0e10cSrcweir     }
874cdf0e10cSrcweir 
875cdf0e10cSrcweir     sal_Bool bCreateView( sal_False );
876cdf0e10cSrcweir     if ( rArguments.get_ensureType( "CreateView", bCreateView ) && bCreateView )
877cdf0e10cSrcweir     {
878cdf0e10cSrcweir         OSL_ENSURE( false, "OQueryController::impl_initialize: CurrentQuery is regognized for compatibility only!" );
879cdf0e10cSrcweir         m_nCommandType = CommandType::TABLE;
880cdf0e10cSrcweir     }
881cdf0e10cSrcweir 
882cdf0e10cSrcweir     // non-legacy parameters which overwrite the legacy parameters
883cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND, sCommand );
884cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND_TYPE, m_nCommandType );
885cdf0e10cSrcweir 
886cdf0e10cSrcweir     // translate Command/Type into proper members
887cdf0e10cSrcweir     // TODO/Later: all this (including those members) should be hidden behind some abstact interface,
888cdf0e10cSrcweir     // which is implemented for all the three commands
889cdf0e10cSrcweir     switch ( m_nCommandType )
890cdf0e10cSrcweir     {
891cdf0e10cSrcweir     case CommandType::QUERY:
892cdf0e10cSrcweir         m_sName = sCommand;
893cdf0e10cSrcweir         break;
894cdf0e10cSrcweir     case CommandType::TABLE:
895cdf0e10cSrcweir         m_sName = sCommand;
896cdf0e10cSrcweir         break;
897cdf0e10cSrcweir     case CommandType::COMMAND:
898cdf0e10cSrcweir         setStatement_fireEvent( sCommand );
899cdf0e10cSrcweir         m_sName = ::rtl::OUString();
900cdf0e10cSrcweir         break;
901cdf0e10cSrcweir     default:
902cdf0e10cSrcweir         OSL_ENSURE( false, "OQueryController::impl_initialize: logic error in code!" );
903cdf0e10cSrcweir         throw RuntimeException();
904cdf0e10cSrcweir     }
905cdf0e10cSrcweir 
906cdf0e10cSrcweir     // more legacy parameters
907cdf0e10cSrcweir     sal_Bool bGraphicalDesign( sal_True );
908cdf0e10cSrcweir     if ( rArguments.get_ensureType( (::rtl::OUString)PROPERTY_QUERYDESIGNVIEW, bGraphicalDesign ) )
909cdf0e10cSrcweir     {
910cdf0e10cSrcweir         OSL_ENSURE( false, "OQueryController::impl_initialize: QueryDesignView is regognized for compatibility only!" );
911cdf0e10cSrcweir         m_bGraphicalDesign = bGraphicalDesign;
912cdf0e10cSrcweir     }
913cdf0e10cSrcweir 
914cdf0e10cSrcweir     // more non-legacy
915cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, m_bGraphicalDesign );
916cdf0e10cSrcweir 
917cdf0e10cSrcweir     bool bEscapeProcessing( sal_True );
918cdf0e10cSrcweir     if ( rArguments.get_ensureType( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, bEscapeProcessing ) )
919cdf0e10cSrcweir     {
920cdf0e10cSrcweir         setEscapeProcessing_fireEvent( bEscapeProcessing );
921cdf0e10cSrcweir 
922cdf0e10cSrcweir         OSL_ENSURE( m_bEscapeProcessing || !m_bGraphicalDesign, "OQueryController::impl_initialize: can't do the graphical design without escape processing!" );
923cdf0e10cSrcweir         if ( !m_bEscapeProcessing )
924cdf0e10cSrcweir             m_bGraphicalDesign = false;
925cdf0e10cSrcweir     }
926cdf0e10cSrcweir 
927cdf0e10cSrcweir     // .................................................................................................................
928cdf0e10cSrcweir     // . initial design
929cdf0e10cSrcweir     bool bForceInitialDesign = false;
930cdf0e10cSrcweir     Sequence< PropertyValue > aCurrentQueryDesignProps;
931cdf0e10cSrcweir     aCurrentQueryDesignProps = rArguments.getOrDefault( "CurrentQueryDesign", aCurrentQueryDesignProps );
932cdf0e10cSrcweir 
933cdf0e10cSrcweir     if ( aCurrentQueryDesignProps.getLength() )
934cdf0e10cSrcweir     {
935cdf0e10cSrcweir         ::comphelper::NamedValueCollection aCurrentQueryDesign( aCurrentQueryDesignProps );
936cdf0e10cSrcweir         if ( aCurrentQueryDesign.has( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN ) )
937cdf0e10cSrcweir         {
938cdf0e10cSrcweir             aCurrentQueryDesign.get_ensureType( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, m_bGraphicalDesign );
939cdf0e10cSrcweir         }
940cdf0e10cSrcweir         if ( aCurrentQueryDesign.has( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING ) )
941cdf0e10cSrcweir         {
942cdf0e10cSrcweir             aCurrentQueryDesign.get_ensureType( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, m_bEscapeProcessing );
943cdf0e10cSrcweir         }
944cdf0e10cSrcweir         if ( aCurrentQueryDesign.has( "Statement" ) )
945cdf0e10cSrcweir         {
946cdf0e10cSrcweir             ::rtl::OUString sStatement;
947cdf0e10cSrcweir             aCurrentQueryDesign.get_ensureType( "Statement", sStatement );
948cdf0e10cSrcweir             aCurrentQueryDesign.remove( "Statement" );
949cdf0e10cSrcweir             setStatement_fireEvent( sStatement );
950cdf0e10cSrcweir         }
951cdf0e10cSrcweir 
952cdf0e10cSrcweir         loadViewSettings( aCurrentQueryDesign );
953cdf0e10cSrcweir 
954cdf0e10cSrcweir         bForceInitialDesign = true;
955cdf0e10cSrcweir     }
956cdf0e10cSrcweir 
957cdf0e10cSrcweir     // �����������������������������������������������������������������������������������������������������������������
958cdf0e10cSrcweir 	if ( !ensureConnected( sal_False ) )
959cdf0e10cSrcweir 	{	// we have no connection so what else should we do
960cdf0e10cSrcweir 		m_bGraphicalDesign = sal_False;
961cdf0e10cSrcweir 		if ( editingView() )
962cdf0e10cSrcweir 		{
963cdf0e10cSrcweir 			connectionLostMessage();
964cdf0e10cSrcweir 			throw SQLException();
965cdf0e10cSrcweir 		}
966cdf0e10cSrcweir 	}
967cdf0e10cSrcweir 
968cdf0e10cSrcweir     // check the view capabilities
969cdf0e10cSrcweir 	if ( isConnected() && editingView() )
970cdf0e10cSrcweir 	{
971cdf0e10cSrcweir 		Reference< XViewsSupplier > xViewsSup( getConnection(), UNO_QUERY );
972cdf0e10cSrcweir         Reference< XNameAccess > xViews;
973cdf0e10cSrcweir         if ( xViewsSup.is() )
974cdf0e10cSrcweir             xViews = xViewsSup->getViews();
975cdf0e10cSrcweir 
976cdf0e10cSrcweir         if ( !xViews.is() )
977cdf0e10cSrcweir 		{	// we can't create views so we ask if the user wants to create a query instead
978cdf0e10cSrcweir             m_nCommandType = CommandType::QUERY;
979cdf0e10cSrcweir 			sal_Bool bClose = sal_False;
980cdf0e10cSrcweir 			{
981cdf0e10cSrcweir 				String aTitle( ModuleRes( STR_QUERYDESIGN_NO_VIEW_SUPPORT ) );
982cdf0e10cSrcweir 				String aMessage( ModuleRes( STR_QUERYDESIGN_NO_VIEW_ASK ) );
983cdf0e10cSrcweir 				ODataView* pWindow = getView();
984cdf0e10cSrcweir 				OSQLMessageBox aDlg( pWindow, aTitle, aMessage, WB_YES_NO | WB_DEF_YES, OSQLMessageBox::Query );
985cdf0e10cSrcweir 				bClose = aDlg.Execute() == RET_NO;
986cdf0e10cSrcweir 			}
987cdf0e10cSrcweir 			if ( bClose )
988cdf0e10cSrcweir 				throw VetoException();
989cdf0e10cSrcweir 		}
990cdf0e10cSrcweir 
991cdf0e10cSrcweir         // now if we are to edit an existing view, check whether this is possible
992cdf0e10cSrcweir         if ( m_sName.getLength() )
993cdf0e10cSrcweir         {
994cdf0e10cSrcweir             Any aView( xViews->getByName( m_sName ) );
995cdf0e10cSrcweir                 // will throw if there is no such view
996cdf0e10cSrcweir             if ( !( aView >>= m_xAlterView ) )
997cdf0e10cSrcweir             {
998cdf0e10cSrcweir                 throw IllegalArgumentException(
999cdf0e10cSrcweir                     ::rtl::OUString( String( ModuleRes( STR_NO_ALTER_VIEW_SUPPORT ) ) ),
1000cdf0e10cSrcweir                     *this,
1001cdf0e10cSrcweir                     1
1002cdf0e10cSrcweir                 );
1003cdf0e10cSrcweir             }
1004cdf0e10cSrcweir         }
1005cdf0e10cSrcweir 	}
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 	OSL_ENSURE(getDataSource().is(),"OQueryController::impl_initialize: need a datasource!");
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 	try
1010cdf0e10cSrcweir 	{
1011cdf0e10cSrcweir 		getContainer()->initialize();
1012cdf0e10cSrcweir         impl_reset( bForceInitialDesign );
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir         SQLExceptionInfo aError;
1015cdf0e10cSrcweir         const bool bAttemptedGraphicalDesign = m_bGraphicalDesign;
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir         if ( bForceInitialDesign )
1018cdf0e10cSrcweir         {
1019cdf0e10cSrcweir             getContainer()->forceInitialView();
1020cdf0e10cSrcweir         }
1021cdf0e10cSrcweir         else
1022cdf0e10cSrcweir         {
1023cdf0e10cSrcweir             impl_setViewMode( &aError );
1024cdf0e10cSrcweir         }
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir         if ( aError.isValid() && bAttemptedGraphicalDesign && !m_bGraphicalDesign )
1027cdf0e10cSrcweir         {
1028cdf0e10cSrcweir             // we tried initializing the graphical view, this failed, and we were automatically switched to SQL
1029cdf0e10cSrcweir             // view => tell this to the user
1030cdf0e10cSrcweir             if ( !editingView() )
1031cdf0e10cSrcweir             {
1032cdf0e10cSrcweir                 impl_showAutoSQLViewError( aError.get() );
1033cdf0e10cSrcweir             }
1034cdf0e10cSrcweir         }
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir 		ClearUndoManager();
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir 		if  (  ( m_bGraphicalDesign )
1039cdf0e10cSrcweir             && (  ( !m_sName.getLength() && !editingCommand() )
1040cdf0e10cSrcweir                || ( !m_sStatement.getLength() && editingCommand() )
1041cdf0e10cSrcweir                )
1042cdf0e10cSrcweir             )
1043cdf0e10cSrcweir         {
1044cdf0e10cSrcweir             Application::PostUserEvent( LINK( this, OQueryController, OnExecuteAddTable ) );
1045cdf0e10cSrcweir         }
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir 		setModified(sal_False);
1048cdf0e10cSrcweir 	}
1049cdf0e10cSrcweir 	catch(SQLException& e)
1050cdf0e10cSrcweir 	{
1051cdf0e10cSrcweir 		DBG_UNHANDLED_EXCEPTION();
1052cdf0e10cSrcweir 		// we caught an exception so we switch to text only mode
1053cdf0e10cSrcweir 		{
1054cdf0e10cSrcweir 			m_bGraphicalDesign = sal_False;
1055cdf0e10cSrcweir 			getContainer()->initialize();
1056cdf0e10cSrcweir 			ODataView* pWindow = getView();
1057cdf0e10cSrcweir 			OSQLMessageBox(pWindow,e).Execute();
1058cdf0e10cSrcweir 		}
1059cdf0e10cSrcweir 		throw;
1060cdf0e10cSrcweir 	}
1061cdf0e10cSrcweir }
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir // -----------------------------------------------------------------------------
1064cdf0e10cSrcweir void OQueryController::onLoadedMenu(const Reference< ::com::sun::star::frame::XLayoutManager >& /*_xLayoutManager*/)
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir     ensureToolbars( *this, m_bGraphicalDesign );
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir // -----------------------------------------------------------------------------
1070cdf0e10cSrcweir ::rtl::OUString OQueryController::getPrivateTitle( ) const
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir 	::rtl::OUString sName = m_sName;
1073cdf0e10cSrcweir 	if ( !sName.getLength() )
1074cdf0e10cSrcweir 	{
1075cdf0e10cSrcweir         if ( !editingCommand() )
1076cdf0e10cSrcweir         {
1077cdf0e10cSrcweir 			::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1078cdf0e10cSrcweir 			::osl::MutexGuard aGuard( getMutex() );
1079cdf0e10cSrcweir             String aDefaultName = String( ModuleRes( editingView() ? STR_VIEW_TITLE : STR_QRY_TITLE ) );
1080cdf0e10cSrcweir 			sName = aDefaultName.GetToken(0,' ');
1081cdf0e10cSrcweir             sName += ::rtl::OUString::valueOf(getCurrentStartNumber());
1082cdf0e10cSrcweir         }
1083cdf0e10cSrcweir 	}
1084cdf0e10cSrcweir     return sName;
1085cdf0e10cSrcweir }
1086cdf0e10cSrcweir // -----------------------------------------------------------------------------
1087cdf0e10cSrcweir void OQueryController::setQueryComposer()
1088cdf0e10cSrcweir {
1089cdf0e10cSrcweir 	if(isConnected())
1090cdf0e10cSrcweir 	{
1091cdf0e10cSrcweir 		Reference< XSQLQueryComposerFactory >  xFactory(getConnection(), UNO_QUERY);
1092cdf0e10cSrcweir 		OSL_ENSURE(xFactory.is(),"Connection doesn't support a querycomposer");
1093cdf0e10cSrcweir 		if ( xFactory.is() && getContainer() )
1094cdf0e10cSrcweir 		{
1095cdf0e10cSrcweir 			try
1096cdf0e10cSrcweir 			{
1097cdf0e10cSrcweir 				m_xComposer = xFactory->createQueryComposer();
1098cdf0e10cSrcweir 				getContainer()->setStatement(m_sStatement);
1099cdf0e10cSrcweir 			}
1100cdf0e10cSrcweir 			catch (Exception&)
1101cdf0e10cSrcweir 			{
1102cdf0e10cSrcweir 				m_xComposer = NULL;
1103cdf0e10cSrcweir 			}
1104cdf0e10cSrcweir 			OSL_ENSURE(m_xComposer.is(),"No querycomposer available!");
1105cdf0e10cSrcweir 			Reference<XTablesSupplier> xTablesSup(getConnection(), UNO_QUERY);
1106cdf0e10cSrcweir 			deleteIterator();
1107cdf0e10cSrcweir 			m_pSqlIterator = new ::connectivity::OSQLParseTreeIterator( getConnection(), xTablesSup->getTables(), m_aSqlParser, NULL );
1108cdf0e10cSrcweir 		}
1109cdf0e10cSrcweir 	}
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir // -----------------------------------------------------------------------------
1112cdf0e10cSrcweir sal_Bool OQueryController::Construct(Window* pParent)
1113cdf0e10cSrcweir {
1114cdf0e10cSrcweir 	// TODO: we have to check if we should create the text- or the design- view
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir 	setView( * new OQueryContainerWindow( pParent, *this, getORB() ) );
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir 	return OJoinController::Construct(pParent);
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir // -----------------------------------------------------------------------------
1122cdf0e10cSrcweir OJoinDesignView* OQueryController::getJoinView()
1123cdf0e10cSrcweir {
1124cdf0e10cSrcweir 	return getContainer()->getDesignView();
1125cdf0e10cSrcweir }
1126cdf0e10cSrcweir // -----------------------------------------------------------------------------
1127cdf0e10cSrcweir void OQueryController::describeSupportedFeatures()
1128cdf0e10cSrcweir {
1129cdf0e10cSrcweir 	OJoinController::describeSupportedFeatures();
1130cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SaveAs",            ID_BROWSER_SAVEASDOC,       CommandGroup::DOCUMENT );
1131cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SbaNativeSql",      ID_BROWSER_ESACPEPROCESSING,CommandGroup::FORMAT );
1132cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewFunctions",   SID_QUERY_VIEW_FUNCTIONS,   CommandGroup::VIEW );
1133cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewTableNames",  SID_QUERY_VIEW_TABLES,      CommandGroup::VIEW );
1134cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewAliases",     SID_QUERY_VIEW_ALIASES,     CommandGroup::VIEW );
1135cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDistinctValues",  SID_QUERY_DISTINCT_VALUES,  CommandGroup::FORMAT );
1136cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBChangeDesignMode",ID_BROWSER_SQL,             CommandGroup::VIEW );
1137cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBClearQuery",      SID_BROWSER_CLEAR_QUERY,    CommandGroup::EDIT );
1138cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SbaExecuteSql",     ID_BROWSER_QUERY_EXECUTE,   CommandGroup::VIEW );
1139cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBAddRelation",     SID_RELATION_ADD_RELATION,  CommandGroup::EDIT );
1140cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryPreview",    SID_DB_QUERY_PREVIEW,       CommandGroup::VIEW );
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1143cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBShowParseTree",   ID_EDIT_QUERY_SQL );
1144cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBMakeDisjunct",    ID_EDIT_QUERY_DESIGN );
1145cdf0e10cSrcweir #endif
1146cdf0e10cSrcweir }
1147cdf0e10cSrcweir // -----------------------------------------------------------------------------
1148cdf0e10cSrcweir void OQueryController::impl_onModifyChanged()
1149cdf0e10cSrcweir {
1150cdf0e10cSrcweir 	OJoinController::impl_onModifyChanged();
1151cdf0e10cSrcweir 	InvalidateFeature(SID_BROWSER_CLEAR_QUERY);
1152cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_SAVEASDOC);
1153cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
1154cdf0e10cSrcweir }
1155cdf0e10cSrcweir // -----------------------------------------------------------------------------
1156cdf0e10cSrcweir void SAL_CALL OQueryController::disposing( const EventObject& Source ) throw(RuntimeException)
1157cdf0e10cSrcweir {
1158cdf0e10cSrcweir 	::vos::OGuard aGuard(Application::GetSolarMutex());
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 	if ( getContainer() && Source.Source.is() )
1161cdf0e10cSrcweir 	{
1162cdf0e10cSrcweir 		if ( Source.Source == m_aCurrentFrame.getFrame() )
1163cdf0e10cSrcweir 		{	// our frame is beeing disposed -> close the preview window (if we have one)
1164cdf0e10cSrcweir             Reference< XFrame > xPreviewFrame( getContainer()->getPreviewFrame() );
1165cdf0e10cSrcweir 			::comphelper::disposeComponent( xPreviewFrame );
1166cdf0e10cSrcweir 		}
1167cdf0e10cSrcweir 		else if ( Source.Source == getContainer()->getPreviewFrame() )
1168cdf0e10cSrcweir 		{
1169cdf0e10cSrcweir 			getContainer()->disposingPreview();
1170cdf0e10cSrcweir 		}
1171cdf0e10cSrcweir 	}
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 	OJoinController::disposing(Source);
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir // -----------------------------------------------------------------------------
1176cdf0e10cSrcweir void OQueryController::reconnect(sal_Bool _bUI)
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir 	deleteIterator();
1179cdf0e10cSrcweir 	::comphelper::disposeComponent(m_xComposer);
1180cdf0e10cSrcweir 
1181cdf0e10cSrcweir 	OJoinController::reconnect( _bUI );
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 	if (isConnected())
1184cdf0e10cSrcweir 	{
1185cdf0e10cSrcweir 		setQueryComposer();
1186cdf0e10cSrcweir 	}
1187cdf0e10cSrcweir 	else
1188cdf0e10cSrcweir 	{
1189cdf0e10cSrcweir 		if(m_bGraphicalDesign)
1190cdf0e10cSrcweir 		{
1191cdf0e10cSrcweir 			m_bGraphicalDesign = sal_False;
1192cdf0e10cSrcweir 			// don't call Execute(SQL) because this changes the sql statement
1193cdf0e10cSrcweir 			impl_setViewMode( NULL );
1194cdf0e10cSrcweir 		}
1195cdf0e10cSrcweir 		InvalidateAll();
1196cdf0e10cSrcweir 	}
1197cdf0e10cSrcweir }
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir // -----------------------------------------------------------------------------
1200cdf0e10cSrcweir void OQueryController::saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includingCriteria ) const
1201cdf0e10cSrcweir {
1202cdf0e10cSrcweir 	saveTableWindows( o_rViewSettings );
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir     OTableFields::const_iterator field = m_vTableFieldDesc.begin();
1205cdf0e10cSrcweir     OTableFields::const_iterator fieldEnd = m_vTableFieldDesc.end();
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir     ::comphelper::NamedValueCollection aAllFieldsData;
1208cdf0e10cSrcweir     ::comphelper::NamedValueCollection aFieldData;
1209cdf0e10cSrcweir 	for ( sal_Int32 i = 1; field != fieldEnd; ++field, ++i )
1210cdf0e10cSrcweir 	{
1211cdf0e10cSrcweir 		if ( !(*field)->IsEmpty() )
1212cdf0e10cSrcweir 		{
1213cdf0e10cSrcweir             aFieldData.clear();
1214cdf0e10cSrcweir 			(*field)->Save( aFieldData, i_includingCriteria );
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir             const ::rtl::OUString sFieldSettingName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Field" ) ) + ::rtl::OUString::valueOf( i );
1217cdf0e10cSrcweir             aAllFieldsData.put( sFieldSettingName, aFieldData.getPropertyValues() );
1218cdf0e10cSrcweir 		}
1219cdf0e10cSrcweir 	}
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir     o_rViewSettings.put( "Fields", aAllFieldsData.getPropertyValues() );
1222cdf0e10cSrcweir     o_rViewSettings.put( "SplitterPosition", m_nSplitPos );
1223cdf0e10cSrcweir     o_rViewSettings.put( "VisibleRows", m_nVisibleRows );
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir // -----------------------------------------------------------------------------
1226cdf0e10cSrcweir void OQueryController::loadViewSettings( const ::comphelper::NamedValueCollection& o_rViewSettings )
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir 	loadTableWindows( o_rViewSettings );
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir     m_nSplitPos = o_rViewSettings.getOrDefault( "SplitterPosition", m_nSplitPos );
1231cdf0e10cSrcweir     m_nVisibleRows = o_rViewSettings.getOrDefault( "VisibleRows", m_nVisibleRows );
1232cdf0e10cSrcweir     m_aFieldInformation = o_rViewSettings.getOrDefault( "Fields", m_aFieldInformation );
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir // -----------------------------------------------------------------------------
1235cdf0e10cSrcweir sal_Int32 OQueryController::getColWidth(sal_uInt16 _nColPos)  const
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir     if ( _nColPos < m_aFieldInformation.getLength() )
1238cdf0e10cSrcweir     {
1239cdf0e10cSrcweir         ::std::auto_ptr<OTableFieldDesc> pField( new OTableFieldDesc());
1240cdf0e10cSrcweir         pField->Load( m_aFieldInformation[ _nColPos ], false );
1241cdf0e10cSrcweir         return pField->GetColWidth();
1242cdf0e10cSrcweir     }
1243cdf0e10cSrcweir     return 0;
1244cdf0e10cSrcweir }
1245cdf0e10cSrcweir // -----------------------------------------------------------------------------
1246cdf0e10cSrcweir Reference<XNameAccess> OQueryController::getObjectContainer()  const
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir 	Reference< XNameAccess > xElements;
1249cdf0e10cSrcweir 	if ( editingView() )
1250cdf0e10cSrcweir 	{
1251cdf0e10cSrcweir 		Reference< XViewsSupplier > xViewsSupp( getConnection(), UNO_QUERY );
1252cdf0e10cSrcweir 		if ( xViewsSupp.is() )
1253cdf0e10cSrcweir 			xElements = xViewsSupp->getViews();
1254cdf0e10cSrcweir 	}
1255cdf0e10cSrcweir 	else
1256cdf0e10cSrcweir 	{
1257cdf0e10cSrcweir 		Reference< XQueriesSupplier > xQueriesSupp( getConnection(), UNO_QUERY );
1258cdf0e10cSrcweir 		if ( xQueriesSupp.is() )
1259cdf0e10cSrcweir 			xElements = xQueriesSupp->getQueries();
1260cdf0e10cSrcweir 		else
1261cdf0e10cSrcweir 		{
1262cdf0e10cSrcweir 			Reference< XQueryDefinitionsSupplier > xQueryDefsSupp( getDataSource(), UNO_QUERY );
1263cdf0e10cSrcweir 			if ( xQueryDefsSupp.is() )
1264cdf0e10cSrcweir 				xElements = xQueryDefsSupp->getQueryDefinitions();
1265cdf0e10cSrcweir 		}
1266cdf0e10cSrcweir 	}
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir     OSL_ENSURE( xElements.is(), "OQueryController::getObjectContainer: unable to obtain the container!" );
1269cdf0e10cSrcweir 	return xElements;
1270cdf0e10cSrcweir }
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir // -----------------------------------------------------------------------------
1273cdf0e10cSrcweir void OQueryController::executeQuery()
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir 	// we don't need to check the connection here because we already check the composer
1276cdf0e10cSrcweir 	// which can't live without his connection
1277cdf0e10cSrcweir 	::rtl::OUString sTranslatedStmt = translateStatement( false );
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir 	::rtl::OUString sDataSourceName = getDataSourceName();
1280cdf0e10cSrcweir 	if ( sDataSourceName.getLength() && sTranslatedStmt.getLength() )
1281cdf0e10cSrcweir 	{
1282cdf0e10cSrcweir 		try
1283cdf0e10cSrcweir 		{
1284cdf0e10cSrcweir 			getContainer()->showPreview( getFrame() );
1285cdf0e10cSrcweir 			InvalidateFeature(SID_DB_QUERY_PREVIEW);
1286cdf0e10cSrcweir 
1287cdf0e10cSrcweir 			URL aWantToDispatch;
1288cdf0e10cSrcweir 			aWantToDispatch.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser");
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir 			::rtl::OUString sFrameName( FRAME_NAME_QUERY_PREVIEW );
1291cdf0e10cSrcweir 			sal_Int32 nSearchFlags = FrameSearchFlag::CHILDREN;
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir 			Reference< XDispatch> xDisp;
1294cdf0e10cSrcweir 			Reference< XDispatchProvider> xProv( getFrame()->findFrame( sFrameName, nSearchFlags ), UNO_QUERY );
1295cdf0e10cSrcweir 			if(!xProv.is())
1296cdf0e10cSrcweir 			{
1297cdf0e10cSrcweir 				xProv.set( getFrame(), UNO_QUERY );
1298cdf0e10cSrcweir 				if (xProv.is())
1299cdf0e10cSrcweir 					xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, nSearchFlags);
1300cdf0e10cSrcweir 			}
1301cdf0e10cSrcweir 			else
1302cdf0e10cSrcweir 			{
1303cdf0e10cSrcweir 				xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, FrameSearchFlag::SELF);
1304cdf0e10cSrcweir 			}
1305cdf0e10cSrcweir 			if (xDisp.is())
1306cdf0e10cSrcweir 			{
1307cdf0e10cSrcweir 				Sequence< PropertyValue> aProps(9);
1308cdf0e10cSrcweir 				aProps[0].Name = PROPERTY_DATASOURCENAME;
1309cdf0e10cSrcweir 				aProps[0].Value <<= sDataSourceName;
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir 				aProps[1].Name = PROPERTY_COMMAND_TYPE;
1312cdf0e10cSrcweir 				aProps[1].Value <<= CommandType::COMMAND;
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir 				aProps[2].Name = PROPERTY_COMMAND;
1315cdf0e10cSrcweir 				aProps[2].Value <<= sTranslatedStmt;
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir 				aProps[3].Name = PROPERTY_ENABLE_BROWSER;
1318cdf0e10cSrcweir 				aProps[3].Value = ::cppu::bool2any(sal_False);
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir 				aProps[4].Name = PROPERTY_ACTIVE_CONNECTION;
1321cdf0e10cSrcweir 				aProps[4].Value <<= getConnection();
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir 				aProps[5].Name = PROPERTY_UPDATE_CATALOGNAME;
1324cdf0e10cSrcweir 				aProps[5].Value <<= m_sUpdateCatalogName;
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir 				aProps[6].Name = PROPERTY_UPDATE_SCHEMANAME;
1327cdf0e10cSrcweir 				aProps[6].Value <<= m_sUpdateSchemaName;
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir 				aProps[7].Name = PROPERTY_UPDATE_TABLENAME;
1330cdf0e10cSrcweir 				aProps[7].Value <<= m_sUpdateTableName;
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir 				aProps[8].Name = PROPERTY_ESCAPE_PROCESSING;
1333cdf0e10cSrcweir 				aProps[8].Value = ::cppu::bool2any(m_bEscapeProcessing);
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir 				xDisp->dispatch(aWantToDispatch, aProps);
1336cdf0e10cSrcweir 				// check the state of the beamer
1337cdf0e10cSrcweir 				// be notified when the beamer frame is closed
1338cdf0e10cSrcweir 				Reference< XComponent >  xComponent( getFrame()->findFrame( sFrameName, nSearchFlags ), UNO_QUERY );
1339cdf0e10cSrcweir 				if (xComponent.is())
1340cdf0e10cSrcweir 				{
1341cdf0e10cSrcweir 					OSL_ENSURE(Reference< XFrame >(xComponent, UNO_QUERY).get() == getContainer()->getPreviewFrame().get(),
1342cdf0e10cSrcweir 						"OQueryController::executeQuery: oops ... which window do I have here?");
1343cdf0e10cSrcweir 					Reference< XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
1344cdf0e10cSrcweir 					xComponent->addEventListener(xEvtL);
1345cdf0e10cSrcweir 				}
1346cdf0e10cSrcweir 			}
1347cdf0e10cSrcweir 			else
1348cdf0e10cSrcweir 			{
1349cdf0e10cSrcweir 				OSL_ENSURE(0,"Couldn't create a beamer window!");
1350cdf0e10cSrcweir 			}
1351cdf0e10cSrcweir 		}
1352cdf0e10cSrcweir 		catch(const Exception&)
1353cdf0e10cSrcweir 		{
1354cdf0e10cSrcweir 			OSL_ENSURE(0,"Couldn't create a beamer window!");
1355cdf0e10cSrcweir 		}
1356cdf0e10cSrcweir 	}
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir // -----------------------------------------------------------------------------
1359cdf0e10cSrcweir sal_Bool OQueryController::askForNewName(const Reference<XNameAccess>& _xElements,sal_Bool _bSaveAs)
1360cdf0e10cSrcweir {
1361cdf0e10cSrcweir     OSL_ENSURE( !editingCommand(), "OQueryController::askForNewName: not to be called when designing an independent statement!" );
1362cdf0e10cSrcweir     if ( editingCommand() )
1363cdf0e10cSrcweir         return sal_False;
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir     OSL_PRECOND( _xElements.is(), "OQueryController::askForNewName: invalid container!" );
1366cdf0e10cSrcweir     if  ( !_xElements.is() )
1367cdf0e10cSrcweir         return sal_False;
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
1370cdf0e10cSrcweir 	sal_Bool bNew = _bSaveAs || !_xElements->hasByName( m_sName );
1371cdf0e10cSrcweir 	if(bNew)
1372cdf0e10cSrcweir 	{
1373cdf0e10cSrcweir 		String aDefaultName;
1374cdf0e10cSrcweir 		if ( ( _bSaveAs && !bNew ) || ( bNew && m_sName.getLength() ) )
1375cdf0e10cSrcweir 			aDefaultName = String( m_sName );
1376cdf0e10cSrcweir 		else
1377cdf0e10cSrcweir         {
1378cdf0e10cSrcweir             String sName = String( ModuleRes( editingView() ? STR_VIEW_TITLE : STR_QRY_TITLE ) );
1379cdf0e10cSrcweir 			aDefaultName = sName.GetToken(0,' ');
1380cdf0e10cSrcweir             //aDefaultName = getPrivateTitle( );
1381cdf0e10cSrcweir             aDefaultName = ::dbtools::createUniqueName(_xElements,aDefaultName);
1382cdf0e10cSrcweir         }
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir         DynamicTableOrQueryNameCheck aNameChecker( getConnection(), CommandType::QUERY );
1385cdf0e10cSrcweir 		OSaveAsDlg aDlg(
1386cdf0e10cSrcweir 				getView(),
1387cdf0e10cSrcweir                 m_nCommandType,
1388cdf0e10cSrcweir                 getORB(),
1389cdf0e10cSrcweir 				getConnection(),
1390cdf0e10cSrcweir 				aDefaultName,
1391cdf0e10cSrcweir                 aNameChecker,
1392cdf0e10cSrcweir 				SAD_DEFAULT );
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir         bRet = ( aDlg.Execute() == RET_OK );
1395cdf0e10cSrcweir 		if ( bRet )
1396cdf0e10cSrcweir 		{
1397cdf0e10cSrcweir 			m_sName = aDlg.getName();
1398cdf0e10cSrcweir 			if ( editingView() )
1399cdf0e10cSrcweir 			{
1400cdf0e10cSrcweir 				m_sUpdateCatalogName	= aDlg.getCatalog();
1401cdf0e10cSrcweir 				m_sUpdateSchemaName		= aDlg.getSchema();
1402cdf0e10cSrcweir 			}
1403cdf0e10cSrcweir 		}
1404cdf0e10cSrcweir 	}
1405cdf0e10cSrcweir 	return bRet;
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir // -----------------------------------------------------------------------------
1408cdf0e10cSrcweir bool OQueryController::doSaveAsDoc(sal_Bool _bSaveAs)
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir 	OSL_ENSURE(isEditable(),"Slot ID_BROWSER_SAVEDOC should not be enabled!");
1411cdf0e10cSrcweir 	if ( !editingCommand() && !haveDataSource() )
1412cdf0e10cSrcweir 	{
1413cdf0e10cSrcweir 		String aMessage(ModuleRes(STR_DATASOURCE_DELETED));
1414cdf0e10cSrcweir 		OSQLWarningBox( getView(), aMessage ).Execute();
1415cdf0e10cSrcweir         return false;
1416cdf0e10cSrcweir 	}
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir 	Reference< XNameAccess > xElements = getObjectContainer();
1419cdf0e10cSrcweir 	if ( !xElements.is() )
1420cdf0e10cSrcweir         return false;
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir     if ( !getContainer()->checkStatement() )
1423cdf0e10cSrcweir 		return false;
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir 	::rtl::OUString sTranslatedStmt = translateStatement();
1426cdf0e10cSrcweir     if ( editingCommand() )
1427cdf0e10cSrcweir     {
1428cdf0e10cSrcweir         setModified( sal_False );
1429cdf0e10cSrcweir         // this is all we need to do here. translateStatement implicitly set our m_sStatement, and
1430cdf0e10cSrcweir         // notified it, and that's all
1431cdf0e10cSrcweir         return true;
1432cdf0e10cSrcweir     }
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	if ( !sTranslatedStmt.getLength() )
1435cdf0e10cSrcweir         return false;
1436cdf0e10cSrcweir 
1437cdf0e10cSrcweir     // first we need a name for our query so ask the user
1438cdf0e10cSrcweir 	// did we get a name
1439cdf0e10cSrcweir     ::rtl::OUString sOriginalName( m_sName );
1440cdf0e10cSrcweir     if ( !askForNewName( xElements, _bSaveAs ) || !m_sName.getLength() )
1441cdf0e10cSrcweir         return false;
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir     SQLExceptionInfo aInfo;
1444cdf0e10cSrcweir     bool bSuccess = false;
1445cdf0e10cSrcweir     bool bNew = false;
1446cdf0e10cSrcweir 	try
1447cdf0e10cSrcweir 	{
1448cdf0e10cSrcweir         bNew = ( _bSaveAs )
1449cdf0e10cSrcweir             || ( !xElements->hasByName( m_sName ) );
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir         Reference<XPropertySet> xQuery;
1452cdf0e10cSrcweir 		if ( bNew ) // just to make sure the query already exists
1453cdf0e10cSrcweir 		{
1454cdf0e10cSrcweir             // drop the query, in case it already exists
1455cdf0e10cSrcweir 			if ( xElements->hasByName( m_sName ) )
1456cdf0e10cSrcweir 			{
1457cdf0e10cSrcweir 				Reference< XDrop > xNameCont( xElements, UNO_QUERY );
1458cdf0e10cSrcweir 				if ( xNameCont.is() )
1459cdf0e10cSrcweir 					xNameCont->dropByName( m_sName );
1460cdf0e10cSrcweir 				else
1461cdf0e10cSrcweir 				{
1462cdf0e10cSrcweir 					Reference< XNameContainer > xCont( xElements, UNO_QUERY );
1463cdf0e10cSrcweir 					if ( xCont.is() )
1464cdf0e10cSrcweir 						xCont->removeByName( m_sName );
1465cdf0e10cSrcweir 				}
1466cdf0e10cSrcweir 			}
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir             // create a new (empty, uninitialized) query resp. view
1469cdf0e10cSrcweir 			Reference< XDataDescriptorFactory > xFact( xElements, UNO_QUERY );
1470cdf0e10cSrcweir 			if ( xFact.is() )
1471cdf0e10cSrcweir 			{
1472cdf0e10cSrcweir 				xQuery = xFact->createDataDescriptor();
1473cdf0e10cSrcweir 				// to set the name is only allowed when the query is new
1474cdf0e10cSrcweir 				xQuery->setPropertyValue( PROPERTY_NAME, makeAny( m_sName ) );
1475cdf0e10cSrcweir 			}
1476cdf0e10cSrcweir 			else
1477cdf0e10cSrcweir 			{
1478cdf0e10cSrcweir 				Reference< XSingleServiceFactory > xSingleFac( xElements, UNO_QUERY );
1479cdf0e10cSrcweir                 if ( xSingleFac.is() )
1480cdf0e10cSrcweir 					xQuery = xQuery.query( xSingleFac->createInstance() );
1481cdf0e10cSrcweir 			}
1482cdf0e10cSrcweir 		}
1483cdf0e10cSrcweir 		else
1484cdf0e10cSrcweir 		{
1485cdf0e10cSrcweir 			xElements->getByName( m_sName ) >>= xQuery;
1486cdf0e10cSrcweir 		}
1487cdf0e10cSrcweir         if ( !xQuery.is() )
1488cdf0e10cSrcweir             throw RuntimeException();
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir         // the new commands
1491cdf0e10cSrcweir         if ( editingView() && !bNew )
1492cdf0e10cSrcweir         {
1493cdf0e10cSrcweir             OSL_ENSURE( xQuery == m_xAlterView, "OQueryController::doSaveAsDoc: already have another alterable view ...!?" );
1494cdf0e10cSrcweir             m_xAlterView.set( xQuery, UNO_QUERY_THROW );
1495cdf0e10cSrcweir             m_xAlterView->alterCommand( sTranslatedStmt );
1496cdf0e10cSrcweir         }
1497cdf0e10cSrcweir         else
1498cdf0e10cSrcweir         {   // we're creating a query, or a *new* view
1499cdf0e10cSrcweir             xQuery->setPropertyValue( PROPERTY_COMMAND, makeAny( sTranslatedStmt ) );
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir             if ( editingView() )
1502cdf0e10cSrcweir             {
1503cdf0e10cSrcweir 			    xQuery->setPropertyValue( PROPERTY_CATALOGNAME, makeAny( m_sUpdateCatalogName ) );
1504cdf0e10cSrcweir 			    xQuery->setPropertyValue( PROPERTY_SCHEMANAME, makeAny( m_sUpdateSchemaName ) );
1505cdf0e10cSrcweir             }
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir             if ( editingQuery() )
1508cdf0e10cSrcweir 			{
1509cdf0e10cSrcweir 				xQuery->setPropertyValue( PROPERTY_UPDATE_TABLENAME, makeAny( m_sUpdateTableName ) );
1510cdf0e10cSrcweir 				xQuery->setPropertyValue( PROPERTY_ESCAPE_PROCESSING,::cppu::bool2any( m_bEscapeProcessing ) );
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir 				xQuery->setPropertyValue( PROPERTY_LAYOUTINFORMATION, getViewData() );
1513cdf0e10cSrcweir 			}
1514cdf0e10cSrcweir         }
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 		if ( bNew )
1517cdf0e10cSrcweir 		{
1518cdf0e10cSrcweir 			Reference< XAppend > xAppend( xElements, UNO_QUERY );
1519cdf0e10cSrcweir 			if ( xAppend.is() )
1520cdf0e10cSrcweir 			{
1521cdf0e10cSrcweir 				xAppend->appendByDescriptor( xQuery );
1522cdf0e10cSrcweir 			}
1523cdf0e10cSrcweir 			else
1524cdf0e10cSrcweir 			{
1525cdf0e10cSrcweir 				Reference< XNameContainer > xCont( xElements, UNO_QUERY );
1526cdf0e10cSrcweir 				if ( xCont.is() )
1527cdf0e10cSrcweir 					xCont->insertByName( m_sName, makeAny( xQuery ) );
1528cdf0e10cSrcweir 			}
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir 			if ( editingView() )
1531cdf0e10cSrcweir 			{
1532cdf0e10cSrcweir 				Reference< XPropertySet > xViewProps;
1533cdf0e10cSrcweir 				if ( xElements->hasByName( m_sName ) )
1534cdf0e10cSrcweir 					xViewProps.set( xElements->getByName( m_sName ), UNO_QUERY );
1535cdf0e10cSrcweir 
1536cdf0e10cSrcweir 				if ( !xViewProps.is() ) // correct name and try again
1537cdf0e10cSrcweir 					m_sName = ::dbtools::composeTableName( getMetaData(), xQuery, ::dbtools::eInDataManipulation, false, false, false );
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir                 OSL_ENSURE( xElements->hasByName( m_sName ), "OQueryController::doSaveAsDoc: newly creaed view does not exist!" );
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir                 if ( xElements->hasByName( m_sName ) )
1542cdf0e10cSrcweir                     m_xAlterView.set( xElements->getByName( m_sName ), UNO_QUERY );
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir                 // now check if our datasource has set a tablefilter and if so, append the new table name to it
1545cdf0e10cSrcweir 				::dbaui::appendToFilter( getConnection(), m_sName, getORB(), getView() );
1546cdf0e10cSrcweir 			} // if ( editingView() )
1547cdf0e10cSrcweir             Reference< XTitleChangeListener> xEventListener(impl_getTitleHelper_throw(),UNO_QUERY);
1548cdf0e10cSrcweir             if ( xEventListener.is() )
1549cdf0e10cSrcweir             {
1550cdf0e10cSrcweir                 TitleChangedEvent aEvent;
1551cdf0e10cSrcweir                 xEventListener->titleChanged(aEvent);
1552cdf0e10cSrcweir             }
1553cdf0e10cSrcweir             releaseNumberForComponent();
1554cdf0e10cSrcweir 		}
1555cdf0e10cSrcweir 
1556cdf0e10cSrcweir 		setModified( sal_False );
1557cdf0e10cSrcweir         bSuccess = true;
1558cdf0e10cSrcweir 
1559cdf0e10cSrcweir 	}
1560cdf0e10cSrcweir 	catch( const SQLException& )
1561cdf0e10cSrcweir 	{
1562cdf0e10cSrcweir         if ( !bNew )
1563cdf0e10cSrcweir             m_sName = sOriginalName;
1564cdf0e10cSrcweir         aInfo = SQLExceptionInfo( ::cppu::getCaughtException() );
1565cdf0e10cSrcweir 	}
1566cdf0e10cSrcweir 	catch(Exception&)
1567cdf0e10cSrcweir 	{
1568cdf0e10cSrcweir         if ( !bNew )
1569cdf0e10cSrcweir             m_sName = sOriginalName;
1570cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1571cdf0e10cSrcweir 	}
1572cdf0e10cSrcweir 
1573cdf0e10cSrcweir 	showError( aInfo );
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir     // update the title of our window
1576cdf0e10cSrcweir 	//updateTitle();
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir     // if we successfully saved a view we were creating, then close the designer
1579cdf0e10cSrcweir     if ( bSuccess && editingView() && !m_xAlterView.is() )
1580cdf0e10cSrcweir     {
1581cdf0e10cSrcweir 		closeTask();
1582cdf0e10cSrcweir     }
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir     if ( bSuccess && editingView() )
1585cdf0e10cSrcweir         InvalidateFeature( ID_BROWSER_EDITDOC );
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir     return bSuccess;
1588cdf0e10cSrcweir }
1589cdf0e10cSrcweir // -----------------------------------------------------------------------------
1590cdf0e10cSrcweir ::rtl::OUString OQueryController::translateStatement( bool _bFireStatementChange )
1591cdf0e10cSrcweir {
1592cdf0e10cSrcweir 	// now set the properties
1593cdf0e10cSrcweir 	setStatement_fireEvent( getContainer()->getStatement(), _bFireStatementChange );
1594cdf0e10cSrcweir 	::rtl::OUString sTranslatedStmt;
1595cdf0e10cSrcweir 	if(m_sStatement.getLength() && m_xComposer.is() && m_bEscapeProcessing)
1596cdf0e10cSrcweir 	{
1597cdf0e10cSrcweir 		try
1598cdf0e10cSrcweir 		{
1599cdf0e10cSrcweir 			::rtl::OUString aErrorMsg;
1600cdf0e10cSrcweir 
1601cdf0e10cSrcweir 			::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree( aErrorMsg, m_sStatement, m_bGraphicalDesign );
1602cdf0e10cSrcweir 			if(pNode)
1603cdf0e10cSrcweir 			{
1604cdf0e10cSrcweir                 pNode->parseNodeToStr( sTranslatedStmt, getConnection() );
1605cdf0e10cSrcweir 				delete pNode;
1606cdf0e10cSrcweir 			}
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir             m_xComposer->setQuery(sTranslatedStmt);
1609cdf0e10cSrcweir 			sTranslatedStmt = m_xComposer->getComposedQuery();
1610cdf0e10cSrcweir 		}
1611cdf0e10cSrcweir 		catch(SQLException& e)
1612cdf0e10cSrcweir 		{
1613cdf0e10cSrcweir 			::dbtools::SQLExceptionInfo aInfo(e);
1614cdf0e10cSrcweir 			showError(aInfo);
1615cdf0e10cSrcweir 			// an error occured so we clear the statement
1616cdf0e10cSrcweir 			sTranslatedStmt = ::rtl::OUString();
1617cdf0e10cSrcweir 		}
1618cdf0e10cSrcweir 	}
1619cdf0e10cSrcweir 	else if(!m_sStatement.getLength())
1620cdf0e10cSrcweir 	{
1621cdf0e10cSrcweir         ModuleRes aModuleRes(STR_QRY_NOSELECT);
1622cdf0e10cSrcweir         String sTmpStr(aModuleRes);
1623cdf0e10cSrcweir 		::rtl::OUString sError(sTmpStr);
1624cdf0e10cSrcweir 		showError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000") ),1000,Any()));
1625cdf0e10cSrcweir 	}
1626cdf0e10cSrcweir 	else
1627cdf0e10cSrcweir 		sTranslatedStmt = m_sStatement;
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir 	return sTranslatedStmt;
1630cdf0e10cSrcweir }
1631cdf0e10cSrcweir // -----------------------------------------------------------------------------
1632cdf0e10cSrcweir short OQueryController::saveModified()
1633cdf0e10cSrcweir {
1634cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1635cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1636cdf0e10cSrcweir 	short nRet = RET_YES;
1637cdf0e10cSrcweir     if ( !isConnected() || !isModified() )
1638cdf0e10cSrcweir         return nRet;
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir 	if  (  !m_bGraphicalDesign
1641cdf0e10cSrcweir         || (  !m_vTableFieldDesc.empty()
1642cdf0e10cSrcweir            && !m_vTableData.empty()
1643cdf0e10cSrcweir            )
1644cdf0e10cSrcweir         )
1645cdf0e10cSrcweir 	{
1646cdf0e10cSrcweir         String sMessageText( lcl_getObjectResourceString( STR_QUERY_SAVEMODIFIED, m_nCommandType ) );
1647cdf0e10cSrcweir         QueryBox aQry( getView(), WB_YES_NO_CANCEL | WB_DEF_YES, sMessageText );
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir         nRet = aQry.Execute();
1650cdf0e10cSrcweir 		if  (   ( nRet == RET_YES )
1651cdf0e10cSrcweir             &&  !doSaveAsDoc( sal_False )
1652cdf0e10cSrcweir             )
1653cdf0e10cSrcweir         {
1654cdf0e10cSrcweir             nRet = RET_CANCEL;
1655cdf0e10cSrcweir 		}
1656cdf0e10cSrcweir 	}
1657cdf0e10cSrcweir 	return nRet;
1658cdf0e10cSrcweir }
1659cdf0e10cSrcweir // -----------------------------------------------------------------------------
1660cdf0e10cSrcweir void OQueryController::impl_reset( const bool i_bForceCurrentControllerSettings )
1661cdf0e10cSrcweir {
1662cdf0e10cSrcweir     bool bValid = false;
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir     Sequence< PropertyValue > aLayoutInformation;
1665cdf0e10cSrcweir 	// get command from the query if a query name was supplied
1666cdf0e10cSrcweir     if ( !i_bForceCurrentControllerSettings && !editingCommand() )
1667cdf0e10cSrcweir     {
1668cdf0e10cSrcweir 	    if ( m_sName.getLength() )
1669cdf0e10cSrcweir 	    {
1670cdf0e10cSrcweir             Reference< XNameAccess > xQueries = getObjectContainer();
1671cdf0e10cSrcweir 		    if ( xQueries.is() )
1672cdf0e10cSrcweir 		    {
1673cdf0e10cSrcweir                 Reference< XPropertySet > xProp;
1674cdf0e10cSrcweir 			    if( xQueries->hasByName( m_sName ) && ( xQueries->getByName( m_sName ) >>= xProp ) && xProp.is() )
1675cdf0e10cSrcweir 			    {
1676cdf0e10cSrcweir                     ::rtl::OUString sNewStatement;
1677cdf0e10cSrcweir 				    xProp->getPropertyValue( PROPERTY_COMMAND ) >>= sNewStatement;
1678cdf0e10cSrcweir                     setStatement_fireEvent( sNewStatement );
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir                     sal_Bool bNewEscapeProcessing( sal_True );
1681cdf0e10cSrcweir                     if ( editingQuery() )
1682cdf0e10cSrcweir                     {
1683cdf0e10cSrcweir                         xProp->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bNewEscapeProcessing;
1684cdf0e10cSrcweir                         setEscapeProcessing_fireEvent( bNewEscapeProcessing );
1685cdf0e10cSrcweir                     }
1686cdf0e10cSrcweir 
1687cdf0e10cSrcweir 				    m_bGraphicalDesign = m_bGraphicalDesign && m_bEscapeProcessing;
1688cdf0e10cSrcweir                     bValid = true;
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir                     try
1691cdf0e10cSrcweir                     {
1692cdf0e10cSrcweir                         if ( editingQuery() )
1693cdf0e10cSrcweir                             xProp->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) >>= aLayoutInformation;
1694cdf0e10cSrcweir                     }
1695cdf0e10cSrcweir                     catch( const Exception& )
1696cdf0e10cSrcweir                     {
1697cdf0e10cSrcweir                     	OSL_ENSURE( sal_False, "OQueryController::impl_reset: could not retrieve the layout information from the query!" );
1698cdf0e10cSrcweir                     }
1699cdf0e10cSrcweir                 }
1700cdf0e10cSrcweir             }
1701cdf0e10cSrcweir         }
1702cdf0e10cSrcweir     }
1703cdf0e10cSrcweir     else
1704cdf0e10cSrcweir     {
1705cdf0e10cSrcweir         bValid = true;
1706cdf0e10cSrcweir         // assume that we got all necessary information during initialization
1707cdf0e10cSrcweir     }
1708cdf0e10cSrcweir 
1709cdf0e10cSrcweir 	if ( bValid )
1710cdf0e10cSrcweir 	{
1711cdf0e10cSrcweir         // load the layoutInformation
1712cdf0e10cSrcweir         if ( aLayoutInformation.getLength() )
1713cdf0e10cSrcweir         {
1714cdf0e10cSrcweir 		    try
1715cdf0e10cSrcweir 		    {
1716cdf0e10cSrcweir 				loadViewSettings( aLayoutInformation );
1717cdf0e10cSrcweir 		    }
1718cdf0e10cSrcweir 		    catch( const Exception& )
1719cdf0e10cSrcweir 		    {
1720cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
1721cdf0e10cSrcweir 		    }
1722cdf0e10cSrcweir         }
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir         if ( m_sStatement.getLength() )
1725cdf0e10cSrcweir         {
1726cdf0e10cSrcweir             setQueryComposer();
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir             bool bError( false );
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir             if ( !m_pSqlIterator )
1731cdf0e10cSrcweir             {
1732cdf0e10cSrcweir                 bError = true;
1733cdf0e10cSrcweir             }
1734cdf0e10cSrcweir 		    else if ( m_bEscapeProcessing )
1735cdf0e10cSrcweir 		    {
1736cdf0e10cSrcweir 			    ::rtl::OUString aErrorMsg;
1737cdf0e10cSrcweir                 ::std::auto_ptr< ::connectivity::OSQLParseNode > pNode(
1738cdf0e10cSrcweir                     m_aSqlParser.parseTree( aErrorMsg, m_sStatement, m_bGraphicalDesign ) );
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir                 if ( pNode.get() )
1741cdf0e10cSrcweir 			    {
1742cdf0e10cSrcweir 				    delete m_pSqlIterator->getParseTree();
1743cdf0e10cSrcweir 				    m_pSqlIterator->setParseTree( pNode.release() );
1744cdf0e10cSrcweir 				    m_pSqlIterator->traverseAll();
1745cdf0e10cSrcweir                     if ( m_pSqlIterator->hasErrors() )
1746cdf0e10cSrcweir                     {
1747cdf0e10cSrcweir                         if ( !i_bForceCurrentControllerSettings && m_bGraphicalDesign && !editingView() )
1748cdf0e10cSrcweir                         {
1749cdf0e10cSrcweir                             impl_showAutoSQLViewError( makeAny( m_pSqlIterator->getErrors() ) );
1750cdf0e10cSrcweir                         }
1751cdf0e10cSrcweir 					    bError = true;
1752cdf0e10cSrcweir 				    }
1753cdf0e10cSrcweir 			    }
1754cdf0e10cSrcweir 			    else
1755cdf0e10cSrcweir 			    {
1756cdf0e10cSrcweir                     if ( !i_bForceCurrentControllerSettings && !editingView() )
1757cdf0e10cSrcweir                     {
1758cdf0e10cSrcweir 				        String aTitle(ModuleRes(STR_SVT_SQL_SYNTAX_ERROR));
1759cdf0e10cSrcweir 				        OSQLMessageBox aDlg(getView(),aTitle,aErrorMsg);
1760cdf0e10cSrcweir 				        aDlg.Execute();
1761cdf0e10cSrcweir                     }
1762cdf0e10cSrcweir 				    bError = true;
1763cdf0e10cSrcweir 			    }
1764cdf0e10cSrcweir             }
1765cdf0e10cSrcweir 
1766cdf0e10cSrcweir             if ( bError )
1767cdf0e10cSrcweir             {
1768cdf0e10cSrcweir                 m_bGraphicalDesign = sal_False;
1769cdf0e10cSrcweir                 if ( editingView() )
1770cdf0e10cSrcweir                     // if we're editing a view whose statement could not be parsed, default to "no escape processing"
1771cdf0e10cSrcweir                     setEscapeProcessing_fireEvent( sal_False );
1772cdf0e10cSrcweir             }
1773cdf0e10cSrcweir         }
1774cdf0e10cSrcweir 	}
1775cdf0e10cSrcweir 
1776cdf0e10cSrcweir 	if(!m_pSqlIterator)
1777cdf0e10cSrcweir 		setQueryComposer();
1778cdf0e10cSrcweir 	OSL_ENSURE(m_pSqlIterator,"No SQLIterator set!");
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir 	getContainer()->setNoneVisbleRow(m_nVisibleRows);
1781cdf0e10cSrcweir }
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir // -----------------------------------------------------------------------------
1784cdf0e10cSrcweir void OQueryController::reset()
1785cdf0e10cSrcweir {
1786cdf0e10cSrcweir 	impl_reset();
1787cdf0e10cSrcweir 	getContainer()->reset( NULL );
1788cdf0e10cSrcweir 	ClearUndoManager();
1789cdf0e10cSrcweir }
1790cdf0e10cSrcweir 
1791cdf0e10cSrcweir // -----------------------------------------------------------------------------
1792cdf0e10cSrcweir void OQueryController::setStatement_fireEvent( const ::rtl::OUString& _rNewStatement, bool _bFireStatementChange )
1793cdf0e10cSrcweir {
1794cdf0e10cSrcweir     Any aOldValue = makeAny( m_sStatement );
1795cdf0e10cSrcweir     m_sStatement = _rNewStatement;
1796cdf0e10cSrcweir     Any aNewValue = makeAny( m_sStatement );
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir     sal_Int32 nHandle = PROPERTY_ID_ACTIVECOMMAND;
1799cdf0e10cSrcweir     if ( _bFireStatementChange )
1800cdf0e10cSrcweir         fire( &nHandle, &aNewValue, &aOldValue, 1, sal_False );
1801cdf0e10cSrcweir }
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir // -----------------------------------------------------------------------------
1804cdf0e10cSrcweir void OQueryController::setEscapeProcessing_fireEvent( const sal_Bool _bEscapeProcessing )
1805cdf0e10cSrcweir {
1806cdf0e10cSrcweir     if ( _bEscapeProcessing == m_bEscapeProcessing )
1807cdf0e10cSrcweir         return;
1808cdf0e10cSrcweir 
1809cdf0e10cSrcweir     Any aOldValue = makeAny( m_bEscapeProcessing );
1810cdf0e10cSrcweir     m_bEscapeProcessing = _bEscapeProcessing;
1811cdf0e10cSrcweir     Any aNewValue = makeAny( m_bEscapeProcessing );
1812cdf0e10cSrcweir 
1813cdf0e10cSrcweir     sal_Int32 nHandle = PROPERTY_ID_ESCAPE_PROCESSING;
1814cdf0e10cSrcweir     fire( &nHandle, &aNewValue, &aOldValue, 1, sal_False );
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir 
1817cdf0e10cSrcweir // -----------------------------------------------------------------------------
1818cdf0e10cSrcweir IMPL_LINK( OQueryController, OnExecuteAddTable, void*, /*pNotInterestedIn*/ )
1819cdf0e10cSrcweir {
1820cdf0e10cSrcweir     Execute( ID_BROWSER_ADDTABLE,Sequence<PropertyValue>() );
1821cdf0e10cSrcweir     return 0L;
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir 
1824cdf0e10cSrcweir // -----------------------------------------------------------------------------
1825cdf0e10cSrcweir bool OQueryController::allowViews() const
1826cdf0e10cSrcweir {
1827cdf0e10cSrcweir     return true;
1828cdf0e10cSrcweir }
1829cdf0e10cSrcweir 
1830cdf0e10cSrcweir // -----------------------------------------------------------------------------
1831cdf0e10cSrcweir bool OQueryController::allowQueries() const
1832cdf0e10cSrcweir {
1833cdf0e10cSrcweir     DBG_ASSERT( getSdbMetaData().isConnected(), "OQueryController::allowQueries: illegal call!" );
1834cdf0e10cSrcweir     if ( !getSdbMetaData().supportsSubqueriesInFrom() )
1835cdf0e10cSrcweir         return false;
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir     const NamedValueCollection& rArguments( getInitParams() );
1838cdf0e10cSrcweir     sal_Int32 nCommandType = rArguments.getOrDefault( (::rtl::OUString)PROPERTY_COMMAND_TYPE, (sal_Int32)CommandType::QUERY );
1839cdf0e10cSrcweir     sal_Bool bCreatingView = ( nCommandType == CommandType::TABLE );
1840cdf0e10cSrcweir     return !bCreatingView;
1841cdf0e10cSrcweir }
1842cdf0e10cSrcweir 
1843cdf0e10cSrcweir // -----------------------------------------------------------------------------
1844cdf0e10cSrcweir Any SAL_CALL OQueryController::getViewData() throw( RuntimeException )
1845cdf0e10cSrcweir {
1846cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1847cdf0e10cSrcweir 
1848cdf0e10cSrcweir     getContainer()->SaveUIConfig();
1849cdf0e10cSrcweir 
1850cdf0e10cSrcweir     ::comphelper::NamedValueCollection aViewSettings;
1851cdf0e10cSrcweir 	saveViewSettings( aViewSettings, false );
1852cdf0e10cSrcweir 
1853cdf0e10cSrcweir 	return makeAny( aViewSettings.getPropertyValues() );
1854cdf0e10cSrcweir }
1855cdf0e10cSrcweir // -----------------------------------------------------------------------------
1856cdf0e10cSrcweir void SAL_CALL OQueryController::restoreViewData(const Any& /*Data*/) throw( RuntimeException )
1857cdf0e10cSrcweir {
1858cdf0e10cSrcweir     // TODO
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir // -----------------------------------------------------------------------------
1862cdf0e10cSrcweir } // namespace dbaui
1863cdf0e10cSrcweir // -----------------------------------------------------------------------------
1864cdf0e10cSrcweir 
1865