2001-02-05 08:35:57 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: querycontroller.cxx,v $
|
|
|
|
*
|
2001-04-30 12:02:01 +00:00
|
|
|
* $Revision: 1.35 $
|
2001-02-05 08:35:57 +00:00
|
|
|
*
|
2001-04-30 12:02:01 +00:00
|
|
|
* last change: $Author: oj $ $Date: 2001-04-30 13:02:01 $
|
2001-02-05 08:35:57 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the License); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an AS IS basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef DBAUI_QUERYCONTROLLER_HXX
|
|
|
|
#include "querycontroller.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_QUERYVIEW_HXX
|
|
|
|
#include "queryview.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _DBAU_REGHELPER_HXX_
|
|
|
|
#include "dbu_reghelper.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _SFXSIDS_HRC
|
|
|
|
#include <sfx2/sfxsids.hrc>
|
|
|
|
#endif
|
|
|
|
#ifndef _DBU_RESOURCE_HRC_
|
|
|
|
#include "dbu_resource.hrc"
|
|
|
|
#endif
|
|
|
|
#ifndef _SV_TOOLBOX_HXX
|
|
|
|
#include <vcl/toolbox.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef DBACCESS_UI_BROWSER_ID_HXX
|
|
|
|
#include "browserids.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_QUERYVIEW_TEXT_HXX
|
|
|
|
#include "QueryTextView.hxx"
|
|
|
|
#endif
|
2001-02-05 15:17:40 +00:00
|
|
|
#ifndef DBAUI_QUERYDESIGNVIEW_HXX
|
2001-02-05 08:35:57 +00:00
|
|
|
#include "QueryDesignView.hxx"
|
2001-02-05 15:17:40 +00:00
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
#ifndef _COMPHELPER_TYPES_HXX_
|
|
|
|
#include <comphelper/types.hxx>
|
|
|
|
#endif
|
2001-04-24 13:28:56 +00:00
|
|
|
#ifndef _SV_MSGBOX_HXX
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
|
|
|
|
#include "dbustrings.hrc"
|
|
|
|
#endif
|
|
|
|
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
|
|
|
|
#include <connectivity/dbtools.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSERFACTORY_HPP_
|
|
|
|
#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
|
|
|
|
#endif
|
2001-04-24 13:28:56 +00:00
|
|
|
#ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
|
|
|
|
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
|
|
|
|
#include <com/sun/star/frame/FrameSearchFlag.hpp>
|
|
|
|
#endif
|
2001-03-15 07:29:16 +00:00
|
|
|
#ifndef _COMPHELPER_EXTRACT_HXX_
|
|
|
|
#include <comphelper/extract.hxx>
|
2001-02-05 08:35:57 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
|
|
|
|
#include <com/sun/star/sdb/CommandType.hpp>
|
|
|
|
#endif
|
2001-04-24 13:28:56 +00:00
|
|
|
#ifndef _COM_SUN_STAR_FRAME_XTASK_HPP_
|
|
|
|
#include <com/sun/star/frame/XTask.hpp>
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
#ifndef DBAUI_DLGSAVE_HXX
|
|
|
|
#include "dlgsave.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
|
|
|
|
#include <com/sun/star/container/XChild.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_
|
|
|
|
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
|
|
|
|
#endif
|
2001-03-14 09:35:11 +00:00
|
|
|
#ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_
|
|
|
|
#include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
|
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
|
|
|
|
#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
|
|
|
|
#include <com/sun/star/sdbcx/XDrop.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
|
|
|
|
#include <com/sun/star/sdbcx/XAppend.hpp>
|
|
|
|
#endif
|
2001-02-06 12:22:12 +00:00
|
|
|
#ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
|
|
|
|
#include <com/sun/star/sdb/SQLContext.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_
|
|
|
|
#include <com/sun/star/sdbc/SQLWarning.hpp>
|
|
|
|
#endif
|
2001-04-24 13:28:56 +00:00
|
|
|
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
|
|
|
|
#include <com/sun/star/sdbc/XRow.hpp>
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
#ifndef _DBHELPER_DBEXCEPTION_HXX_
|
|
|
|
#include <connectivity/dbexception.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_UI_XEXECUTABLEDIALOG_HPP_
|
|
|
|
#include <com/sun/star/ui/XExecutableDialog.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_TABLECONNECTIONDATA_HXX
|
|
|
|
#include "TableConnectionData.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_QYDLGTAB_HXX
|
|
|
|
#include "adtabdlg.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_QUERYVIEWSWITCH_HXX
|
|
|
|
#include "QueryViewSwitch.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _COMPHELPER_STREAMSECTION_HXX_
|
|
|
|
#include <comphelper/streamsection.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _COMPHELPER_BASIC_IO_HXX_
|
|
|
|
#include <comphelper/basicio.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_TABLEFIELDDESC_HXX
|
|
|
|
#include "TableFieldDescription.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_QUERY_TABLEWINDOWDATA_HXX
|
|
|
|
#include "QTableWindowData.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _COMPHELPER_SEQSTREAM_HXX
|
|
|
|
#include <comphelper/seqstream.hxx>
|
|
|
|
#endif
|
2001-04-23 08:30:31 +00:00
|
|
|
#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
|
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataSource.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataSink.hpp>
|
|
|
|
#endif
|
2001-02-05 15:17:40 +00:00
|
|
|
#ifndef DBAUI_QUERY_TABLEWINDOW_HXX
|
|
|
|
#include "QTableWindow.hxx"
|
|
|
|
#endif
|
2001-02-23 14:04:37 +00:00
|
|
|
#ifndef _DBAUI_SQLMESSAGE_HXX_
|
|
|
|
#include "sqlmessage.hxx"
|
|
|
|
#endif
|
2001-04-24 13:28:56 +00:00
|
|
|
#ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_
|
|
|
|
#include <com/sun/star/util/XFlushable.hpp>
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
|
|
extern "C" void SAL_CALL createRegistryInfo_OQueryControl()
|
|
|
|
{
|
|
|
|
static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OQueryController > aAutoRegistration;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::io;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::frame;
|
|
|
|
using namespace ::com::sun::star::util;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::sdbcx;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::sdb;
|
|
|
|
using namespace ::com::sun::star::ui;
|
2001-04-23 08:30:31 +00:00
|
|
|
using namespace ::com::sun::star::awt;
|
2001-02-05 08:35:57 +00:00
|
|
|
using namespace ::connectivity;
|
|
|
|
using namespace ::dbtools;
|
|
|
|
using namespace ::dbaui;
|
|
|
|
using namespace ::comphelper;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
::rtl::OUString SAL_CALL OQueryController::getImplementationName() throw( RuntimeException )
|
|
|
|
{
|
|
|
|
return getImplementationName_Static();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
::rtl::OUString OQueryController::getImplementationName_Static() throw( RuntimeException )
|
|
|
|
{
|
|
|
|
return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.OQueryDesign");
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
Sequence< ::rtl::OUString> OQueryController::getSupportedServiceNames_Static(void) throw( RuntimeException )
|
|
|
|
{
|
|
|
|
Sequence< ::rtl::OUString> aSupported(1);
|
|
|
|
aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.QueryDesign");
|
|
|
|
return aSupported;
|
|
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
Sequence< ::rtl::OUString> SAL_CALL OQueryController::getSupportedServiceNames() throw(RuntimeException)
|
|
|
|
{
|
|
|
|
return getSupportedServiceNames_Static();
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Reference< XInterface > SAL_CALL OQueryController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
|
|
|
|
{
|
|
|
|
return *(new OQueryController(_rxFactory));
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-28 09:18:26 +00:00
|
|
|
OQueryController::OQueryController(const Reference< XMultiServiceFactory >& _rM)
|
|
|
|
: OJoinController(_rM)
|
2001-02-05 08:35:57 +00:00
|
|
|
,m_bDesign(sal_False)
|
|
|
|
,m_bDistinct(sal_False)
|
|
|
|
,m_bViewAlias(sal_False)
|
|
|
|
,m_bViewTable(sal_False)
|
|
|
|
,m_bViewFunction(sal_False)
|
|
|
|
,m_bEsacpeProcessing(sal_True)
|
|
|
|
,m_pSqlIterator(NULL)
|
|
|
|
,m_nSplitPos(-1)
|
|
|
|
,m_nVisibleRows(0x400)
|
2001-04-24 13:28:56 +00:00
|
|
|
,m_bCreateView(sal_False)
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
2001-02-14 13:54:12 +00:00
|
|
|
m_pParseContext = new OQueryParseContext();
|
|
|
|
m_pSqlParser = new OSQLParser(_rM,m_pParseContext);
|
2001-02-05 08:35:57 +00:00
|
|
|
InvalidateAll();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
OQueryController::~OQueryController()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-04-06 12:47:18 +00:00
|
|
|
void OQueryController::deleteIterator()
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
|
|
|
if(m_pSqlIterator)
|
|
|
|
{
|
|
|
|
delete m_pSqlIterator->getParseTree();
|
|
|
|
m_pSqlIterator->dispose();
|
|
|
|
delete m_pSqlIterator;
|
2001-04-06 12:47:18 +00:00
|
|
|
m_pSqlIterator = NULL;
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
2001-04-06 12:47:18 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::disposing()
|
|
|
|
{
|
|
|
|
deleteIterator();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
2001-02-14 13:54:12 +00:00
|
|
|
delete m_pSqlParser;
|
|
|
|
delete m_pParseContext;
|
|
|
|
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
|
|
|
::std::vector< OTableFieldDesc*>::iterator aIter = m_vTableFieldDesc.begin();
|
|
|
|
for(;aIter != m_vTableFieldDesc.end();++aIter)
|
|
|
|
delete *aIter;
|
|
|
|
m_vTableFieldDesc.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pView = NULL;
|
|
|
|
m_pWindow = NULL; // don't delete this window it will be deleted by the frame
|
|
|
|
|
|
|
|
::comphelper::disposeComponent(m_xComposer);
|
2001-03-01 14:17:55 +00:00
|
|
|
OJoinController::disposing();
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
FeatureState OQueryController::GetState(sal_uInt16 _nId)
|
|
|
|
{
|
|
|
|
FeatureState aReturn;
|
2001-03-20 07:15:49 +00:00
|
|
|
aReturn.bEnabled = sal_True;
|
2001-02-05 08:35:57 +00:00
|
|
|
// (disabled automatically)
|
2001-03-14 09:35:11 +00:00
|
|
|
// aReturn.bEnabled = m_xConnection.is();
|
|
|
|
// if(!m_xConnection.is()) // so what should otherwise happen
|
|
|
|
// {
|
|
|
|
// aReturn.aState = ::cppu::bool2any(sal_False);
|
|
|
|
// return aReturn;
|
|
|
|
// }
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
|
|
switch (_nId)
|
|
|
|
{
|
|
|
|
case ID_BROWSER_ESACPEPROCESSING:
|
|
|
|
aReturn.aState = ::cppu::bool2any(!m_bEsacpeProcessing);
|
2001-03-14 11:57:37 +00:00
|
|
|
aReturn.bEnabled = m_pSqlIterator != NULL;
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_EDITDOC:
|
|
|
|
aReturn.aState = ::cppu::bool2any(m_bEditable);
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_SAVEASDOC:
|
2001-04-24 13:28:56 +00:00
|
|
|
aReturn.bEnabled = !m_bCreateView && (!m_bDesign || (m_vTableFieldDesc.size() && m_vTableData.size()));
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_SAVEDOC:
|
2001-03-14 09:35:11 +00:00
|
|
|
aReturn.bEnabled = m_bModified && (!m_bDesign || (m_vTableFieldDesc.size() && m_vTableData.size()));
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case SID_PRINTDOCDIRECT:
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_CUT:
|
2001-04-24 13:28:56 +00:00
|
|
|
aReturn.bEnabled = m_bEditable && m_pWindow && m_pWindow->getView()->isCutAllowed();
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_COPY:
|
2001-04-24 13:28:56 +00:00
|
|
|
aReturn.bEnabled = m_pWindow && m_pWindow->getView()->isCopyAllowed();
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_PASTE:
|
2001-04-24 13:28:56 +00:00
|
|
|
aReturn.bEnabled = m_bEditable && m_pWindow && m_pWindow->getView()->isPasteAllowed();
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_SQL:
|
2001-03-14 09:35:11 +00:00
|
|
|
aReturn.bEnabled = m_bEsacpeProcessing && m_pSqlIterator;
|
2001-02-05 08:35:57 +00:00
|
|
|
aReturn.aState = ::cppu::bool2any(m_bDesign);
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_CLEAR_QUERY:
|
2001-03-20 07:15:49 +00:00
|
|
|
aReturn.bEnabled = m_bEditable && (m_sStatement.getLength() || m_vTableData.size());
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_QUERY_VIEW_FUNCTIONS:
|
|
|
|
case ID_BROWSER_QUERY_VIEW_TABLES:
|
|
|
|
case ID_BROWSER_QUERY_VIEW_ALIASES:
|
2001-04-24 13:28:56 +00:00
|
|
|
aReturn.aState = ::cppu::bool2any(m_pWindow && m_pWindow->getView()->isSlotEnabled(_nId));
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_QUERY_DISTINCT_VALUES:
|
|
|
|
aReturn.aState = ::cppu::bool2any(m_bDistinct);
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_QUERY_EXECUTE:
|
|
|
|
aReturn.bEnabled = sal_True;
|
|
|
|
break;
|
2001-02-28 09:18:26 +00:00
|
|
|
default:
|
|
|
|
aReturn = OJoinController::GetState(_nId);
|
|
|
|
break;
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
return aReturn;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::Execute(sal_uInt16 _nId)
|
|
|
|
{
|
|
|
|
switch(_nId)
|
|
|
|
{
|
|
|
|
case ID_BROWSER_ESACPEPROCESSING:
|
|
|
|
m_bEsacpeProcessing = !m_bEsacpeProcessing;
|
2001-02-07 12:32:20 +00:00
|
|
|
InvalidateFeature(ID_BROWSER_SQL);
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_EDITDOC:
|
|
|
|
m_bEditable = !m_bEditable;
|
2001-03-02 08:31:40 +00:00
|
|
|
m_pWindow->getView()->setReadOnly(!m_bEditable);
|
2001-02-05 08:35:57 +00:00
|
|
|
InvalidateFeature(ID_BROWSER_PASTE);
|
|
|
|
InvalidateFeature(ID_BROWSER_CLEAR_QUERY);
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_SAVEASDOC:
|
|
|
|
case ID_BROWSER_SAVEDOC:
|
2001-04-24 13:28:56 +00:00
|
|
|
doSaveAsDoc(ID_BROWSER_SAVEASDOC == _nId);
|
|
|
|
if(m_bCreateView)
|
|
|
|
closeTask();
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case SID_PRINTDOCDIRECT:
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_CUT:
|
2001-03-02 08:31:40 +00:00
|
|
|
m_pWindow->getView()->cut();
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_COPY:
|
2001-03-02 08:31:40 +00:00
|
|
|
m_pWindow->getView()->copy();
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_PASTE:
|
2001-03-02 08:31:40 +00:00
|
|
|
m_pWindow->getView()->paste();
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_SQL:
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2001-02-14 13:54:12 +00:00
|
|
|
::rtl::OUString aErrorMsg;
|
2001-03-02 08:31:40 +00:00
|
|
|
m_sStatement = m_pWindow->getView()->getStatement();
|
2001-03-14 09:35:11 +00:00
|
|
|
if(!m_sStatement.getLength() && m_pSqlIterator)
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
|
|
|
// change the view of the data
|
|
|
|
delete m_pSqlIterator->getParseTree();
|
|
|
|
m_pSqlIterator->setParseTree(NULL);
|
|
|
|
m_bDesign = !m_bDesign;
|
|
|
|
m_pWindow->switchView();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-14 13:54:12 +00:00
|
|
|
::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree(aErrorMsg,m_sStatement,sal_True);
|
2001-02-05 08:35:57 +00:00
|
|
|
// m_pParseNode = pNode;
|
|
|
|
if(pNode)
|
|
|
|
{
|
|
|
|
delete m_pSqlIterator->getParseTree();
|
|
|
|
m_pSqlIterator->setParseTree(pNode);
|
|
|
|
m_pSqlIterator->traverseAll();
|
2001-02-23 14:04:37 +00:00
|
|
|
SQLWarning aWarning = m_pSqlIterator->getWarning();
|
|
|
|
if(aWarning.Message.getLength())
|
|
|
|
showError(SQLExceptionInfo(aWarning));
|
2001-02-05 08:35:57 +00:00
|
|
|
else
|
|
|
|
{
|
2001-02-23 14:04:37 +00:00
|
|
|
const OSQLTables& xTabs = m_pSqlIterator->getTables();
|
2001-02-28 09:18:26 +00:00
|
|
|
if( m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT && m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT_COUNT || xTabs.begin() == xTabs.end())
|
2001-02-23 14:04:37 +00:00
|
|
|
{
|
|
|
|
ErrorBox aBox( getQueryView(), ModuleRes( ERR_QRY_NOSELECT ) );
|
|
|
|
aBox.Execute();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// change the view of the data
|
|
|
|
m_bDesign = !m_bDesign;
|
|
|
|
m_sStatement = ::rtl::OUString();
|
|
|
|
pNode->parseNodeToStr( m_sStatement,
|
|
|
|
m_xConnection->getMetaData(),
|
|
|
|
&getParser()->getContext(),
|
|
|
|
sal_True,sal_True);
|
2001-02-28 09:18:26 +00:00
|
|
|
m_pWindow->getView()->SaveUIConfig();
|
2001-02-23 14:04:37 +00:00
|
|
|
m_pWindow->switchView();
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ErrorBox aBox( getQueryView(), ModuleRes( ERR_QRY_SYNTAX ) );
|
|
|
|
aBox.Execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(SQLException& e)
|
|
|
|
{
|
|
|
|
::dbtools::SQLExceptionInfo aInfo(e);
|
|
|
|
showError(aInfo);
|
|
|
|
}
|
|
|
|
catch(Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if(m_bDesign)
|
|
|
|
InvalidateFeature(ID_BROWSER_ADDTABLE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_CLEAR_QUERY:
|
2001-04-30 12:02:01 +00:00
|
|
|
{
|
|
|
|
m_aUndoManager.EnterListAction( String( ModuleRes(STR_QUERY_UNDO_TABWINDELETE) ), String() );
|
|
|
|
m_pWindow->getView()->clear();
|
|
|
|
m_aUndoManager.LeaveListAction();
|
|
|
|
|
|
|
|
m_sStatement = ::rtl::OUString();
|
|
|
|
if(m_bDesign)
|
|
|
|
InvalidateFeature(ID_BROWSER_ADDTABLE);
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
// InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_QUERY_VIEW_FUNCTIONS:
|
|
|
|
case ID_BROWSER_QUERY_VIEW_TABLES:
|
|
|
|
case ID_BROWSER_QUERY_VIEW_ALIASES:
|
2001-02-28 09:18:26 +00:00
|
|
|
m_pWindow->getView()->setSlotEnabled(_nId,!m_pWindow->getView()->isSlotEnabled(_nId));
|
2001-02-05 08:35:57 +00:00
|
|
|
break;
|
|
|
|
case ID_BROWSER_QUERY_DISTINCT_VALUES:
|
|
|
|
m_bDistinct = !m_bDistinct;
|
|
|
|
break;
|
|
|
|
case ID_BROWSER_QUERY_EXECUTE:
|
|
|
|
{
|
2001-04-02 09:18:50 +00:00
|
|
|
executeQuery();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_QUERY_ZOOM_IN:
|
|
|
|
{
|
|
|
|
// m_aZoom *= Fraction(1,10);
|
|
|
|
// static_cast<OQueryViewSwitch*>(getQueryView())->zoomTableView(m_aZoom);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_QUERY_ZOOM_OUT:
|
|
|
|
{
|
|
|
|
// if(m_aZoom != Fraction(1,1))
|
|
|
|
// m_aZoom /= Fraction(1,10);
|
|
|
|
// static_cast<OQueryViewSwitch*>(getQueryView())->zoomTableView(m_aZoom);
|
|
|
|
}
|
|
|
|
break;
|
2001-02-28 09:18:26 +00:00
|
|
|
default:
|
|
|
|
OJoinController::Execute(_nId);
|
|
|
|
return; // else we would invalidate twice
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
InvalidateFeature(_nId);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OQueryController::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
|
|
|
|
{
|
2001-04-24 13:28:56 +00:00
|
|
|
|
2001-03-12 14:09:37 +00:00
|
|
|
OJoinController::initialize(aArguments);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
|
|
// m_pWindow->initialize(m_xCurrentFrame);
|
|
|
|
|
|
|
|
PropertyValue aValue;
|
|
|
|
const Any* pBegin = aArguments.getConstArray();
|
|
|
|
const Any* pEnd = pBegin + aArguments.getLength();
|
|
|
|
|
|
|
|
for(;pBegin != pEnd;++pBegin)
|
|
|
|
{
|
|
|
|
if((*pBegin >>= aValue) && aValue.Name == PROPERTY_ACTIVECONNECTION)
|
|
|
|
{
|
2001-02-14 13:54:12 +00:00
|
|
|
::cppu::extractInterface(m_xConnection,aValue.Value);
|
2001-02-05 08:35:57 +00:00
|
|
|
// be notified when connection is in disposing
|
|
|
|
Reference< XComponent > xComponent(m_xConnection, UNO_QUERY);
|
|
|
|
if (xComponent.is())
|
|
|
|
{
|
|
|
|
Reference< ::com::sun::star::lang::XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
|
|
|
|
xComponent->addEventListener(xEvtL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(aValue.Name == PROPERTY_DATASOURCENAME)
|
|
|
|
{
|
|
|
|
aValue.Value >>= m_sDataSourceName;
|
|
|
|
}
|
|
|
|
else if(aValue.Name == PROPERTY_CURRENTQUERY)
|
|
|
|
{
|
|
|
|
aValue.Value >>= m_sName;
|
|
|
|
}
|
|
|
|
else if(aValue.Name == PROPERTY_QUERYDESIGNVIEW)
|
|
|
|
{
|
|
|
|
m_bDesign = ::cppu::any2bool(aValue.Value);
|
|
|
|
}
|
2001-04-24 13:28:56 +00:00
|
|
|
else if(aValue.Name == PROPERTY_CREATEVIEW)
|
|
|
|
{
|
|
|
|
m_bCreateView = ::cppu::any2bool(aValue.Value);
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_xConnection.is())
|
|
|
|
{ // whoever instantiated us did not give us a connection to share. Okay, create an own one
|
|
|
|
createNewConnection(sal_False);
|
|
|
|
}
|
2001-04-24 13:28:56 +00:00
|
|
|
if (!m_xConnection.is())
|
|
|
|
{ // we have no connection so what else should we do
|
2001-02-23 14:04:37 +00:00
|
|
|
m_bDesign = sal_False;
|
2001-04-24 13:28:56 +00:00
|
|
|
if(m_bCreateView)
|
|
|
|
{
|
|
|
|
String aMessage(ModuleRes(RID_STR_CONNECTION_LOST));
|
|
|
|
ODataView* pWindow = getView();
|
|
|
|
InfoBox(pWindow, aMessage).Execute();
|
|
|
|
Reference<XTask> xTask(m_xCurrentFrame,UNO_QUERY);
|
|
|
|
if(xTask.is())
|
|
|
|
{
|
|
|
|
xTask->close();
|
|
|
|
throw SQLException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-23 14:04:37 +00:00
|
|
|
|
2001-03-14 09:35:11 +00:00
|
|
|
// we need a datasource
|
|
|
|
if(m_xConnection.is())
|
|
|
|
{
|
|
|
|
Reference<XChild> xChild(m_xConnection,UNO_QUERY);
|
|
|
|
if(xChild.is())
|
|
|
|
m_xDataSource = Reference< XPropertySet >(xChild->getParent(),UNO_QUERY);
|
2001-04-24 13:28:56 +00:00
|
|
|
// now we have to check if our database supports views
|
|
|
|
if(m_bCreateView)
|
|
|
|
{
|
|
|
|
static ::rtl::OUString sView = ::rtl::OUString::createFromAscii("VIEW");
|
|
|
|
Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
|
|
|
|
Reference<XResultSet> xRes = xMeta->getTableTypes();
|
|
|
|
sal_Bool bFound = sal_False;
|
|
|
|
if(xRes.is())
|
|
|
|
{
|
|
|
|
Reference<XRow> xRow(xRes,UNO_QUERY);
|
|
|
|
while(xRes->next())
|
|
|
|
{
|
|
|
|
::rtl::OUString sValue = xRow->getString(1);
|
|
|
|
if(!xRow->wasNull() && sValue == sView)
|
|
|
|
bFound = sal_True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!bFound)
|
|
|
|
{ // we can't create views so we ask if the user wants to create a query instead
|
|
|
|
m_bCreateView = sal_False;
|
|
|
|
sal_Bool bClose = sal_False;
|
|
|
|
{
|
|
|
|
String aTitle(ModuleRes(STR_QUERYDESIGN_NO_VIEW_SUPPORT));
|
|
|
|
String aMessage(ModuleRes(STR_QUERYDESIGN_NO_VIEW_ASK));
|
|
|
|
ODataView* pWindow = getView();
|
|
|
|
OSQLMessageBox aDlg(pWindow,aTitle, aMessage,WB_YES_NO|WB_DEF_YES,OSQLMessageBox::Query);
|
|
|
|
bClose = aDlg.Execute() == RET_NO;
|
|
|
|
}
|
|
|
|
if(bClose)
|
|
|
|
{
|
|
|
|
Reference<XTask> xTask(m_xCurrentFrame,UNO_QUERY);
|
|
|
|
if(xTask.is())
|
|
|
|
{
|
|
|
|
xTask->close();
|
|
|
|
throw SQLException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-14 09:35:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Reference<XNameAccess> xDatabaseContext = Reference< XNameAccess >(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
|
|
|
|
xDatabaseContext->getByName(m_sDataSourceName) >>= m_xDataSource;
|
|
|
|
OSL_ENSURE(m_xDataSource.is(),"We need a datasource!");
|
|
|
|
}
|
2001-04-24 13:28:56 +00:00
|
|
|
try
|
|
|
|
{
|
2001-02-05 08:35:57 +00:00
|
|
|
// get command from the query if a query name was supplied
|
|
|
|
if(m_sName.getLength())
|
|
|
|
{
|
2001-04-24 13:28:56 +00:00
|
|
|
OSL_ENSURE(!m_bCreateView,"Can not support a name for a view!");
|
|
|
|
Reference<XNameAccess> xQueries = getElements();
|
2001-03-14 09:35:11 +00:00
|
|
|
if(xQueries.is())
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
|
|
|
Reference<XPropertySet> xProp;
|
2001-03-14 09:35:11 +00:00
|
|
|
if(xQueries->hasByName(m_sName) && ::cppu::extractInterface(xProp,xQueries->getByName(m_sName)) && xProp.is())
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
|
|
|
xProp->getPropertyValue(PROPERTY_COMMAND) >>= m_sStatement;
|
2001-02-07 12:32:20 +00:00
|
|
|
m_bEsacpeProcessing = ::cppu::any2bool(xProp->getPropertyValue(PROPERTY_USE_ESCAPE_PROCESSING));
|
2001-02-05 08:35:57 +00:00
|
|
|
// load the layoutInformation
|
2001-02-07 11:44:13 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Sequence< sal_Int8 > aInputSequence;
|
|
|
|
xProp->getPropertyValue(PROPERTY_LAYOUTINFORMATION) >>= aInputSequence;
|
|
|
|
{
|
|
|
|
Reference< XInputStream> xInStreamHelper = new SequenceInputStream(aInputSequence);; // used for wrapping sequence to xinput
|
|
|
|
Reference< XObjectInputStream> xInStream = Reference< XObjectInputStream >(getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.ObjectInputStream")),UNO_QUERY);
|
|
|
|
Reference< XInputStream> xMarkInStream = Reference< XInputStream >(getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.MarkableInputStream")),UNO_QUERY);
|
|
|
|
Reference< XActiveDataSink >(xMarkInStream,UNO_QUERY)->setInputStream(xInStreamHelper);
|
|
|
|
Reference< XActiveDataSink > xInDataSource(xInStream, UNO_QUERY);
|
|
|
|
OSL_ENSURE(xInDataSource.is(),"Couldn't create com.sun.star.io.ObjectInputStream!");
|
|
|
|
xInDataSource->setInputStream(xMarkInStream);
|
|
|
|
Load(xInStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception&)
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
setQueryComposer();
|
|
|
|
::rtl::OUString aErrorMsg;
|
2001-02-14 13:54:12 +00:00
|
|
|
::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree(aErrorMsg,m_sStatement,sal_True);
|
2001-02-05 08:35:57 +00:00
|
|
|
// m_pParseNode = pNode;
|
|
|
|
if(pNode)
|
|
|
|
{
|
2001-03-14 09:35:11 +00:00
|
|
|
if(m_pSqlIterator)
|
2001-02-23 14:04:37 +00:00
|
|
|
{
|
2001-03-14 09:35:11 +00:00
|
|
|
delete m_pSqlIterator->getParseTree();
|
|
|
|
m_pSqlIterator->setParseTree(pNode);
|
|
|
|
m_pSqlIterator->traverseAll();
|
|
|
|
SQLWarning aWarning = m_pSqlIterator->getWarning();
|
|
|
|
if(aWarning.Message.getLength())
|
|
|
|
{
|
|
|
|
showError(SQLExceptionInfo(aWarning));
|
|
|
|
m_bDesign = sal_False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete pNode;
|
2001-02-23 14:04:37 +00:00
|
|
|
m_bDesign = sal_False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String aTitle(ModuleRes(STR_SVT_SQL_SYNTAX_ERROR));
|
|
|
|
OSQLMessageBox aDlg(getView(),aTitle,aErrorMsg);
|
|
|
|
aDlg.Execute();
|
|
|
|
m_bDesign = sal_False; // the statement can't be parsed so we show the text view
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-14 09:35:11 +00:00
|
|
|
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
setQueryComposer();
|
2001-03-14 09:35:11 +00:00
|
|
|
if(!m_xFormatter.is() && m_xDataSource.is())
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
2001-03-14 09:35:11 +00:00
|
|
|
Reference< XNumberFormatsSupplier> xSupplier;
|
|
|
|
::cppu::extractInterface(xSupplier,m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER));
|
|
|
|
if(xSupplier.is())
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
2001-03-14 09:35:11 +00:00
|
|
|
m_xFormatter = Reference< ::com::sun::star::util::XNumberFormatter >(getORB()
|
|
|
|
->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatter")), UNO_QUERY);
|
|
|
|
m_xFormatter->attachNumberFormatsSupplier(xSupplier);
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
2001-03-14 09:35:11 +00:00
|
|
|
OSL_ENSURE(m_xFormatter.is(),"No NumberFormatter!");
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
2001-02-28 09:18:26 +00:00
|
|
|
m_pWindow->getView()->initialize();
|
2001-02-06 08:31:46 +00:00
|
|
|
getUndoMgr()->Clear();
|
2001-03-12 14:09:37 +00:00
|
|
|
if(m_bDesign && !m_sName.getLength())
|
2001-02-16 15:03:51 +00:00
|
|
|
Execute(ID_BROWSER_ADDTABLE);
|
2001-02-06 08:31:46 +00:00
|
|
|
setModified(sal_False);
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
catch(SQLException&)
|
|
|
|
{
|
2001-04-03 13:16:03 +00:00
|
|
|
OSL_ENSURE(sal_False, "OQueryController::initialize: caught an exception!");
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::setQueryComposer()
|
|
|
|
{
|
|
|
|
if(m_xConnection.is())
|
|
|
|
{
|
|
|
|
Reference< XSQLQueryComposerFactory > xFactory(m_xConnection, UNO_QUERY);
|
|
|
|
OSL_ENSURE(xFactory.is(),"Connection doesn't support a querycomposer");
|
|
|
|
if (xFactory.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_xComposer = xFactory->createQueryComposer();
|
2001-03-02 08:31:40 +00:00
|
|
|
m_pWindow->getView()->setStatement(m_sStatement);
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
catch (Exception&)
|
|
|
|
{
|
|
|
|
m_xComposer = NULL;
|
|
|
|
}
|
|
|
|
OSL_ENSURE(m_xComposer.is(),"No querycomposer available!");
|
|
|
|
Reference<XTablesSupplier> xTablesSup(m_xConnection, UNO_QUERY);
|
2001-04-06 12:47:18 +00:00
|
|
|
deleteIterator();
|
2001-02-23 14:04:37 +00:00
|
|
|
m_pSqlIterator = new ::connectivity::OSQLParseTreeIterator(xTablesSup->getTables(),m_xConnection->getMetaData(),NULL,m_pSqlParser);
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-04-23 08:30:31 +00:00
|
|
|
Reference< XWindow > OQueryController::getComponentWindow()
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
2001-04-23 08:30:31 +00:00
|
|
|
return VCLUnoHelper::GetInterface(m_pWindow);
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
sal_Bool OQueryController::Construct(Window* pParent)
|
|
|
|
{
|
|
|
|
// TODO: we have to check if we should create the text- or the design- view
|
|
|
|
m_pWindow = new OQueryContainerWindow(pParent,this,m_xMultiServiceFacatory);
|
|
|
|
// OQueryTextView *pView = new OQueryTextView(pParent,this,m_xMultiServiceFacatory);
|
|
|
|
m_pWindow->getView()->Construct(NULL);
|
|
|
|
// m_pView = pView;
|
2001-02-28 09:18:26 +00:00
|
|
|
m_pView = m_pWindow->getView()->getRealView();
|
2001-02-05 08:35:57 +00:00
|
|
|
OGenericUnoController::Construct(pParent);
|
|
|
|
// getView()->Show();
|
|
|
|
m_pWindow->Show();
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OQueryController::propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OQueryController::elementInserted(const ::com::sun::star::container::ContainerEvent& Event) throw( RuntimeException )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OQueryController::elementRemoved(const ::com::sun::star::container::ContainerEvent& Event) throw( RuntimeException )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OQueryController::elementReplaced(const ::com::sun::star::container::ContainerEvent& Event) throw( RuntimeException )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
sal_Bool SAL_CALL OQueryController::suspend(sal_Bool bSuspend) throw( RuntimeException )
|
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
sal_Bool bRet = sal_True;
|
2001-02-23 14:04:37 +00:00
|
|
|
if(m_xConnection.is() && m_bModified && (!m_bDesign || (m_vTableFieldDesc.size() && m_vTableData.size())))
|
|
|
|
{
|
|
|
|
QueryBox aQry(getView(), ModuleRes(QUERY_DESIGN_SAVEMODIFIED));
|
|
|
|
switch (aQry.Execute())
|
|
|
|
{
|
|
|
|
case RET_YES:
|
2001-04-26 12:34:47 +00:00
|
|
|
doSaveAsDoc(sal_False);
|
|
|
|
bRet = m_sName.getLength() != 0;
|
2001-02-23 14:04:37 +00:00
|
|
|
break;
|
|
|
|
case RET_CANCEL:
|
2001-04-26 12:34:47 +00:00
|
|
|
bRet = sal_False;
|
2001-02-23 14:04:37 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
return bRet;
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::AddSupportedFeatures()
|
|
|
|
{
|
2001-04-24 13:28:56 +00:00
|
|
|
OJoinController::AddSupportedFeatures();
|
|
|
|
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:Copy")] = ID_BROWSER_COPY;
|
|
|
|
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:Cut")] = ID_BROWSER_CUT;
|
|
|
|
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:Paste")] = ID_BROWSER_PASTE;
|
2001-02-05 08:35:57 +00:00
|
|
|
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:SaveAsDoc")] = SID_SAVEASDOC;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
ToolBox* OQueryController::CreateToolBox(Window* _pParent)
|
|
|
|
{
|
|
|
|
if(m_pView)
|
|
|
|
return m_pView->getToolBox();
|
|
|
|
return new ToolBox(_pParent, ModuleRes(RID_BRW_QUERYDESIGN_TOOLBOX));
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::setModified(sal_Bool _bModified)
|
|
|
|
{
|
2001-02-28 09:18:26 +00:00
|
|
|
OJoinController::setModified(_bModified);
|
2001-02-05 08:35:57 +00:00
|
|
|
InvalidateFeature(ID_BROWSER_CLEAR_QUERY);
|
|
|
|
InvalidateFeature(ID_BROWSER_SAVEASDOC);
|
|
|
|
InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OQueryController::disposing( const EventObject& Source ) throw(RuntimeException)
|
|
|
|
{
|
2001-02-28 09:18:26 +00:00
|
|
|
if(Reference<XFrame>(Source.Source,UNO_QUERY).is())
|
2001-02-05 08:35:57 +00:00
|
|
|
{ // the beamer was closed so resize our window
|
|
|
|
m_pWindow->hideBeamer();
|
|
|
|
}
|
2001-02-28 09:18:26 +00:00
|
|
|
else
|
|
|
|
OJoinController::disposing(Source);
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::createNewConnection(sal_Bool _bUI)
|
|
|
|
{
|
2001-04-06 12:47:18 +00:00
|
|
|
deleteIterator();
|
2001-02-05 08:35:57 +00:00
|
|
|
::comphelper::disposeComponent(m_xComposer);
|
2001-03-14 09:35:11 +00:00
|
|
|
|
2001-02-28 09:18:26 +00:00
|
|
|
OJoinController::createNewConnection(_bUI);
|
|
|
|
if (m_xConnection.is())
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
2001-02-28 09:18:26 +00:00
|
|
|
// 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();
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
2001-03-14 09:35:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(m_bDesign)
|
|
|
|
{
|
|
|
|
m_bDesign = sal_False;
|
|
|
|
// don't call Execute(SQL) because this changes the sql statement
|
|
|
|
m_pWindow->switchView();
|
|
|
|
}
|
|
|
|
InvalidateAll();
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::Save(const Reference< XObjectOutputStream>& _rxOut)
|
|
|
|
{
|
2001-02-28 09:18:26 +00:00
|
|
|
OJoinController::Save(_rxOut);
|
2001-02-05 08:35:57 +00:00
|
|
|
OStreamSection aSection(_rxOut.get());
|
|
|
|
|
|
|
|
// some data
|
|
|
|
_rxOut << m_nSplitPos;
|
|
|
|
_rxOut << m_nVisibleRows;
|
|
|
|
|
|
|
|
// the fielddata
|
|
|
|
_rxOut << (sal_Int32)m_vTableFieldDesc.size();
|
|
|
|
::std::vector<OTableFieldDesc*>::const_iterator aFieldIter = m_vTableFieldDesc.begin();
|
|
|
|
for(;aFieldIter != m_vTableFieldDesc.end();++aFieldIter)
|
|
|
|
(*aFieldIter)->Save(_rxOut);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::Load(const Reference< XObjectInputStream>& _rxIn)
|
|
|
|
{
|
2001-02-28 09:18:26 +00:00
|
|
|
OJoinController::Load(_rxIn);
|
2001-02-05 08:35:57 +00:00
|
|
|
OStreamSection aSection(_rxIn.get());
|
2001-02-07 11:44:13 +00:00
|
|
|
try
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
2001-02-07 11:44:13 +00:00
|
|
|
// some data
|
|
|
|
_rxIn >> m_nSplitPos;
|
|
|
|
_rxIn >> m_nVisibleRows;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
2001-02-07 11:44:13 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Liste loeschen
|
|
|
|
::std::vector< OTableFieldDesc*>::iterator aFieldIter = m_vTableFieldDesc.begin();
|
|
|
|
for(;aFieldIter != m_vTableFieldDesc.end();++aFieldIter)
|
|
|
|
delete *aFieldIter;
|
|
|
|
m_vTableFieldDesc.clear();
|
|
|
|
|
2001-02-28 09:18:26 +00:00
|
|
|
sal_Int32 nCount = 0;
|
2001-02-07 11:44:13 +00:00
|
|
|
_rxIn >> nCount;
|
|
|
|
for(sal_Int32 j=0;j<nCount;++j)
|
|
|
|
{
|
|
|
|
OTableFieldDesc* pData = new OTableFieldDesc();
|
|
|
|
pData->Load(_rxIn);
|
|
|
|
m_vTableFieldDesc.push_back(pData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception&)
|
2001-02-05 08:35:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2001-03-01 12:29:19 +00:00
|
|
|
|
2001-02-05 15:17:40 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2001-03-01 12:29:19 +00:00
|
|
|
OTableWindowData* OQueryController::createTableWindowData()
|
|
|
|
{
|
|
|
|
return new OQueryTableWindowData();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-04-24 13:28:56 +00:00
|
|
|
Reference<XNameAccess> OQueryController::getElements() const
|
2001-03-14 09:35:11 +00:00
|
|
|
{
|
2001-04-24 13:28:56 +00:00
|
|
|
Reference<XNameAccess> xElements;
|
|
|
|
if(m_bCreateView)
|
|
|
|
{
|
|
|
|
Reference<XViewsSupplier> xConSup(m_xConnection,UNO_QUERY);
|
|
|
|
if(xConSup.is())
|
|
|
|
xElements = xConSup->getViews();
|
|
|
|
}
|
2001-03-14 09:35:11 +00:00
|
|
|
else
|
|
|
|
{
|
2001-04-24 13:28:56 +00:00
|
|
|
Reference<XQueriesSupplier> xConSup(m_xConnection,UNO_QUERY);
|
|
|
|
if(xConSup.is())
|
|
|
|
xElements = xConSup->getQueries();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Reference<XQueryDefinitionsSupplier> xSup(m_xDataSource,UNO_QUERY);
|
|
|
|
if(xSup.is())
|
|
|
|
xElements = xSup->getQueryDefinitions();
|
|
|
|
}
|
2001-03-14 09:35:11 +00:00
|
|
|
}
|
2001-04-24 13:28:56 +00:00
|
|
|
return xElements;
|
2001-03-14 09:35:11 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-04-02 09:18:50 +00:00
|
|
|
void OQueryController::executeQuery()
|
|
|
|
{
|
|
|
|
// we don't need to check the connection here because we already check the composer
|
|
|
|
// which can't live without his connection
|
|
|
|
m_sStatement = m_pWindow->getView()->getStatement();
|
|
|
|
::rtl::OUString sTranslatedStmt;
|
|
|
|
if(m_sStatement.getLength() && m_xComposer.is() && m_bEsacpeProcessing)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
::rtl::OUString aErrorMsg;
|
|
|
|
::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree(aErrorMsg,m_sStatement,sal_True);
|
|
|
|
// m_pParseNode = pNode;
|
|
|
|
if(pNode)
|
|
|
|
{
|
|
|
|
pNode->parseNodeToStr( sTranslatedStmt,
|
|
|
|
m_xConnection->getMetaData());
|
|
|
|
delete pNode;
|
|
|
|
}
|
|
|
|
m_xComposer->setQuery(sTranslatedStmt);
|
|
|
|
sTranslatedStmt = m_xComposer->getComposedQuery();
|
|
|
|
}
|
|
|
|
catch(SQLException& e)
|
|
|
|
{
|
|
|
|
::dbtools::SQLExceptionInfo aInfo(e);
|
|
|
|
showError(aInfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sTranslatedStmt = m_sStatement;
|
|
|
|
if(m_sDataSourceName.getLength() && sTranslatedStmt.getLength())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
URL aWantToDispatch;
|
|
|
|
aWantToDispatch.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser");
|
|
|
|
|
|
|
|
::rtl::OUString sFrameName = ::rtl::OUString::createFromAscii("_beamer");
|
|
|
|
// | ::com::sun::star::frame::FrameSearchFlag::CREATE
|
|
|
|
sal_Int32 nSearchFlags = FrameSearchFlag::CHILDREN;
|
|
|
|
m_pWindow->showBeamer(m_xCurrentFrame);
|
|
|
|
|
|
|
|
Reference< ::com::sun::star::frame::XDispatch> xDisp;
|
|
|
|
Reference< ::com::sun::star::frame::XDispatchProvider> xProv(m_xCurrentFrame->findFrame(sFrameName,nSearchFlags),UNO_QUERY);
|
|
|
|
if(!xProv.is())
|
|
|
|
{
|
|
|
|
xProv = Reference< ::com::sun::star::frame::XDispatchProvider>(m_xCurrentFrame, UNO_QUERY);
|
|
|
|
if (xProv.is())
|
|
|
|
xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, nSearchFlags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, FrameSearchFlag::SELF);
|
|
|
|
}
|
|
|
|
if (xDisp.is())
|
|
|
|
{
|
|
|
|
Sequence< PropertyValue> aProps(10);
|
|
|
|
aProps[0].Name = PROPERTY_DATASOURCENAME;
|
|
|
|
aProps[0].Value <<= m_sDataSourceName;
|
|
|
|
|
|
|
|
aProps[1].Name = PROPERTY_COMMANDTYPE;
|
|
|
|
aProps[1].Value <<= CommandType::COMMAND;
|
|
|
|
|
|
|
|
aProps[2].Name = PROPERTY_COMMAND;
|
|
|
|
aProps[2].Value <<= sTranslatedStmt;
|
|
|
|
|
|
|
|
aProps[3].Name = PROPERTY_SHOWTREEVIEW;
|
|
|
|
aProps[3].Value = ::cppu::bool2any(sal_False);
|
|
|
|
|
|
|
|
aProps[4].Name = PROPERTY_SHOWTREEVIEWBUTTON;
|
|
|
|
aProps[4].Value = ::cppu::bool2any(sal_False);
|
|
|
|
|
|
|
|
aProps[5].Name = PROPERTY_ACTIVECONNECTION;
|
|
|
|
aProps[5].Value <<= m_xConnection;
|
|
|
|
|
|
|
|
aProps[6].Name = PROPERTY_UPDATE_CATALOGNAME;
|
|
|
|
aProps[6].Value <<= m_sUpdateCatalogName;
|
|
|
|
|
|
|
|
aProps[7].Name = PROPERTY_UPDATE_SCHEMANAME;
|
|
|
|
aProps[7].Value <<= m_sUpdateSchemaName;
|
|
|
|
|
|
|
|
aProps[8].Name = PROPERTY_UPDATE_TABLENAME;
|
|
|
|
aProps[8].Value <<= m_sUpdateTableName;
|
|
|
|
|
|
|
|
aProps[9].Name = PROPERTY_USE_ESCAPE_PROCESSING;
|
|
|
|
aProps[9].Value = ::cppu::bool2any(m_bEsacpeProcessing);
|
|
|
|
|
|
|
|
xDisp->dispatch(aWantToDispatch, aProps);
|
|
|
|
// check the state of the beamer
|
|
|
|
// be notified when the beamer frame is closed
|
|
|
|
Reference< XComponent > xComponent(m_xCurrentFrame->findFrame(sFrameName,nSearchFlags), UNO_QUERY);
|
|
|
|
if (xComponent.is())
|
|
|
|
{
|
|
|
|
Reference< ::com::sun::star::lang::XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
|
|
|
|
xComponent->addEventListener(xEvtL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ENSURE(0,"Couldn't create a beamer window!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(0,"Couldn't create a beamer window!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Bool bAllEmpty = sal_True;
|
|
|
|
::std::vector< OTableFieldDesc*>::const_iterator aIter = m_vTableFieldDesc.begin();
|
|
|
|
for(;bAllEmpty && aIter != m_vTableFieldDesc.end();++aIter)
|
|
|
|
bAllEmpty = (*aIter)->IsEmpty();
|
|
|
|
|
2001-04-26 09:32:27 +00:00
|
|
|
ErrorBox aBox(getQueryView(), ModuleRes(bAllEmpty ? ERR_QRY_NOCRITERIA : ERR_QRY_NOSTATEMENT));
|
|
|
|
aBox.Execute();
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
String OQueryController::getMenu() const
|
|
|
|
{
|
|
|
|
return String::CreateFromInt32(RID_QUERY_DESIGN_MAIN_MENU);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::askForNewName(const Reference<XNameAccess>& _xElements,sal_Bool _bSaveAs)
|
|
|
|
{
|
|
|
|
sal_Bool bNew = 0 == m_sName.getLength();
|
|
|
|
bNew = bNew || _bSaveAs;
|
|
|
|
if(bNew)
|
|
|
|
{
|
|
|
|
String aDefaultName;
|
|
|
|
if(_bSaveAs && !bNew)
|
|
|
|
aDefaultName = String(m_sName);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String aName = String(ModuleRes(m_bCreateView ? STR_VIEW_TITLE : STR_QRY_TITLE));
|
|
|
|
aName = aName.GetToken(0,' ');
|
|
|
|
aDefaultName = String(::dbtools::createUniqueName(_xElements,aName));
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference<XDatabaseMetaData> xMeta;
|
|
|
|
if(m_xConnection.is())
|
|
|
|
xMeta = m_xConnection->getMetaData();
|
|
|
|
OSaveAsDlg aDlg(
|
|
|
|
getView(), m_bCreateView ? CommandType::TABLE : CommandType::QUERY, _xElements,
|
|
|
|
xMeta, aDefaultName,
|
|
|
|
_bSaveAs ? SAD_OVERWRITE : SAD_DEFAULT);
|
|
|
|
|
|
|
|
if(aDlg.Execute() == RET_OK)
|
|
|
|
{
|
|
|
|
m_sName = aDlg.getName();
|
|
|
|
if(m_bCreateView)
|
|
|
|
{
|
|
|
|
m_sUpdateCatalogName = aDlg.getCatalog();
|
|
|
|
m_sUpdateSchemaName = aDlg.getSchema();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryController::doSaveAsDoc(sal_Bool _bSaveAs)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(m_bEditable,"Slot ID_BROWSER_SAVEDOC should not be enabled!");
|
|
|
|
|
|
|
|
Reference<XNameAccess> xElements = getElements();
|
|
|
|
if(xElements.is())
|
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
::rtl::OUString sTranslatedStmt = translateStatement();
|
2001-04-24 13:28:56 +00:00
|
|
|
|
2001-04-26 12:34:47 +00:00
|
|
|
if(sTranslatedStmt.getLength())
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
sal_Bool bNew = 0 == m_sName.getLength();
|
|
|
|
bNew = bNew || _bSaveAs;
|
|
|
|
// first we need a name for our query so ask the user
|
|
|
|
askForNewName(xElements,_bSaveAs);
|
2001-04-24 13:28:56 +00:00
|
|
|
|
2001-04-26 12:34:47 +00:00
|
|
|
// did we get a name
|
|
|
|
if(m_sName.getLength())
|
|
|
|
{
|
|
|
|
SQLExceptionInfo aInfo;
|
|
|
|
try
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
Reference<XPropertySet> xProp;
|
|
|
|
if(bNew || !xElements->hasByName(m_sName)) // just to make sure the query already exists
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
if(xElements->hasByName(m_sName))
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
Reference<XDrop> xNameCont(xElements,UNO_QUERY);
|
|
|
|
OSL_ENSURE(xNameCont.is(),"Can not drop query!");
|
|
|
|
if(xNameCont.is())
|
|
|
|
xNameCont->dropByName(m_sName);
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
|
|
|
|
Reference<XDataDescriptorFactory> xFact(xElements,UNO_QUERY);
|
|
|
|
OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
|
|
|
|
xProp = xFact->createDataDescriptor();
|
|
|
|
OSL_ENSURE(xProp.is(),"OQueryController::Execute ID_BROWSER_SAVEDOC: Create query failed!");
|
|
|
|
// to set the name is only allowed when the wuery is new
|
|
|
|
xProp->setPropertyValue(PROPERTY_NAME,makeAny(m_sName));
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
else
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
::cppu::extractInterface(xProp,xElements->getByName(m_sName));
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-26 12:34:47 +00:00
|
|
|
xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(sTranslatedStmt));
|
2001-04-24 13:28:56 +00:00
|
|
|
|
2001-04-26 12:34:47 +00:00
|
|
|
// some properties are only valid for a query object
|
2001-04-24 13:28:56 +00:00
|
|
|
if(m_bCreateView)
|
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
xProp->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(m_sUpdateCatalogName));
|
|
|
|
xProp->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(m_sUpdateSchemaName));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xProp->setPropertyValue(CONFIGKEY_QRYDESCR_UPDATE_TABLENAME,makeAny(m_sUpdateTableName));
|
|
|
|
xProp->setPropertyValue(CONFIGKEY_QRYDESCR_UPDATE_CATALOGNAME,makeAny(m_sUpdateCatalogName));
|
|
|
|
xProp->setPropertyValue(CONFIGKEY_QRYDESCR_UPDATE_SCHEMANAME,makeAny(m_sUpdateSchemaName));
|
|
|
|
xProp->setPropertyValue(CONFIGKEY_QRYDESCR_USE_ESCAPE_PROCESSING,::cppu::bool2any(m_bEsacpeProcessing));
|
2001-04-24 13:28:56 +00:00
|
|
|
|
2001-04-26 12:34:47 +00:00
|
|
|
// now we save the layout information
|
|
|
|
// create the output stream
|
|
|
|
m_pWindow->getView()->SaveUIConfig();
|
|
|
|
Sequence< sal_Int8 > aOutputSeq;
|
|
|
|
Reference< XOutputStream> xOutStreamHelper = new OSequenceOutputStream(aOutputSeq);
|
|
|
|
Reference< XObjectOutputStream> xOutStream(getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.ObjectOutputStream")),UNO_QUERY);
|
|
|
|
Reference< XOutputStream> xMarkOutStream(getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.MarkableOutputStream")),UNO_QUERY);
|
|
|
|
Reference< XActiveDataSource >(xMarkOutStream,UNO_QUERY)->setOutputStream(xOutStreamHelper);
|
|
|
|
Reference< XActiveDataSource > xOutDataSource(xOutStream, UNO_QUERY);
|
|
|
|
OSL_ENSURE(xOutDataSource.is(),"Couldn't create com.sun.star.io.ObjectOutputStream!");
|
|
|
|
xOutDataSource->setOutputStream(xMarkOutStream);
|
|
|
|
Save(xOutStream);
|
|
|
|
xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aOutputSeq));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bNew)
|
|
|
|
{
|
|
|
|
Reference<XAppend> xAppend(xElements,UNO_QUERY);
|
|
|
|
OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
|
|
|
|
xAppend->appendByDescriptor(xProp);
|
|
|
|
|
|
|
|
if(m_bCreateView)
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
Reference<XPropertySet> xProp2;
|
|
|
|
if(xElements->hasByName(m_sName))
|
|
|
|
xElements->getByName(m_sName) >>= xProp2;
|
|
|
|
if(!xProp2.is()) // correct name and try again
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
// it can be that someone inserted new data for us
|
|
|
|
::rtl::OUString sCatalog,sSchema,sTable,sComposedName;
|
|
|
|
xProp->getPropertyValue(PROPERTY_CATALOGNAME) >>= sCatalog;
|
|
|
|
xProp->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema;
|
|
|
|
xProp->getPropertyValue(PROPERTY_NAME) >>= sTable;
|
|
|
|
|
|
|
|
::dbtools::composeTableName(m_xConnection->getMetaData(),sCatalog,sSchema,sTable,sComposedName,sal_False);
|
|
|
|
m_sName = sComposedName;
|
|
|
|
}
|
|
|
|
// now check if our datasource has set a tablefilter and if append the new table name to it
|
|
|
|
Reference< XChild> xChild(m_xConnection,UNO_QUERY);
|
|
|
|
if(xChild.is())
|
|
|
|
{
|
|
|
|
Reference< XPropertySet> xDSProp(xChild->getParent(),UNO_QUERY);
|
|
|
|
if(xDSProp.is())
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
Sequence< ::rtl::OUString > aFilter;
|
|
|
|
xDSProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aFilter;
|
|
|
|
// first check if we have something like SCHEMA.%
|
|
|
|
sal_Bool bHasToInsert = sal_True;
|
|
|
|
static ::rtl::OUString sPattern = ::rtl::OUString::createFromAscii("%");
|
|
|
|
const ::rtl::OUString* pBegin = aFilter.getConstArray();
|
|
|
|
const ::rtl::OUString* pEnd = pBegin + aFilter.getLength();
|
|
|
|
for (;pBegin != pEnd; ++pBegin)
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
if(pBegin->indexOf('%') != -1)
|
|
|
|
{
|
|
|
|
sal_Int32 nLen;
|
|
|
|
if((nLen = pBegin->lastIndexOf('.')) != -1 && !pBegin->compareTo(m_sName,nLen))
|
|
|
|
bHasToInsert = sal_False;
|
|
|
|
else if(pBegin->getLength() == 1)
|
|
|
|
bHasToInsert = sal_False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(bHasToInsert)
|
|
|
|
{
|
|
|
|
aFilter.realloc(aFilter.getLength()+1);
|
|
|
|
aFilter.getArray()[aFilter.getLength()-1] = m_sName;
|
|
|
|
xDSProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
|
|
|
|
Reference<XFlushable> xFlush(xDSProp,UNO_QUERY);
|
|
|
|
if(xFlush.is())
|
|
|
|
xFlush->flush();
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
setModified(sal_False);
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
catch(SQLContext& e) { aInfo = SQLExceptionInfo(e); }
|
|
|
|
catch(SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
|
|
|
|
catch(SQLException& e) { aInfo = SQLExceptionInfo(e); }
|
|
|
|
catch(Exception&)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(0,"OQueryController::doSaveAsDoc: Query could not be inserted!");
|
|
|
|
}
|
|
|
|
showError(aInfo);
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
::rtl::OUString OQueryController::translateStatement()
|
|
|
|
{
|
|
|
|
// now set the properties
|
|
|
|
m_sStatement = m_pWindow->getView()->getStatement();
|
|
|
|
::rtl::OUString sTranslatedStmt;
|
|
|
|
if(m_sStatement.getLength() && m_xComposer.is() && m_bEsacpeProcessing)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
::rtl::OUString aErrorMsg;
|
|
|
|
::connectivity::OSQLParseNode* pNode = m_pSqlParser->parseTree(aErrorMsg,m_sStatement,sal_True);
|
|
|
|
// m_pParseNode = pNode;
|
|
|
|
if(pNode)
|
2001-04-24 13:28:56 +00:00
|
|
|
{
|
2001-04-26 12:34:47 +00:00
|
|
|
pNode->parseNodeToStr( sTranslatedStmt,
|
|
|
|
m_xConnection->getMetaData());
|
|
|
|
delete pNode;
|
2001-04-24 13:28:56 +00:00
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
m_xComposer->setQuery(sTranslatedStmt);
|
|
|
|
sTranslatedStmt = m_xComposer->getComposedQuery();
|
|
|
|
}
|
|
|
|
catch(SQLException& e)
|
|
|
|
{
|
|
|
|
::dbtools::SQLExceptionInfo aInfo(e);
|
2001-04-24 13:28:56 +00:00
|
|
|
showError(aInfo);
|
|
|
|
}
|
2001-04-02 09:18:50 +00:00
|
|
|
}
|
2001-04-26 12:34:47 +00:00
|
|
|
else if(!m_sStatement.getLength())
|
|
|
|
{
|
|
|
|
ErrorBox aBox( getQueryView(), ModuleRes( ERR_QRY_NOSELECT ) );
|
|
|
|
aBox.Execute();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sTranslatedStmt = m_sStatement;
|
|
|
|
|
|
|
|
return sTranslatedStmt;
|
2001-04-02 09:18:50 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-05 08:35:57 +00:00
|
|
|
|