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