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