User: obo Date: 2006/07/10 08:45:10 Modified: dba/dbaccess/source/ui/querydesign/querycontroller.cxx
Log: INTEGRATION: CWS qiq (1.103.4); FILE MERGED 2006/07/03 19:48:01 fs 1.103.4.12: #i51143# don't allow to add queries to the designer which do not produce a result set 2006/06/28 10:31:11 fs 1.103.4.11: #i10000# 2006/06/27 12:57:09 fs 1.103.4.10: RESYNC: (1.103-1.104); FILE MERGED 2006/06/19 10:46:28 fs 1.103.4.9: during #i51143#: describeSupportedFeatures: DBAddTable is unnecessary, base class already adds (equivalent) AddTable 2006/06/19 09:27:52 fs 1.103.4.8: during #i51143#: A FeatureState can now transport more than one state. In particular, it has typed bChecked and sTitle members, instead of the previous unchecked aState 2006/05/24 06:49:29 fs 1.103.4.7: some refactoring of compose/quoteTableName and friends, in preparation of #i51143# 2006/05/18 09:18:35 fs 1.103.4.6: #i51143# when creating/pasting/saving a table/query, care for name collisions with both tables and queries (usign a DynamicTableOrQueryNameCheck), if the database supports queries in queries 2006/05/17 11:48:47 fs 1.103.4.5: refactored OSaveAsDlg in preparation of #i51143# 2006/05/17 04:30:56 fs 1.103.4.4: #i51143# changed signature of OSQLParseTreeIterator 2006/05/12 13:45:50 fs 1.103.4.3: #i51143# don't allow sub queries if we're creating a view 2006/05/12 11:10:16 fs 1.103.4.2: #i51143# +allowViews/+allowQueries 2006/05/10 11:08:50 fs 1.103.4.1: #i51143# allow for queries in queries File Changes: Directory: /dba/dbaccess/source/ui/querydesign/ =============================================== File [changed]: querycontroller.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/querydesign/querycontroller.cxx?r1=1.104&r2=1.105 Delta lines: +142 -170 ----------------------- --- querycontroller.cxx 20 Jun 2006 03:29:57 -0000 1.104 +++ querycontroller.cxx 10 Jul 2006 15:45:08 -0000 1.105 @@ -59,6 +59,9 @@ #ifndef DBAUI_QUERYDESIGNVIEW_HXX #include "QueryDesignView.hxx" #endif +#ifndef DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX +#include "defaultobjectnamecheck.hxx" +#endif #ifndef _COMPHELPER_TYPES_HXX_ #include <comphelper/types.hxx> #endif @@ -95,6 +98,9 @@ #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_ #include <com/sun/star/sdb/CommandType.hpp> #endif +#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#endif #ifndef DBAUI_DLGSAVE_HXX #include "dlgsave.hxx" #endif @@ -331,6 +337,8 @@ void switchDesignModeImpl(OQueryController* _pController,OQueryContainerWindow* _pWindow,sal_Bool& _rbDesign) { + bool isModified = _pController->isModified(); + if ( !_pWindow->switchView() ) { _rbDesign = !_rbDesign; @@ -340,6 +348,8 @@ { ensureToolbars( _pController, _rbDesign ); } + + _pController->setModified( isModified ); } } @@ -375,6 +385,8 @@ // ----------------------------------------------------------------------------- OQueryController::OQueryController(const Reference< XMultiServiceFactory >& _rM) :OJoinController(_rM) + ,m_pParseContext( new svxform::OSystemParseContext ) + ,m_aSqlParser( _rM, m_pParseContext ) ,m_pSqlIterator(NULL) ,m_nVisibleRows(0x400) ,m_nSplitPos(-1) @@ -388,8 +400,6 @@ ,m_bIndependent( sal_False ) { DBG_CTOR(OQueryController,NULL); - m_pParseContext = new svxform::OSystemParseContext(); - m_pSqlParser = new OSQLParser(_rM,m_pParseContext); InvalidateAll(); registerProperty( PROPERTY_ACTIVECOMMAND, PROPERTY_ID_ACTIVECOMMAND, PropertyAttribute::READONLY | PropertyAttribute::BOUND, @@ -424,14 +434,11 @@ { deleteIterator(); - delete m_pSqlParser; delete m_pParseContext; clearFields(); OTableFields().swap(m_vUnUsedFieldsDesc); - m_pView = NULL; - ::comphelper::disposeComponent(m_xComposer); OJoinController::disposing(); } @@ -457,7 +464,7 @@ break; case ID_BROWSER_ESACPEPROCESSING: - aReturn.aState = ::cppu::bool2any(!m_bEsacpeProcessing); + aReturn.bChecked = !m_bEsacpeProcessing; aReturn.bEnabled = !m_bIndependent && ( m_pSqlIterator != NULL ) && !m_bDesign; break; case SID_RELATION_ADD_RELATION: @@ -482,7 +489,7 @@ break; case ID_BROWSER_SQL: aReturn.bEnabled = m_bEsacpeProcessing && m_pSqlIterator; - aReturn.aState = ::cppu::bool2any(m_bDesign); + aReturn.bChecked = m_bDesign; break; case SID_BROWSER_CLEAR_QUERY: aReturn.bEnabled = isEditable() && (m_sStatement.getLength() || !m_vTableData.empty()); @@ -490,19 +497,19 @@ case SID_QUERY_VIEW_FUNCTIONS: case SID_QUERY_VIEW_TABLES: case SID_QUERY_VIEW_ALIASES: - aReturn.aState = ::cppu::bool2any(getContainer() && getContainer()->isSlotEnabled(_nId)); + aReturn.bChecked = getContainer() && getContainer()->isSlotEnabled(_nId); aReturn.bEnabled = m_bDesign; break; case SID_QUERY_DISTINCT_VALUES: aReturn.bEnabled = m_bDesign && isEditable(); - aReturn.aState = ::cppu::bool2any(m_bDistinct); + aReturn.bChecked = m_bDistinct; break; case ID_BROWSER_QUERY_EXECUTE: aReturn.bEnabled = sal_True; break; case SID_DB_QUERY_PREVIEW: aReturn.bEnabled = sal_True; - aReturn.aState <<= ::cppu::bool2any(getContainer() && getContainer()->getPreviewFrame().is()); + aReturn.bChecked = getContainer() && getContainer()->getPreviewFrame().is(); break; #if OSL_DEBUG_LEVEL > 1 case ID_EDIT_QUERY_SQL: @@ -559,8 +566,8 @@ getContainer()->paste(); break; case ID_BROWSER_SQL: - if(getContainer()->checkStatement()) - { + if ( !getContainer()->checkStatement() ) + break; try { ::rtl::OUString aErrorMsg; @@ -575,20 +582,21 @@ } else { - ::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree(aErrorMsg,m_sStatement,m_bDesign); + ::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree(aErrorMsg,m_sStatement,m_bDesign); // m_pParseNode = pNode; if(pNode) { delete m_pSqlIterator->getParseTree(); m_pSqlIterator->setParseTree(pNode); m_pSqlIterator->traverseAll(); - SQLWarning aWarning = m_pSqlIterator->getWarning(); - if(aWarning.Message.getLength()) - showError(SQLExceptionInfo(aWarning)); + if ( m_pSqlIterator->hasErrors() ) + { + showError( SQLExceptionInfo( m_pSqlIterator->getErrors() ) ); + } else { const OSQLTables& xTabs = m_pSqlIterator->getTables(); - if( m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT && m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT_COUNT || xTabs.begin() == xTabs.end()) + if( m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT || xTabs.begin() == xTabs.end()) { ModuleRes aModuleRes(STR_QRY_NOSELECT); String sTmpStr(aModuleRes); @@ -629,7 +637,6 @@ InvalidateFeature(ID_BROWSER_ADDTABLE); InvalidateFeature(SID_RELATION_ADD_RELATION); } - } break; case SID_BROWSER_CLEAR_QUERY: { @@ -698,7 +705,7 @@ { ::rtl::OUString aErrorMsg; setStatement_fireEvent( getContainer()->getStatement() ); - ::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree( aErrorMsg, m_sStatement, m_bDesign ); + ::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree( aErrorMsg, m_sStatement, m_bDesign ); if ( pNode ) { Window* pView = getView(); @@ -746,56 +753,35 @@ InvalidateFeature(_nId); } // ----------------------------------------------------------------------------- -void OQueryController::impl_initialize( const Sequence< Any >& aArguments ) +void OQueryController::impl_initialize() { - OJoinController::impl_initialize(aArguments); + OJoinController::impl_initialize(); - PropertyValue aValue; - const Any* pIter = aArguments.getConstArray(); - const Any* pEnd = pIter + aArguments.getLength(); + const NamedValueCollection& rArguments( getInitParams() ); - for(;pIter != pEnd;++pIter) - { - if (!(*pIter >>= aValue)) - throw Exception(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid type in argument list. PropertyValue expected.")),*this); + Reference< XConnection > xConnection; + xConnection = rArguments.getOrDefault( (::rtl::OUString)PROPERTY_ACTIVECONNECTION, xConnection ); + if ( xConnection.is() ) + initializeConnection( xConnection ); - if (0 == aValue.Name.compareToAscii(PROPERTY_ACTIVECONNECTION)) - { - Reference< XConnection > xConn; - if ( !(aValue.Value >>= xConn) ) - throw Exception(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid argument type for ActiveConnection.")),*this); - if ( xConn.is() ) - initializeConnection( xConn ); - } - else if(0 == aValue.Name.compareToAscii(PROPERTY_CURRENTQUERY)) - { - if ( !(aValue.Value >>= m_sName) ) + if ( !rArguments.getIfExists_ensureType( (::rtl::OUString)PROPERTY_CURRENTQUERY, m_sName ) ) throw Exception(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid argument type for CurrentQuery.")),*this); - } - else if(0 == aValue.Name.compareToAscii(PROPERTY_QUERYDESIGNVIEW)) - { - if ( !(aValue.Value >>= m_bDesign) ) + + if ( !rArguments.getIfExists_ensureType( (::rtl::OUString)PROPERTY_QUERYDESIGNVIEW, m_bDesign ) ) throw Exception(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid argument type for QueryDesignView.")),*this); - } - else if(0 == aValue.Name.compareToAscii(PROPERTY_CREATEVIEW)) - { - if ( !(aValue.Value >>= m_bCreateView) ) + + if ( !rArguments.getIfExists_ensureType( (::rtl::OUString)PROPERTY_CREATEVIEW, m_bCreateView ) ) throw Exception(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid argument type for CreateView.")),*this); - } - else if ( 0 == aValue.Name.compareToAscii( PARAM_INDEPENDENT_SQL_COMMAND ) ) + + ::rtl::OUString sIndependentSQLCommand; + if ( !rArguments.getIfExists_ensureType( (::rtl::OUString)PARAM_INDEPENDENT_SQL_COMMAND, sIndependentSQLCommand ) ) + throw Exception( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid argument type for IndependentSQLCommand." ) ),*this); + if ( sIndependentSQLCommand.getLength() ) { m_bIndependent = sal_True; m_bEsacpeProcessing = sal_True; + setStatement_fireEvent( sIndependentSQLCommand ); - ::rtl::OUString sNewStatement; - if ( !(aValue.Value >>= sNewStatement) ) - throw Exception(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid argument type for IndependentSQLCommand.")),*this); - setStatement_fireEvent( sNewStatement ); - } - } - - if ( m_bIndependent ) - { OSL_ENSURE( m_sName.getLength() == 0, "OQueryController::initialize: both a query name and an independent SQL command?" ); OSL_ENSURE( !m_bCreateView, "OQueryController::initialize: create a view, *and* an independent SQL command?" ); m_sName = ::rtl::OUString(); @@ -937,7 +923,7 @@ OSL_ENSURE(m_xComposer.is(),"No querycomposer available!"); Reference<XTablesSupplier> xTablesSup(getConnection(), UNO_QUERY); deleteIterator(); - m_pSqlIterator = new ::connectivity::OSQLParseTreeIterator(xTablesSup->getTables(),getMetaData(),NULL,m_pSqlParser); + m_pSqlIterator = new ::connectivity::OSQLParseTreeIterator( getConnection(), xTablesSup->getTables(), m_aSqlParser, NULL ); } } } @@ -970,7 +956,6 @@ implDescribeSupportedFeature( ".uno:DBClearQuery", SID_BROWSER_CLEAR_QUERY, CommandGroup::EDIT ); implDescribeSupportedFeature( ".uno:SbaExecuteSql", ID_BROWSER_QUERY_EXECUTE, CommandGroup::VIEW ); implDescribeSupportedFeature( ".uno:DBAddRelation", SID_RELATION_ADD_RELATION, CommandGroup::EDIT ); - implDescribeSupportedFeature( ".uno:DBAddTable", ID_BROWSER_ADDTABLE, CommandGroup::EDIT ); implDescribeSupportedFeature( ".uno:DBQueryPreview", SID_DB_QUERY_PREVIEW, CommandGroup::VIEW ); #if OSL_DEBUG_LEVEL > 1 @@ -1017,10 +1002,6 @@ if (isConnected()) { - // we hide the add table dialog because the tables in it are from the old connection - if(m_pAddTabDlg) - m_pAddTabDlg->Hide(); - InvalidateFeature(ID_BROWSER_ADDTABLE); setQueryComposer(); } else @@ -1142,30 +1123,6 @@ return xElements; } -//typedef ::cppu::ImplHelper1< XLoadEventListener > OQueryControllerLoadListener_BASE; -//class OQueryControllerLoadListener : public OQueryControllerLoadListener_BASE -//{ -// OQueryController* m_pController; -//public: -// OQueryControllerLoadListener(OQueryController* _pController) : m_pController(_pController) -// { -// OSL_ENSURE(m_pController,"Controller can not be NULL!"); -// } -// // ----------------------------------------------------------------------------- -// virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException) -// { -// } -// // ----------------------------------------------------------------------------- -// // XLoadEventListener -// virtual void SAL_CALL loadFinished( const Reference< XFrameLoader >& aLoader ) throw (RuntimeException) -// { -// } -// // ----------------------------------------------------------------------------- -// virtual void SAL_CALL loadCancelled( const Reference< XFrameLoader >& aLoader ) throw (RuntimeException) -// { -// m_pController->Execute(ID_BROWSER_CLOSE); -// } -//}; // ----------------------------------------------------------------------------- void OQueryController::executeQuery() { @@ -1181,15 +1138,10 @@ getContainer()->showPreview(m_xCurrentFrame); InvalidateFeature(SID_DB_QUERY_PREVIEW); -// Reference< XFrame > xBeamer = getContainer()->getPreviewFrame(); -// Reference< XLoadEventListener> xLoadEvtL = new OQueryControllerLoadListener(this); -// xBeamer->addFrameActionListener( xLoadEvtL ); - URL aWantToDispatch; aWantToDispatch.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser"); - ::rtl::OUString sFrameName = FRAME_NAME_QUERY_PREVIEW; - // | FrameSearchFlag::CREATE + ::rtl::OUString sFrameName( FRAME_NAME_QUERY_PREVIEW ); sal_Int32 nSearchFlags = FrameSearchFlag::CHILDREN; Reference< XDispatch> xDisp; @@ -1288,17 +1240,18 @@ aDefaultName = String(::dbtools::createUniqueName(_xElements,aName)); } - + DynamicTableOrQueryNameCheck aNameChecker( getConnection(), CommandType::QUERY ); OSaveAsDlg aDlg( getView(), m_bCreateView ? CommandType::TABLE : CommandType::QUERY, - _xElements, - xMetaData, + getORB(), getConnection(), aDefaultName, - _bSaveAs ? SAD_OVERWRITE : SAD_DEFAULT); + aNameChecker, + SAD_DEFAULT ); - if(bRet = (aDlg.Execute() == RET_OK)) + bRet = ( aDlg.Execute() == RET_OK ); + if ( bRet ) { m_sName = aDlg.getName(); if(m_bCreateView) @@ -1437,11 +1390,7 @@ if ( xElements->hasByName(m_sName) ) xProp2.set(xElements->getByName(m_sName),UNO_QUERY); if ( !xProp2.is() ) // correct name and try again - { - sal_Bool bUseCatalogInSelect = ::dbtools::isDataSourcePropertyEnabled(getDataSource(),PROPERTY_USECATALOGINSELECT,sal_True); - sal_Bool bUseSchemaInSelect = ::dbtools::isDataSourcePropertyEnabled(getDataSource(),PROPERTY_USESCHEMAINSELECT,sal_True); - m_sName = ::dbtools::composeTableName(getMetaData(),xQuery,sal_False,::dbtools::eInDataManipulation,bUseCatalogInSelect,bUseSchemaInSelect); - } + m_sName = ::dbtools::composeTableName( getMetaData(), xQuery, ::dbtools::eInDataManipulation, false, false, false ); // now check if our datasource has set a tablefilter and if append the new table name to it ::dbaui::appendToFilter(getConnection(),m_sName,getORB(),getView()); // we are not interessted in the return value } @@ -1487,13 +1436,14 @@ { ::rtl::OUString aErrorMsg; - ::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree( aErrorMsg, m_sStatement, m_bDesign ); + ::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree( aErrorMsg, m_sStatement, m_bDesign ); if(pNode) { pNode->parseNodeToStr( sTranslatedStmt, getMetaData()); delete pNode; } + m_xComposer->setQuery(sTranslatedStmt); sTranslatedStmt = m_xComposer->getComposedQuery(); } @@ -1622,7 +1572,7 @@ if ( m_bEsacpeProcessing ) { ::rtl::OUString aErrorMsg; - ::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree(aErrorMsg,m_sStatement,m_bDesign); + ::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree(aErrorMsg,m_sStatement,m_bDesign); // m_pParseNode = pNode; if(pNode) { @@ -1631,10 +1581,14 @@ delete m_pSqlIterator->getParseTree(); m_pSqlIterator->setParseTree(pNode); m_pSqlIterator->traverseAll(); - SQLWarning aWarning = m_pSqlIterator->getWarning(); - if(aWarning.Message.getLength()) + if ( m_pSqlIterator->hasErrors() ) { - showError(SQLExceptionInfo(aWarning)); + SQLContext aErrorContext; + aErrorContext.Message = String( ModuleRes( STR_ERROR_PARSING_STATEMENT ) ); + aErrorContext.Context = *this; + aErrorContext.Details = String( ModuleRes( STR_INFO_OPENING_IN_SQL_VIEW ) ); + aErrorContext.NextException <<= m_pSqlIterator->getErrors(); + showError( aErrorContext ); m_bDesign = sal_False; } } @@ -1688,7 +1642,25 @@ Execute( ID_BROWSER_ADDTABLE,Sequence<PropertyValue>() ); return 0L; } + // ----------------------------------------------------------------------------- +bool OQueryController::allowViews() const +{ + return true; +} + +// ----------------------------------------------------------------------------- +bool OQueryController::allowQueries() const +{ + DBG_ASSERT( getSdbMetaData().isConnected(), "OQueryController::allowQueries: illegal call!" ); + if ( !getSdbMetaData().supportsSubqueriesInFrom() ) + return false; + + const NamedValueCollection& rArguments( getInitParams() ); + bool bCreatingView = rArguments.getOrDefault( (::rtl::OUString)PROPERTY_CREATEVIEW, false ); + return !bCreatingView; +} + // ----------------------------------------------------------------------------- } // namespace dbaui // ----------------------------------------------------------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
