2001-02-05 08:35:57 +00:00
|
|
|
|
/*************************************************************************
|
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* $RCSfile: QueryDesignView.cxx,v $
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* $Revision: 1.75 $
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* last change: $Author: rt $ $Date: 2005-09-08 16:24:29 $
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
|
* =============================================
|
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* 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.
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* 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.
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
2005-09-08 15:24:29 +00:00
|
|
|
|
* 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
|
2001-02-05 08:35:57 +00:00
|
|
|
|
*
|
|
|
|
|
************************************************************************/
|
|
|
|
|
#ifndef DBAUI_QUERYDESIGNVIEW_HXX
|
|
|
|
|
#include "QueryDesignView.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_QUERYTABLEVIEW_HXX
|
|
|
|
|
#include "QueryTableView.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_QUERY_TABLEWINDOW_HXX
|
|
|
|
|
#include "QTableWindow.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _SV_TOOLBOX_HXX
|
|
|
|
|
#include <vcl/toolbox.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_QUERYCONTROLLER_HXX
|
|
|
|
|
#include "querycontroller.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _SV_SPLIT_HXX
|
|
|
|
|
#include <vcl/split.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _UNDO_HXX
|
|
|
|
|
#include <svtools/undo.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_QYDLGTAB_HXX
|
|
|
|
|
#include "adtabdlg.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _SV_SVAPP_HXX
|
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _SV_COMBOBOX_HXX
|
|
|
|
|
#include <vcl/combobox.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _SV_MSGBOX_HXX
|
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBACCESS_UI_BROWSER_ID_HXX
|
|
|
|
|
#include "browserids.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX
|
|
|
|
|
#include "SelectionBrowseBox.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_TABLEFIELDDATA_HXX
|
|
|
|
|
#include "TableFieldData.hxx"
|
|
|
|
|
#endif
|
2002-08-19 07:01:32 +00:00
|
|
|
|
#ifndef _DBU_QRY_HRC_
|
|
|
|
|
#include "dbu_qry.hrc"
|
2001-02-05 08:35:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef _UTL_CONFIGMGR_HXX_
|
|
|
|
|
#include <unotools/configmgr.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _COMPHELPER_TYPES_HXX_
|
|
|
|
|
#include <comphelper/types.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
|
|
|
|
|
#include <connectivity/dbtools.hxx>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _COM_SUN_STAR_I18N_XLOCALEDATA_HPP_
|
|
|
|
|
#include <com/sun/star/i18n/XLocaleData.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
|
|
|
|
|
#include <com/sun/star/sdbc/DataType.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
|
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
|
#endif
|
2001-09-27 05:19:05 +00:00
|
|
|
|
#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
|
|
|
|
|
#include <com/sun/star/sdbc/ColumnValue.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _CONNECTIVITY_PCOLUMN_HXX_
|
|
|
|
|
#include <connectivity/PColumn.hxx>
|
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
|
#ifndef DBAUI_QUERYTABLECONNECTION_HXX
|
|
|
|
|
#include "QTableConnection.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_CONNECTIONLINE_HXX
|
|
|
|
|
#include "ConnectionLine.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_CONNECTIONLINEDATA_HXX
|
|
|
|
|
#include "ConnectionLineData.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBAUI_QTABLECONNECTIONDATA_HXX
|
|
|
|
|
#include "QTableConnectionData.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
|
|
|
|
|
#include "dbustrings.hrc"
|
|
|
|
|
#endif
|
2001-03-15 07:29:16 +00:00
|
|
|
|
#ifndef _COMPHELPER_EXTRACT_HXX_
|
|
|
|
|
#include <comphelper/extract.hxx>
|
2001-02-14 13:54:12 +00:00
|
|
|
|
#endif
|
2001-02-23 14:04:37 +00:00
|
|
|
|
#ifndef DBAUI_TOOLS_HXX
|
|
|
|
|
#include "UITools.hxx"
|
|
|
|
|
#endif
|
2001-08-23 13:39:09 +00:00
|
|
|
|
#ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
|
|
|
|
|
#include "querycontainerwindow.hxx"
|
|
|
|
|
#endif
|
2001-09-27 05:19:05 +00:00
|
|
|
|
#ifndef _ISOLANG_HXX
|
|
|
|
|
#include <tools/isolang.hxx>
|
|
|
|
|
#endif
|
2002-02-06 07:08:30 +00:00
|
|
|
|
#ifndef DBAUI_QUERYTABLEVIEW_HXX
|
|
|
|
|
#include "QueryTableView.hxx"
|
|
|
|
|
#endif
|
2002-04-09 14:30:33 +00:00
|
|
|
|
#ifndef _DBAUI_SQLMESSAGE_HXX_
|
|
|
|
|
#include "sqlmessage.hxx"
|
|
|
|
|
#endif
|
2002-04-09 14:49:26 +00:00
|
|
|
|
#ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
|
|
|
|
|
#include <svtools/syslocale.hxx>
|
|
|
|
|
#endif
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
|
|
|
|
using namespace ::dbaui;
|
|
|
|
|
using namespace ::utl;
|
|
|
|
|
using namespace ::connectivity;
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
|
using namespace ::com::sun::star::i18n;
|
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
|
|
2002-02-19 13:04:20 +00:00
|
|
|
|
#define SQL_ISRULEOR2(pParseNode, e1,e2) ((pParseNode)->isRule() && (\
|
2003-06-12 09:19:45 +00:00
|
|
|
|
(pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e1) || \
|
|
|
|
|
(pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e2)))
|
2002-02-19 13:04:20 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// here we define our functions used in the anonymous namespace to get our header file smaller
|
|
|
|
|
// please look at the book LargeScale C++ to know why
|
|
|
|
|
namespace
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
static const ::rtl::OUString C_AND = ::rtl::OUString::createFromAscii(" AND ");
|
|
|
|
|
static const ::rtl::OUString C_OR = ::rtl::OUString::createFromAscii(" OR ");
|
2001-09-27 05:19:05 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// forward declarations
|
|
|
|
|
sal_Bool InsertJoin( const OQueryDesignView* _pView,
|
|
|
|
|
const ::connectivity::OSQLParseNode *pNode);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError InstallFields(OQueryDesignView* _pView,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pNode,
|
|
|
|
|
OJoinTableView::OTableWindowMap* pTabList );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetGroupCriteria( OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pSelectRoot );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetHavingCriteria(OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pSelectRoot,
|
|
|
|
|
int &rLevel );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetOrderCriteria( OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pParseRoot );
|
2002-04-09 14:30:33 +00:00
|
|
|
|
|
2004-03-15 11:43:43 +00:00
|
|
|
|
SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
const int nLevel,
|
|
|
|
|
sal_Bool bHaving);
|
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
::rtl::OUString quoteTableAlias(sal_Bool _bQuote, const ::rtl::OUString& _sAliasName, const ::rtl::OUString& _sQuote)
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString sRet;
|
|
|
|
|
if ( _bQuote && _sAliasName.getLength() )
|
|
|
|
|
{
|
|
|
|
|
sRet = ::dbtools::quoteName(_sQuote,_sAliasName);
|
|
|
|
|
const static ::rtl::OUString sTableSeparater('.');
|
|
|
|
|
sRet += sTableSeparater;
|
|
|
|
|
}
|
|
|
|
|
return sRet;
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2004-03-15 11:43:43 +00:00
|
|
|
|
::rtl::OUString ParseCondition( OQueryController* pController
|
|
|
|
|
,const ::connectivity::OSQLParseNode* pCondition
|
|
|
|
|
,const ::rtl::OUString _sDecimal
|
|
|
|
|
,const ::com::sun::star::lang::Locale& _rLocale
|
|
|
|
|
,sal_uInt32 _nStartIndex)
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString aCondition;
|
|
|
|
|
Reference< XConnection> xConnection = pController->getConnection();
|
|
|
|
|
if ( xConnection.is() )
|
|
|
|
|
{
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
sal_uInt32 nCount = pCondition->count();
|
|
|
|
|
for(sal_uInt32 i = _nStartIndex ; i < nCount ; ++i)
|
|
|
|
|
pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
|
|
|
|
|
xMetaData,
|
|
|
|
|
pController->getNumberFormatter(),
|
|
|
|
|
_rLocale,
|
|
|
|
|
static_cast<sal_Char>(_sDecimal.toChar()),
|
|
|
|
|
&pController->getParser()->getContext());
|
|
|
|
|
}
|
|
|
|
|
return aCondition;
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError FillOuterJoins(OQueryDesignView* _pView,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pTableRefList)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
|
|
|
|
sal_uInt32 nCount = pTableRefList->count();
|
2003-04-28 15:00:22 +00:00
|
|
|
|
sal_Bool bError = sal_False;
|
|
|
|
|
for (sal_uInt32 i=0; !bError && i < nCount; ++i)
|
2001-02-05 15:17:40 +00:00
|
|
|
|
{
|
2003-04-28 15:00:22 +00:00
|
|
|
|
const ::connectivity::OSQLParseNode* pParseNode = pTableRefList->getChild(i);
|
|
|
|
|
const ::connectivity::OSQLParseNode* pJoinNode = NULL;
|
2002-02-19 13:04:20 +00:00
|
|
|
|
|
2003-04-28 15:00:22 +00:00
|
|
|
|
if ( SQL_ISRULEOR2(pParseNode , qualified_join,joined_table) || SQL_ISRULE(pParseNode ,cross_union) )
|
|
|
|
|
pJoinNode = pParseNode;
|
|
|
|
|
else if( pParseNode->count() == 4
|
|
|
|
|
&& SQL_ISPUNCTUATION(pParseNode->getChild(0),"{")
|
|
|
|
|
&& SQL_ISRULE(pParseNode,table_ref))
|
|
|
|
|
pJoinNode = pParseNode->getChild(2);
|
2002-02-19 13:04:20 +00:00
|
|
|
|
|
2003-04-28 15:00:22 +00:00
|
|
|
|
if ( pJoinNode )
|
2002-05-06 08:45:36 +00:00
|
|
|
|
{
|
2003-04-28 15:00:22 +00:00
|
|
|
|
if ( !InsertJoin(_pView,pJoinNode) )
|
|
|
|
|
bError = sal_True;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
}
|
2001-02-05 15:17:40 +00:00
|
|
|
|
}
|
2003-04-28 15:00:22 +00:00
|
|
|
|
// check if error occured
|
|
|
|
|
if ( bError )
|
|
|
|
|
eErrorCode = eIllegalJoin;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
|
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
::rtl::OUString QuoteField( const OQueryDesignView* _pView,const ::rtl::OUString& rValue, sal_Int32 aType )
|
2001-02-06 08:46:27 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString rNewValue;
|
|
|
|
|
switch (rValue.toChar())
|
|
|
|
|
{
|
|
|
|
|
case '?':
|
|
|
|
|
if (rValue.getLength() != 1)
|
|
|
|
|
break;
|
|
|
|
|
case '\'': // ::rtl::OUString Quotierung oder Datum
|
|
|
|
|
//case '#': // Datumsquotierung // jetengine
|
|
|
|
|
case ':': // Parameter
|
|
|
|
|
case '[': // Parameter
|
|
|
|
|
return rValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Reference< XConnection> xConnection = static_cast<OQueryController*>(_pView->getController())->getConnection();
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData;
|
|
|
|
|
if(xConnection.is())
|
|
|
|
|
xMetaData = xConnection->getMetaData();
|
|
|
|
|
::rtl::OUString aQuote;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(xMetaData.is())
|
|
|
|
|
aQuote = xMetaData->getIdentifierQuoteString();
|
|
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
|
{
|
|
|
|
|
case DataType::DATE:
|
|
|
|
|
case DataType::TIME:
|
|
|
|
|
case DataType::TIMESTAMP:
|
|
|
|
|
if (rValue.toChar() != '{') // nur quoten, wenn kein Access Datum
|
|
|
|
|
rNewValue = ::dbtools::quoteName(aQuote,rValue);
|
|
|
|
|
else
|
|
|
|
|
rNewValue = rValue;
|
|
|
|
|
break;
|
|
|
|
|
case DataType::CHAR:
|
|
|
|
|
case DataType::VARCHAR:
|
|
|
|
|
case DataType::LONGVARCHAR:
|
|
|
|
|
rNewValue = ::dbtools::quoteName(aQuote,rValue);
|
|
|
|
|
break;
|
|
|
|
|
case DataType::DECIMAL:
|
|
|
|
|
case DataType::NUMERIC:
|
|
|
|
|
case DataType::TINYINT:
|
|
|
|
|
case DataType::SMALLINT:
|
|
|
|
|
case DataType::INTEGER:
|
|
|
|
|
case DataType::BIGINT:
|
|
|
|
|
case DataType::REAL:
|
|
|
|
|
case DataType::DOUBLE:
|
|
|
|
|
case DataType::BINARY:
|
|
|
|
|
case DataType::VARBINARY:
|
|
|
|
|
case DataType::LONGVARBINARY:
|
|
|
|
|
rNewValue = rValue;
|
|
|
|
|
break;
|
|
|
|
|
case DataType::BIT:
|
2005-02-17 10:08:56 +00:00
|
|
|
|
case DataType::BOOLEAN:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
if(xMetaData.is())
|
|
|
|
|
{
|
|
|
|
|
::comphelper::UStringMixEqual bCase(xMetaData->storesMixedCaseQuotedIdentifiers());
|
2005-04-13 07:36:53 +00:00
|
|
|
|
if (bCase(rValue, String(ModuleRes(STR_QUERY_TRUE))))
|
2002-02-19 13:04:20 +00:00
|
|
|
|
rNewValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TRUE"));
|
2005-04-13 07:36:53 +00:00
|
|
|
|
else if (bCase(rValue, String(ModuleRes(STR_QUERY_FALSE))))
|
2002-02-19 13:04:20 +00:00
|
|
|
|
rNewValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FALSE"));
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else
|
|
|
|
|
rNewValue = rValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DBG_ERROR( "QuoteField: illegal type" );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(SQLException&)
|
|
|
|
|
{
|
|
|
|
|
DBG_ERROR( "QuoteField: Exception" );
|
|
|
|
|
}
|
|
|
|
|
return rNewValue;
|
2001-02-06 08:46:27 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
/** FillDragInfo fills the field description out of the table
|
|
|
|
|
*/
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError FillDragInfo( const OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const ::connectivity::OSQLParseNode* pColumnRef,
|
|
|
|
|
OTableFieldDescRef& _rDragInfo)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
sal_Bool bErg = sal_False;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aTableRange,aColumnName;
|
|
|
|
|
sal_uInt16 nCntAccount;
|
|
|
|
|
::connectivity::OSQLParseTreeIterator& rParseIter = static_cast<OQueryController*>(_pView->getController())->getParseIterator();
|
|
|
|
|
rParseIter.getColumnRange( pColumnRef, aColumnName, aTableRange );
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( aTableRange.getLength() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pSTW = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( aTableRange );
|
2002-05-06 08:45:36 +00:00
|
|
|
|
bErg = (pSTW && pSTW->ExistsField( aColumnName, _rDragInfo ) );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( !bErg )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
bErg = static_cast<OQueryTableView*>(_pView->getTableView())->FindTableFromField(aColumnName, _rDragInfo, nCntAccount);
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( !bErg )
|
|
|
|
|
{
|
|
|
|
|
eErrorCode = eColumnNotFound;
|
|
|
|
|
String sError(ModuleRes(STR_QRY_COLUMN_NOT_FOUND));
|
|
|
|
|
sError.SearchAndReplaceAscii("$name$",aColumnName);
|
|
|
|
|
_pView->getController()->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000") ),1000,Any()));
|
|
|
|
|
|
2003-12-01 09:38:33 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Reference<XDatabaseMetaData> xMeta = _pView->getController()->getConnection()->getMetaData();
|
|
|
|
|
if ( xMeta.is() && xMeta->storesMixedCaseQuotedIdentifiers() )
|
|
|
|
|
_pView->getController()->appendError(SQLException(String(ModuleRes(STR_QRY_CHECK_CASESENSITIVE)),NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000") ),1000,Any()));
|
|
|
|
|
}
|
|
|
|
|
catch(Exception&)
|
|
|
|
|
{
|
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return eErrorCode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString BuildJoinCriteria( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OConnectionLineDataVec* pLineDataList,
|
|
|
|
|
OQueryTableConnectionData* pData)
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString aCondition;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( !_xConnection.is() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return aCondition;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OConnectionLineDataVec::iterator aIter = pLineDataList->begin();
|
|
|
|
|
try
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = _xConnection->getMetaData();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
for(;aIter != pLineDataList->end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
OConnectionLineDataRef pLineData = *aIter;
|
|
|
|
|
if(pLineData->IsValid())
|
|
|
|
|
{
|
|
|
|
|
if(aCondition.getLength())
|
|
|
|
|
aCondition += C_AND;
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aCondition += quoteTableAlias(sal_True,pData->GetAliasName(JTCS_FROM),aQuote);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aCondition += ::dbtools::quoteName(aQuote, pLineData->GetFieldName(JTCS_FROM) );
|
2002-02-19 13:04:20 +00:00
|
|
|
|
aCondition += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" = "));
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aCondition += quoteTableAlias(sal_True,pData->GetAliasName(JTCS_TO),aQuote);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aCondition += ::dbtools::quoteName(aQuote, pLineData->GetFieldName(JTCS_TO) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(SQLException&)
|
|
|
|
|
{
|
|
|
|
|
OSL_ASSERT(!"Failure while building Join criteria!");
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return aCondition;
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
/** JoinCycle looks for a join cycle and append it to the string
|
2002-05-06 08:45:36 +00:00
|
|
|
|
@param _xConnection the connection
|
2002-02-06 07:08:30 +00:00
|
|
|
|
@param _pEntryConn the table connection which holds the data
|
|
|
|
|
@param _pEntryTabTo the corresponding table window
|
|
|
|
|
@param _rJoin the String which will contain the resulting string
|
|
|
|
|
*/
|
2002-05-06 08:45:36 +00:00
|
|
|
|
void JoinCycle( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableConnection* _pEntryConn,
|
|
|
|
|
const OQueryTableWindow* _pEntryTabTo,
|
|
|
|
|
::rtl::OUString& _rJoin )
|
|
|
|
|
{
|
|
|
|
|
OSL_ENSURE(_pEntryConn,"TableConnection can not be null!");
|
|
|
|
|
|
|
|
|
|
OQueryTableConnectionData* pData = static_cast< OQueryTableConnectionData*>(_pEntryConn->GetData());
|
|
|
|
|
if ( pData->GetJoinType() != INNER_JOIN && _pEntryTabTo->ExistsAVisitedConn() )
|
|
|
|
|
{
|
|
|
|
|
sal_Bool bBrace = sal_False;
|
|
|
|
|
if(_rJoin.getLength() && _rJoin.lastIndexOf(')') == (_rJoin.getLength()-1))
|
|
|
|
|
{
|
|
|
|
|
bBrace = sal_True;
|
|
|
|
|
_rJoin = _rJoin.replaceAt(_rJoin.getLength()-1,1,::rtl::OUString(' '));
|
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
(_rJoin += C_AND) += BuildJoinCriteria(_xConnection,pData->GetConnLineDataList(),pData);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(bBrace)
|
|
|
|
|
_rJoin += ::rtl::OUString(')');
|
|
|
|
|
_pEntryConn->SetVisited(sal_True);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString BuildTable( const Reference< XConnection>& _xConnection,
|
2003-09-04 07:33:37 +00:00
|
|
|
|
const OQueryTableWindow* pEntryTab
|
|
|
|
|
)
|
2001-04-18 10:44:59 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aDBName(pEntryTab->GetComposedName());
|
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
// Reference< XConnection> xConnection = static_cast<OQueryController*>(_pView->getController())->getConnection();
|
|
|
|
|
if( _xConnection.is() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = _xConnection->getMetaData();
|
2002-06-27 07:21:18 +00:00
|
|
|
|
|
2004-08-02 15:12:50 +00:00
|
|
|
|
sal_Bool bUseCatalogInSelect = ::dbtools::isDataSourcePropertyEnabled(_xConnection,PROPERTY_USECATALOGINSELECT,sal_True);
|
|
|
|
|
sal_Bool bUseSchemaInSelect = ::dbtools::isDataSourcePropertyEnabled(_xConnection,PROPERTY_USESCHEMAINSELECT,sal_True);
|
|
|
|
|
::rtl::OUString aTableListStr = ::dbtools::quoteTableName(xMetaData,aDBName,::dbtools::eInDataManipulation,bUseCatalogInSelect,bUseSchemaInSelect);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
|
2003-09-04 07:33:37 +00:00
|
|
|
|
if ( isAppendTableAliasEnabled(_xConnection) )
|
|
|
|
|
{
|
|
|
|
|
aTableListStr += ::rtl::OUString(' ');
|
|
|
|
|
aTableListStr += ::dbtools::quoteName(aQuote, pEntryTab->GetAliasName());
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aDBName = aTableListStr;
|
|
|
|
|
}
|
|
|
|
|
catch(SQLException&)
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
OSL_ENSURE(0,"Exception catched while building table table for query!");
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return aDBName;
|
2001-04-18 10:44:59 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const ::rtl::OUString& rLh,
|
|
|
|
|
const ::rtl::OUString& rRh,
|
|
|
|
|
OQueryTableConnectionData* pData)
|
2001-05-02 11:44:27 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
String aErg(rLh);
|
|
|
|
|
switch(pData->GetJoinType())
|
|
|
|
|
{
|
|
|
|
|
case LEFT_JOIN:
|
|
|
|
|
aErg.AppendAscii(" LEFT OUTER ");
|
|
|
|
|
break;
|
|
|
|
|
case RIGHT_JOIN:
|
|
|
|
|
aErg.AppendAscii(" RIGHT OUTER ");
|
|
|
|
|
break;
|
|
|
|
|
case INNER_JOIN:
|
|
|
|
|
DBG_ERROR("OQueryDesignView::BuildJoin: This should not happen!");
|
|
|
|
|
//aErg.AppendAscii(" INNER ");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
aErg.AppendAscii(" FULL OUTER ");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
aErg.AppendAscii("JOIN ");
|
|
|
|
|
aErg += String(rRh);
|
|
|
|
|
aErg.AppendAscii(" ON ");
|
2002-05-06 08:45:36 +00:00
|
|
|
|
aErg += String(BuildJoinCriteria(_xConnection,pData->GetConnLineDataList(),pData));
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
return aErg;
|
2001-05-02 11:44:27 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableWindow* pLh,
|
|
|
|
|
OQueryTableWindow* pRh,
|
2003-09-04 07:33:37 +00:00
|
|
|
|
OQueryTableConnectionData* pData
|
|
|
|
|
)
|
2001-05-02 11:44:27 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return BuildJoin(_xConnection,BuildTable(_xConnection,pLh),BuildTable(_xConnection,pRh),pData);
|
2001-05-02 11:44:27 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const ::rtl::OUString &rLh,
|
|
|
|
|
OQueryTableWindow* pRh,
|
2003-09-04 07:33:37 +00:00
|
|
|
|
OQueryTableConnectionData* pData
|
|
|
|
|
)
|
2001-05-02 11:44:27 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return BuildJoin(_xConnection,rLh,BuildTable(_xConnection,pRh),pData);
|
2001-05-02 11:44:27 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableWindow* pLh,
|
|
|
|
|
const ::rtl::OUString &rRh,
|
2003-09-04 07:33:37 +00:00
|
|
|
|
OQueryTableConnectionData* pData
|
|
|
|
|
)
|
2001-05-02 11:44:27 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return BuildJoin(_xConnection,BuildTable(_xConnection,pLh),rRh,pData);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
void GetNextJoin( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableConnection* pEntryConn,
|
|
|
|
|
OQueryTableWindow* pEntryTabTo,
|
|
|
|
|
::rtl::OUString &aJoin)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableConnectionData* pEntryConnData = static_cast<OQueryTableConnectionData*>(pEntryConn->GetData());
|
|
|
|
|
if(pEntryConnData->GetJoinType() == INNER_JOIN)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
// Reference< XConnection> xConnection = static_cast<OQueryController*>(_pView->getController())->getConnection();
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(!aJoin.getLength())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
|
2002-05-06 08:45:36 +00:00
|
|
|
|
aJoin = BuildJoin(_xConnection,pEntryTabFrom,pEntryTabTo,pEntryConnData);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else if(pEntryTabTo == pEntryConn->GetDestWin())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aTmpJoin('(');
|
|
|
|
|
(aTmpJoin += aJoin) += ::rtl::OUString(')');
|
2002-05-06 08:45:36 +00:00
|
|
|
|
aJoin = BuildJoin(_xConnection,aTmpJoin,pEntryTabTo,pEntryConnData);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else if(pEntryTabTo == pEntryConn->GetSourceWin())
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString aTmpJoin('(');
|
|
|
|
|
(aTmpJoin += aJoin) += ::rtl::OUString(')');
|
2002-05-06 08:45:36 +00:00
|
|
|
|
aJoin = BuildJoin(_xConnection,pEntryTabTo,aTmpJoin,pEntryConnData);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
pEntryConn->SetVisited(sal_True);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// first search for the "to" window
|
2002-02-19 13:04:20 +00:00
|
|
|
|
const ::std::vector<OTableConnection*>* pConnections = pEntryConn->GetParent()->getTableConnections();
|
|
|
|
|
::std::vector<OTableConnection*>::const_iterator aIter = pConnections->begin();
|
|
|
|
|
for(;aIter != pConnections->end();++aIter)
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
OQueryTableConnection* pNext = static_cast<OQueryTableConnection*>(*aIter);
|
|
|
|
|
if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabTo || pNext->GetDestWin() == pEntryTabTo))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabTo ? static_cast<OQueryTableWindow*>(pNext->GetDestWin()) : static_cast<OQueryTableWindow*>(pNext->GetSourceWin());
|
|
|
|
|
// exists there a connection to a OQueryTableWindow that holds a connection that has been already visited
|
2002-05-06 08:45:36 +00:00
|
|
|
|
JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(!pNext->IsVisited())
|
2002-05-06 08:45:36 +00:00
|
|
|
|
GetNextJoin(_xConnection,pNext,pEntryTab,aJoin);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// when nothing found found look for the "from" window
|
2002-02-19 13:04:20 +00:00
|
|
|
|
if(aIter == pConnections->end())
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
|
2002-02-19 13:04:20 +00:00
|
|
|
|
aIter = pConnections->begin();
|
|
|
|
|
for(;aIter != pConnections->end();++aIter)
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
OQueryTableConnection* pNext = static_cast<OQueryTableConnection*>(*aIter);
|
|
|
|
|
if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabFrom || pNext->GetDestWin() == pEntryTabFrom))
|
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabFrom ? static_cast<OQueryTableWindow*>(pNext->GetDestWin()) : static_cast<OQueryTableWindow*>(pNext->GetSourceWin());
|
|
|
|
|
// exists there a connection to a OQueryTableWindow that holds a connection that has been already visited
|
2002-05-06 08:45:36 +00:00
|
|
|
|
JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(!pNext->IsVisited())
|
2002-05-06 08:45:36 +00:00
|
|
|
|
GetNextJoin(_xConnection,pNext,pEntryTab,aJoin);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError InsertJoinConnection( const OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const ::connectivity::OSQLParseNode *pNode,
|
|
|
|
|
const EJoinType& _eJoinType)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (pNode->count() == 3 && // Ausdruck is geklammert
|
|
|
|
|
SQL_ISPUNCTUATION(pNode->getChild(0),"(") &&
|
|
|
|
|
SQL_ISPUNCTUATION(pNode->getChild(2),")"))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = InsertJoinConnection(_pView,pNode->getChild(1), _eJoinType);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-02-19 13:04:20 +00:00
|
|
|
|
else if (SQL_ISRULEOR2(pNode,search_condition,boolean_term) && // AND/OR-Verknuepfung:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
pNode->count() == 3)
|
|
|
|
|
{
|
|
|
|
|
// nur AND Verkn<6B>pfung zulassen
|
|
|
|
|
if (!SQL_ISTOKEN(pNode->getChild(1),AND))
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = eIllegalJoinCondition;
|
|
|
|
|
else if ( eOk == (eErrorCode = InsertJoinConnection(_pView,pNode->getChild(0), _eJoinType)) )
|
|
|
|
|
eErrorCode = InsertJoinConnection(_pView,pNode->getChild(2), _eJoinType);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else if (SQL_ISRULE(pNode,comparison_predicate))
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
// only the comparison of columns is allowed
|
2002-02-06 07:08:30 +00:00
|
|
|
|
DBG_ASSERT(pNode->count() == 3,"OQueryDesignView::InsertJoinConnection: Fehler im Parse Tree");
|
|
|
|
|
if (!(SQL_ISRULE(pNode->getChild(0),column_ref) &&
|
|
|
|
|
SQL_ISRULE(pNode->getChild(2),column_ref) &&
|
|
|
|
|
pNode->getChild(1)->getNodeType() == SQL_NODE_EQUAL))
|
2002-05-06 08:45:36 +00:00
|
|
|
|
{
|
|
|
|
|
String sError(ModuleRes(STR_QRY_JOIN_COLUMN_COMPARE));
|
|
|
|
|
_pView->getController()->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000") ),1000,Any()));
|
|
|
|
|
return eIllegalJoin;
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
|
|
|
|
OTableFieldDescRef aDragRight = new OTableFieldDesc();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( eOk != ( eErrorCode = FillDragInfo(_pView,pNode->getChild(0),aDragLeft)) ||
|
|
|
|
|
eOk != ( eErrorCode = FillDragInfo(_pView,pNode->getChild(2),aDragRight)))
|
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableView* pTableView = static_cast<OQueryTableView*>(_pView->getTableView());
|
|
|
|
|
OQueryTableConnection* pConn = static_cast<OQueryTableConnection*>( pTableView->GetTabConn(static_cast<OQueryTableWindow*>(aDragLeft->GetTabWindow()),static_cast<OQueryTableWindow*>(aDragRight->GetTabWindow())));
|
|
|
|
|
if(!pConn)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableConnectionData aInfoData;
|
|
|
|
|
aInfoData.InitFromDrag(aDragLeft, aDragRight);
|
|
|
|
|
aInfoData.SetJoinType(_eJoinType);
|
|
|
|
|
|
|
|
|
|
OQueryTableConnection aInfo(pTableView, &aInfoData);
|
|
|
|
|
// da ein OQueryTableConnection-Objekt nie den Besitz der uebergebenen Daten uebernimmt, sondern sich nur den Zeiger merkt,
|
|
|
|
|
// ist dieser Zeiger auf eine lokale Variable hier unkritisch, denn aInfoData und aInfo haben die selbe Lebensdauer
|
|
|
|
|
pTableView->NotifyTabConnection( aInfo );
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aSourceFieldName(aDragLeft->GetField());
|
|
|
|
|
::rtl::OUString aDestFieldName(aDragRight->GetField());
|
|
|
|
|
// the connection could point on the other side
|
|
|
|
|
if(pConn->GetSourceWin() == aDragRight->GetTabWindow())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aTmp(aSourceFieldName);
|
|
|
|
|
aSourceFieldName = aDestFieldName;
|
|
|
|
|
aDestFieldName = aTmp;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
pConn->GetData()->AppendConnLine( aSourceFieldName,aDestFieldName);
|
|
|
|
|
pConn->UpdateLineList();
|
|
|
|
|
// Modified-Flag
|
|
|
|
|
// SetModified();
|
|
|
|
|
// und neu zeichnen
|
|
|
|
|
pConn->RecalcLines();
|
|
|
|
|
// fuer das unten folgende Invalidate muss ich dieser neuen Connection erst mal die Moeglichkeit geben,
|
|
|
|
|
// ihr BoundingRect zu ermitteln
|
|
|
|
|
pConn->Invalidate();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
else
|
|
|
|
|
eErrorCode = eIllegalJoin;
|
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
sal_Bool GetInnerJoinCriteria( const OQueryDesignView* _pView,
|
|
|
|
|
const ::connectivity::OSQLParseNode *pCondition)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return InsertJoinConnection(_pView,pCondition, INNER_JOIN) != eOk;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
::rtl::OUString GenerateSelectList( const OQueryDesignView* _pView,
|
|
|
|
|
OTableFields& _rFieldList,
|
|
|
|
|
sal_Bool bAlias)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aTmpStr,aFieldListStr;
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
sal_Bool bAsterix = sal_False;
|
|
|
|
|
int nVis = 0;
|
|
|
|
|
OTableFields::iterator aIter = _rFieldList.begin();
|
|
|
|
|
for(;aIter != _rFieldList.end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OTableFieldDescRef pEntryField = *aIter;
|
2002-08-19 07:01:32 +00:00
|
|
|
|
if ( pEntryField->IsVisible() )
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-08-19 07:01:32 +00:00
|
|
|
|
if ( pEntryField->GetField().toChar() == '*' )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
bAsterix = sal_True;
|
|
|
|
|
++nVis;
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(nVis == 1)
|
|
|
|
|
bAsterix = sal_False;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XConnection> xConnection = static_cast<OQueryController*>(_pView->getController())->getConnection();
|
|
|
|
|
if(!xConnection.is())
|
|
|
|
|
return aFieldListStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
try
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
2004-03-15 11:43:43 +00:00
|
|
|
|
OJoinTableView::OTableWindowMap* pTabList = _pView->getTableView()->GetTabWinMap();
|
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
const static ::rtl::OUString sFieldSeparator(RTL_CONSTASCII_USTRINGPARAM(", "));
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aIter = _rFieldList.begin();
|
|
|
|
|
for(;aIter != _rFieldList.end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OTableFieldDescRef pEntryField = *aIter;
|
|
|
|
|
::rtl::OUString rFieldName = pEntryField->GetField();
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( rFieldName.getLength() && pEntryField->IsVisible() )
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aTmpStr = ::rtl::OUString();
|
|
|
|
|
::rtl::OUString rAlias = pEntryField->GetAlias();
|
|
|
|
|
::rtl::OUString rFieldAlias = pEntryField->GetFieldAlias();
|
2002-08-30 10:13:38 +00:00
|
|
|
|
|
|
|
|
|
aTmpStr += quoteTableAlias((bAlias || bAsterix),rAlias,aQuote);
|
|
|
|
|
|
|
|
|
|
// if we have a none numeric field, the table alias could be in the name
|
|
|
|
|
// otherwise we are not allowed to do this (e.g. 0.1 * PRICE )
|
|
|
|
|
if ( !pEntryField->isNumeric() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2004-03-15 11:43:43 +00:00
|
|
|
|
// we have to look if we have alias.* here but before we have to check if the column doesn't already exist
|
2002-08-30 10:13:38 +00:00
|
|
|
|
String sTemp = rFieldName;
|
2004-03-15 11:43:43 +00:00
|
|
|
|
OTableFieldDescRef aInfo = new OTableFieldDesc();
|
|
|
|
|
OJoinTableView::OTableWindowMap::iterator aIter = pTabList->begin();
|
|
|
|
|
sal_Bool bFound = sal_False;
|
|
|
|
|
for(;!bFound && aIter != pTabList->end() ;++aIter)
|
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
|
|
|
|
|
|
|
|
|
|
if ( bFound = pTabWin->ExistsField( rFieldName, aInfo ) )
|
|
|
|
|
{
|
|
|
|
|
rFieldName = aInfo->GetField();
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( rFieldName.toChar() != '*' )
|
|
|
|
|
{
|
|
|
|
|
OSL_ENSURE(pEntryField->GetTable().getLength(),"No table field name!");
|
|
|
|
|
aTmpStr += ::dbtools::quoteName(aQuote, rFieldName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
aTmpStr += rFieldName;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
aTmpStr += rFieldName;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pEntryField->isAggreateFunction() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
DBG_ASSERT(pEntryField->GetFunction().getLength(),"Functionname darf hier nicht leer sein! ;-(");
|
2003-08-18 14:05:15 +00:00
|
|
|
|
::rtl::OUString aTmpStr2( pEntryField->GetFunction());
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aTmpStr2 += ::rtl::OUString('(');
|
|
|
|
|
aTmpStr2 += aTmpStr;
|
|
|
|
|
aTmpStr2 += ::rtl::OUString(')');
|
|
|
|
|
aTmpStr = aTmpStr2;
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if (rFieldAlias.getLength() &&
|
2002-02-06 07:08:30 +00:00
|
|
|
|
(rFieldName.toChar() != '*' ||
|
2002-08-30 10:13:38 +00:00
|
|
|
|
pEntryField->isNumericOrAggreateFunction() ||
|
|
|
|
|
pEntryField->isOtherFunction()))
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
aTmpStr += ::rtl::OUString::createFromAscii(" AS ");
|
|
|
|
|
aTmpStr += ::dbtools::quoteName(aQuote, rFieldAlias);
|
|
|
|
|
}
|
|
|
|
|
aFieldListStr += aTmpStr;
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aFieldListStr += sFieldSeparator;
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(aFieldListStr.getLength())
|
|
|
|
|
aFieldListStr = aFieldListStr.replaceAt(aFieldListStr.getLength()-2,2, ::rtl::OUString() );
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
catch(SQLException&)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSL_ASSERT(!"Failure while building select list!");
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return aFieldListStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
sal_Bool GenerateCriterias( OQueryDesignView* _pView,
|
|
|
|
|
::rtl::OUString& rRetStr,
|
|
|
|
|
::rtl::OUString& rHavingStr,
|
|
|
|
|
OTableFields& _rFieldList,
|
|
|
|
|
sal_Bool bMulti )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// * darf keine Filter enthalten : habe ich die entsprechende Warnung schon angezeigt ?
|
|
|
|
|
sal_Bool bCritsOnAsterikWarning = sal_False; // ** TMFS **
|
|
|
|
|
|
|
|
|
|
::rtl::OUString aFieldName,aCriteria,aWhereStr,aHavingStr,aWork/*,aOrderStr*/;
|
|
|
|
|
// Zeilenweise werden die Ausdr"ucke mit AND verknuepft
|
|
|
|
|
sal_uInt16 nMaxCriteria = 0;
|
|
|
|
|
OTableFields::iterator aIter = _rFieldList.begin();
|
|
|
|
|
for(;aIter != _rFieldList.end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nMaxCriteria = ::std::max<sal_uInt16>(nMaxCriteria,(*aIter)->GetCriteria().size());
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XConnection> xConnection = static_cast<OQueryController*>(_pView->getController())->getConnection();
|
|
|
|
|
if(!xConnection.is())
|
|
|
|
|
return FALSE;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
|
2002-09-27 10:26:33 +00:00
|
|
|
|
const IParseContext& rContext = static_cast<OQueryController*>(_pView->getController())->getParser()->getContext();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
for (sal_uInt16 i=0 ; i < nMaxCriteria ; i++)
|
|
|
|
|
{
|
|
|
|
|
aHavingStr = aWhereStr = ::rtl::OUString();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
for(aIter = _rFieldList.begin();aIter != _rFieldList.end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
OTableFieldDescRef pEntryField = *aIter;
|
|
|
|
|
aFieldName = pEntryField->GetField();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (!aFieldName.getLength())
|
|
|
|
|
continue;
|
|
|
|
|
aCriteria = pEntryField->GetCriteria( i );
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( aCriteria.getLength() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
// * is not allowed to contain any filter, only when used in combination an aggregate function
|
|
|
|
|
if ( aFieldName.toChar() == '*' && pEntryField->isNoneFunction() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
// only show the messagebox the first time
|
|
|
|
|
if (!bCritsOnAsterikWarning)
|
|
|
|
|
ErrorBox(_pView, ModuleRes( ERR_QRY_CRITERIA_ON_ASTERISK)).Execute();
|
|
|
|
|
bCritsOnAsterikWarning = sal_True;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
aWork = ::rtl::OUString();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aWork += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
|
|
|
|
|
|
|
|
|
|
if ( (pEntryField->GetFunctionType() & (FKT_OTHER|FKT_NUMERIC)) || (aFieldName.toChar() == '*') )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aWork += aFieldName;
|
|
|
|
|
else
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aWork += ::dbtools::quoteName(aQuote, aFieldName);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pEntryField->isAggreateFunction() || pEntryField->IsGroupBy() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (!aHavingStr.getLength()) // noch keine Kriterien
|
|
|
|
|
aHavingStr += ::rtl::OUString('('); // Klammern
|
|
|
|
|
else
|
|
|
|
|
aHavingStr += C_AND;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pEntryField->isAggreateFunction() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
OSL_ENSURE(pEntryField->GetFunction().getLength(),"No function name for aggregate given!");
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aHavingStr += pEntryField->GetFunction();
|
|
|
|
|
aHavingStr += ::rtl::OUString('('); // Klammern
|
|
|
|
|
aHavingStr += aWork;
|
|
|
|
|
aHavingStr += ::rtl::OUString(')'); // Klammern
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
aHavingStr += aWork;
|
|
|
|
|
|
|
|
|
|
::rtl::OUString aTmp = aCriteria;
|
|
|
|
|
::rtl::OUString aErrorMsg;
|
|
|
|
|
Reference<XPropertySet> xColumn;
|
|
|
|
|
::connectivity::OSQLParseNode* pParseNode = _pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn);
|
|
|
|
|
if (pParseNode)
|
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if (bMulti && !(pEntryField->isOtherFunction() || (aFieldName.toChar() == '*')))
|
2002-06-27 07:21:18 +00:00
|
|
|
|
pParseNode->replaceNodeValue(pEntryField->GetAlias(),aFieldName);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString sHavingStr = aHavingStr;
|
2004-03-15 11:43:43 +00:00
|
|
|
|
|
|
|
|
|
sal_uInt32 nCount = pParseNode->count();
|
|
|
|
|
for( sal_uInt32 i = 1 ; i < nCount ; ++i)
|
2002-02-19 13:04:20 +00:00
|
|
|
|
pParseNode->getChild(i)->parseNodeToStr( sHavingStr,
|
|
|
|
|
xMetaData,
|
|
|
|
|
&rContext,
|
|
|
|
|
sal_False,
|
2002-08-30 10:13:38 +00:00
|
|
|
|
!pEntryField->isOtherFunction());
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aHavingStr = sHavingStr;
|
|
|
|
|
delete pParseNode;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
aHavingStr += aCriteria;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( !aWhereStr.getLength() ) // noch keine Kriterien
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aWhereStr += ::rtl::OUString('('); // Klammern
|
|
|
|
|
else
|
|
|
|
|
aWhereStr += C_AND;
|
|
|
|
|
|
|
|
|
|
aWhereStr += ::rtl::OUString(' ');
|
|
|
|
|
// aCriteria could have some german numbers so I have to be sure here
|
|
|
|
|
::rtl::OUString aTmp = aCriteria;
|
|
|
|
|
::rtl::OUString aErrorMsg;
|
|
|
|
|
Reference<XPropertySet> xColumn;
|
|
|
|
|
::connectivity::OSQLParseNode* pParseNode = _pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn);
|
|
|
|
|
if (pParseNode)
|
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if (bMulti && !(pEntryField->isOtherFunction() || (aFieldName.toChar() == '*')))
|
2002-06-27 07:21:18 +00:00
|
|
|
|
pParseNode->replaceNodeValue(pEntryField->GetAlias(),aFieldName);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aWhere = aWhereStr;
|
|
|
|
|
pParseNode->parseNodeToStr( aWhere,
|
|
|
|
|
xMetaData,
|
|
|
|
|
&rContext,
|
|
|
|
|
sal_False,
|
2002-08-30 10:13:38 +00:00
|
|
|
|
!pEntryField->isOtherFunction() );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aWhereStr = aWhere;
|
|
|
|
|
delete pParseNode;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
aWhereStr += aWork;
|
2004-03-02 11:46:44 +00:00
|
|
|
|
aWhereStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("="));
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aWhereStr += aCriteria;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// nur einmal f<>r jedes Feld
|
2002-08-30 10:13:38 +00:00
|
|
|
|
else if ( !i && pEntryField->isCondition() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (!aWhereStr.getLength()) // noch keine Kriterien
|
|
|
|
|
aWhereStr += ::rtl::OUString('('); // Klammern
|
|
|
|
|
else
|
|
|
|
|
aWhereStr += C_AND;
|
|
|
|
|
aWhereStr += pEntryField->GetField();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (aWhereStr.getLength())
|
|
|
|
|
{
|
|
|
|
|
aWhereStr += ::rtl::OUString(')'); // Klammern zu fuer 'AND' Zweig
|
|
|
|
|
if (rRetStr.getLength()) // schon Feldbedingungen ?
|
|
|
|
|
rRetStr += C_OR;
|
|
|
|
|
else // Klammern auf fuer 'OR' Zweig
|
|
|
|
|
rRetStr += ::rtl::OUString('(');
|
|
|
|
|
rRetStr += aWhereStr;
|
|
|
|
|
}
|
|
|
|
|
if (aHavingStr.getLength())
|
|
|
|
|
{
|
|
|
|
|
aHavingStr += ::rtl::OUString(')'); // Klammern zu fuer 'AND' Zweig
|
|
|
|
|
if (rHavingStr.getLength()) // schon Feldbedingungen ?
|
|
|
|
|
rHavingStr += C_OR;
|
|
|
|
|
else // Klammern auf fuer 'OR' Zweig
|
|
|
|
|
rHavingStr += ::rtl::OUString('(');
|
|
|
|
|
rHavingStr += aHavingStr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (rRetStr.getLength())
|
|
|
|
|
rRetStr += ::rtl::OUString(')'); // Klammern zu fuer 'OR' Zweig
|
|
|
|
|
if (rHavingStr.getLength())
|
|
|
|
|
rHavingStr += ::rtl::OUString(')'); // Klammern zu fuer 'OR' Zweig
|
|
|
|
|
}
|
|
|
|
|
catch(SQLException&)
|
|
|
|
|
{
|
|
|
|
|
OSL_ASSERT(!"Failure while building where clause!");
|
|
|
|
|
}
|
|
|
|
|
return sal_True;
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GenerateOrder( OQueryDesignView* _pView,
|
|
|
|
|
OTableFields& _rFieldList,
|
|
|
|
|
sal_Bool bMulti,
|
|
|
|
|
::rtl::OUString& _rsRet)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XConnection> xConnection = static_cast<OQueryController*>(_pView->getController())->getConnection();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( !xConnection.is() )
|
|
|
|
|
return eNoConnection;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
|
|
|
|
|
|
|
|
|
::rtl::OUString aColumnName;
|
2002-08-30 10:13:38 +00:00
|
|
|
|
::rtl::OUString aWorkStr;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
try
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
|
|
|
|
|
// * darf keine Filter enthalten : habe ich die entsprechende Warnung schon angezeigt ?
|
|
|
|
|
sal_Bool bCritsOnAsterikWarning = sal_False; // ** TMFS **
|
|
|
|
|
OTableFields::iterator aIter = _rFieldList.begin();
|
|
|
|
|
|
|
|
|
|
for(;aIter != _rFieldList.end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OTableFieldDescRef pEntryField = *aIter;
|
|
|
|
|
EOrderDir eOrder = pEntryField->GetOrderDir();
|
2001-12-10 10:04:08 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// nur wenn eine Sortierung und ein Tabellenname vorhanden ist-> erzeugen
|
|
|
|
|
// sonst werden die Expressions vom Order By im GenerateCriteria mit erzeugt
|
2005-03-10 15:52:55 +00:00
|
|
|
|
if ( eOrder != ORDER_NONE )
|
2001-12-10 10:04:08 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aColumnName = pEntryField->GetField();
|
|
|
|
|
if(aColumnName.toChar() == '*')
|
|
|
|
|
{
|
|
|
|
|
// die entsprechende MessageBox nur beim ersten mal anzeigen
|
|
|
|
|
if (!bCritsOnAsterikWarning)
|
|
|
|
|
ErrorBox(_pView, ModuleRes( ERR_QRY_ORDERBY_ON_ASTERISK)).Execute();
|
|
|
|
|
bCritsOnAsterikWarning = sal_True;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
|
|
|
|
|
if ( pEntryField->GetFieldAlias().getLength() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aWorkStr += ::dbtools::quoteName(aQuote, pEntryField->GetFieldAlias());
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
else if ( pEntryField->isNumericOrAggreateFunction() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
DBG_ASSERT(pEntryField->GetFunction().getLength(),"Functionname darf hier nicht leer sein! ;-(");
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aWorkStr += pEntryField->GetFunction();
|
|
|
|
|
aWorkStr += ::rtl::OUString('(');
|
|
|
|
|
aWorkStr += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
|
|
|
|
|
// only quote column name when we don't have a numeric
|
|
|
|
|
if ( pEntryField->isNumeric() )
|
|
|
|
|
aWorkStr += aColumnName;
|
|
|
|
|
else
|
|
|
|
|
aWorkStr += ::dbtools::quoteName(aQuote, aColumnName);
|
|
|
|
|
|
|
|
|
|
aWorkStr += ::rtl::OUString(')');
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aWorkStr += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
|
|
|
|
|
aWorkStr += ::dbtools::quoteName(aQuote, aColumnName);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aWorkStr += ::rtl::OUString(' ');
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aWorkStr += String::CreateFromAscii( ";ASC;DESC" ).GetToken( eOrder );
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aWorkStr += ::rtl::OUString(',');
|
2001-12-10 10:04:08 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
{
|
|
|
|
|
String sTemp(aWorkStr);
|
|
|
|
|
sTemp.EraseTrailingChars( ',' );
|
|
|
|
|
aWorkStr = sTemp;
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( aWorkStr.getLength() )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
sal_Int32 nMaxOrder = xMetaData->getMaxColumnsInOrderBy();
|
2002-08-30 10:13:38 +00:00
|
|
|
|
String sToken(aWorkStr);
|
|
|
|
|
if ( nMaxOrder && nMaxOrder < sToken.GetTokenCount(',') )
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = eStatementTooLong;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
_rsRet = ::rtl::OUString::createFromAscii(" ORDER BY ");
|
|
|
|
|
_rsRet += aWorkStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
catch(SQLException&)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSL_ASSERT(!"Failure while building group by!");
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2001-10-05 05:49:21 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString BuildACriteria( const OQueryDesignView* _pView,const ::rtl::OUString& _rVal, sal_Int32 aType )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aRetStr;
|
|
|
|
|
String aVal,rVal;
|
|
|
|
|
String aOpList;aOpList.AssignAscii("<>;>=;<=;<;>;=;LIKE");
|
|
|
|
|
xub_StrLen nOpListCnt = aOpList.GetTokenCount();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
String aToken;
|
|
|
|
|
for( xub_StrLen nIdx=0 ; nIdx < nOpListCnt ; nIdx++ )
|
|
|
|
|
{
|
|
|
|
|
aToken = aOpList.GetToken(nIdx);
|
|
|
|
|
if (rVal.Search( aToken ) == 0)
|
|
|
|
|
{
|
|
|
|
|
aRetStr = ::rtl::OUString(' ');
|
|
|
|
|
aRetStr += aToken;
|
|
|
|
|
aRetStr += ::rtl::OUString(' ');
|
|
|
|
|
aVal = rVal.Copy( aToken.Len() );
|
|
|
|
|
aVal.EraseLeadingChars( ' ' );
|
|
|
|
|
if( aVal.Search( '\'' ) == STRING_NOTFOUND )//XXX O'Brien???
|
|
|
|
|
{
|
|
|
|
|
aVal = QuoteField(_pView, aVal, aType );
|
|
|
|
|
}
|
|
|
|
|
aRetStr += aVal;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if( !aRetStr.getLength()) // == 0
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aRetStr = rVal.Search( '%' ) == STRING_NOTFOUND ? ::rtl::OUString::createFromAscii(" = ") : ::rtl::OUString::createFromAscii(" LIKE ");
|
|
|
|
|
aVal = rVal;
|
|
|
|
|
if( aVal.Search( '\'' ) == STRING_NOTFOUND )//XXX O'Brien???
|
|
|
|
|
{
|
|
|
|
|
aVal = QuoteField( _pView,aVal, aType );
|
|
|
|
|
}
|
|
|
|
|
aRetStr += aVal;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return aRetStr;//XXX
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
void GenerateInnerJoinCriterias(const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString& _rJoinCrit,
|
|
|
|
|
const ::std::vector<OTableConnection*>* _pConnList)
|
2001-10-26 06:57:11 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::std::vector<OTableConnection*>::const_iterator aIter = _pConnList->begin();
|
|
|
|
|
for(;aIter != _pConnList->end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
const OQueryTableConnection* pEntryConn = static_cast<const OQueryTableConnection*>(*aIter);
|
|
|
|
|
OQueryTableConnectionData* pEntryConnData = static_cast<OQueryTableConnectionData*>(pEntryConn->GetData());
|
|
|
|
|
if(pEntryConnData->GetJoinType() == INNER_JOIN)
|
|
|
|
|
{
|
|
|
|
|
if(_rJoinCrit.getLength())
|
|
|
|
|
_rJoinCrit += C_AND;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
_rJoinCrit += BuildJoinCriteria(_xConnection,pEntryConnData->GetConnLineDataList(),pEntryConnData);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-10-26 06:57:11 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
void searchAndAppendName(const Reference< XConnection>& _xConnection,
|
2002-02-19 13:04:20 +00:00
|
|
|
|
const OQueryTableWindow* _pTableWindow,
|
|
|
|
|
map< ::rtl::OUString,sal_Bool,::comphelper::UStringMixLess>& _rTableNames,
|
2003-09-04 07:33:37 +00:00
|
|
|
|
::rtl::OUString& _rsTableListStr
|
|
|
|
|
)
|
2002-02-19 13:04:20 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString sTabName(BuildTable(_xConnection,_pTableWindow));
|
2002-02-19 13:04:20 +00:00
|
|
|
|
|
|
|
|
|
if(_rTableNames.find(sTabName) == _rTableNames.end())
|
|
|
|
|
{
|
|
|
|
|
_rTableNames[sTabName] = sal_True;
|
|
|
|
|
_rsTableListStr += sTabName;
|
|
|
|
|
_rsTableListStr += ::rtl::OUString(',');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString GenerateFromClause( const Reference< XConnection>& _xConnection,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const OQueryTableView::OTableWindowMap* pTabList,
|
2003-09-04 07:33:37 +00:00
|
|
|
|
const ::std::vector<OTableConnection*>* pConnList
|
|
|
|
|
)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aTableListStr;
|
|
|
|
|
// wird gebraucht um sicher zustelllen das eine Tabelle nicht doppelt vorkommt
|
2005-03-23 09:53:49 +00:00
|
|
|
|
map< ::rtl::OUString,sal_Bool,::comphelper::UStringMixLess> aTableNames;
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// generate outer join clause in from
|
|
|
|
|
if(!pConnList->empty())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-19 13:04:20 +00:00
|
|
|
|
::std::vector<OTableConnection*>::const_iterator aIter = pConnList->begin();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
for(;aIter != pConnList->end();++aIter)
|
|
|
|
|
static_cast<OQueryTableConnection*>(*aIter)->SetVisited(sal_False);
|
|
|
|
|
|
|
|
|
|
aIter = pConnList->begin();
|
|
|
|
|
for(;aIter != pConnList->end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableConnection* pEntryConn = static_cast<OQueryTableConnection*>(*aIter);
|
|
|
|
|
if(!pEntryConn->IsVisited())
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aJoin;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
GetNextJoin(_xConnection,pEntryConn,static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin()),aJoin);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
if(aJoin.getLength())
|
|
|
|
|
{
|
2005-03-23 09:53:49 +00:00
|
|
|
|
// insert tables into table list to avoid double entries
|
|
|
|
|
OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
|
|
|
|
|
OQueryTableWindow* pEntryTabTo = static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin());
|
|
|
|
|
|
|
|
|
|
::rtl::OUString sTabName(BuildTable(_xConnection,pEntryTabFrom));
|
|
|
|
|
if(aTableNames.find(sTabName) == aTableNames.end())
|
|
|
|
|
aTableNames[sTabName] = sal_True;
|
|
|
|
|
sTabName = BuildTable(_xConnection,pEntryTabTo);
|
|
|
|
|
if(aTableNames.find(sTabName) == aTableNames.end())
|
|
|
|
|
aTableNames[sTabName] = sal_True;
|
|
|
|
|
|
|
|
|
|
// create join
|
2004-08-02 15:12:50 +00:00
|
|
|
|
sal_Bool bUseEscape = ::dbtools::isDataSourcePropertyEnabled(_xConnection,PROPERTY_OUTERJOINESCAPE,sal_True);
|
2004-03-15 11:43:43 +00:00
|
|
|
|
::rtl::OUString aStr;
|
|
|
|
|
if ( bUseEscape )
|
|
|
|
|
aStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("{ OJ "));
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aStr += aJoin;
|
2004-03-15 11:43:43 +00:00
|
|
|
|
if ( bUseEscape )
|
|
|
|
|
aStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" }"));
|
|
|
|
|
aStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aTableListStr += aStr;
|
|
|
|
|
}
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// and now all inner joins
|
|
|
|
|
aIter = pConnList->begin();
|
|
|
|
|
for(;aIter != pConnList->end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
OQueryTableConnection* pEntryConn = static_cast<OQueryTableConnection*>(*aIter);
|
|
|
|
|
if(!pEntryConn->IsVisited())
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
searchAndAppendName(_xConnection,
|
2002-02-19 13:04:20 +00:00
|
|
|
|
static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin()),
|
|
|
|
|
aTableNames,
|
|
|
|
|
aTableListStr);
|
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
searchAndAppendName(_xConnection,
|
2002-02-19 13:04:20 +00:00
|
|
|
|
static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin()),
|
|
|
|
|
aTableNames,
|
|
|
|
|
aTableListStr);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// all tables that haven't a connection to anyone
|
|
|
|
|
OQueryTableView::OTableWindowMap::const_iterator aTabIter = pTabList->begin();
|
|
|
|
|
for(;aTabIter != pTabList->end();++aTabIter)
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const OQueryTableWindow* pEntryTab = static_cast<const OQueryTableWindow*>(aTabIter->second);
|
|
|
|
|
if(!pEntryTab->ExistsAConn())
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
aTableListStr += BuildTable(_xConnection,pEntryTab);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aTableListStr += ::rtl::OUString(',');
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
if(aTableListStr.getLength())
|
|
|
|
|
aTableListStr = aTableListStr.replaceAt(aTableListStr.getLength()-1,1, ::rtl::OUString() );
|
|
|
|
|
return aTableListStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
::rtl::OUString GenerateGroupBy(const OQueryDesignView* _pView,OTableFields& _rFieldList, sal_Bool bMulti )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XConnection> xConnection = static_cast<OQueryController*>(_pView->getController())->getConnection();
|
|
|
|
|
if(!xConnection.is())
|
|
|
|
|
return ::rtl::OUString();
|
|
|
|
|
|
|
|
|
|
::rtl::OUString aGroupByStr;
|
|
|
|
|
try
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OTableFields::iterator aIter = _rFieldList.begin();
|
|
|
|
|
for(;aIter != _rFieldList.end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2001-10-11 07:38:14 +00:00
|
|
|
|
OTableFieldDescRef pEntryField = *aIter;
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pEntryField->IsGroupBy() )
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
DBG_ASSERT(pEntryField->GetField().getLength(),"Kein FieldName vorhanden!;-(");
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aGroupByStr += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
// only quote the field name when it isn't calculated
|
|
|
|
|
if ( pEntryField->isNoneFunction() )
|
|
|
|
|
aGroupByStr += ::dbtools::quoteName(aQuote, pEntryField->GetField());
|
|
|
|
|
else
|
|
|
|
|
aGroupByStr += pEntryField->GetField();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aGroupByStr += ::rtl::OUString(',');
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( aGroupByStr.getLength() )
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aGroupByStr = aGroupByStr.replaceAt(aGroupByStr.getLength()-1,1, ::rtl::OUString(' ') );
|
|
|
|
|
::rtl::OUString aGroupByStr2 = ::rtl::OUString::createFromAscii(" GROUP BY ");
|
|
|
|
|
aGroupByStr2 += aGroupByStr;
|
|
|
|
|
aGroupByStr = aGroupByStr2;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
catch(SQLException&)
|
|
|
|
|
{
|
|
|
|
|
OSL_ASSERT(!"Failure while building group by!");
|
|
|
|
|
}
|
|
|
|
|
return aGroupByStr;
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetORCriteria(OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
2002-05-06 08:45:36 +00:00
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
int& nLevel ,
|
|
|
|
|
sal_Bool bHaving = sal_False);
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
SqlParseError GetSelectionCriteria( OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pNode,
|
|
|
|
|
int& rLevel,
|
|
|
|
|
sal_Bool bJoinWhere = sal_False)
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (!SQL_ISRULE(pNode, select_statement))
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eNoSelectStatement;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// nyi: mehr Pruefung auf korrekte Struktur!
|
|
|
|
|
pNode = pNode ? pNode->getChild(3)->getChild(1) : NULL;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
// no where clause found
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (!pNode || pNode->isLeaf())
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eOk;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
// Naechster freier Satz ...
|
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::connectivity::OSQLParseNode * pCondition = pNode->getChild(1);
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( pCondition ) // no where clause
|
2002-02-19 13:04:20 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
// now we have to chech the other conditions
|
|
|
|
|
// first make the logical easier
|
2002-02-19 13:04:20 +00:00
|
|
|
|
::connectivity::OSQLParseNode::negateSearchCondition(pCondition);
|
|
|
|
|
::connectivity::OSQLParseNode *pNodeTmp = pNode->getChild(1);
|
2002-10-07 12:09:48 +00:00
|
|
|
|
|
2002-02-19 13:04:20 +00:00
|
|
|
|
::connectivity::OSQLParseNode::disjunctiveNormalForm(pNodeTmp);
|
|
|
|
|
pNodeTmp = pNode->getChild(1);
|
|
|
|
|
::connectivity::OSQLParseNode::absorptions(pNodeTmp);
|
|
|
|
|
pNodeTmp = pNode->getChild(1);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-19 13:04:20 +00:00
|
|
|
|
// first extract the inner joins conditions
|
|
|
|
|
GetInnerJoinCriteria(_pView,pNodeTmp);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-19 13:04:20 +00:00
|
|
|
|
// it could happen that pCondition is not more valid
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pNodeTmp, rLevel);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetANDCriteria( OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
const int nLevel,
|
|
|
|
|
sal_Bool bHaving );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2004-03-15 11:43:43 +00:00
|
|
|
|
SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
const int nLevel,
|
|
|
|
|
sal_Bool bHaving );
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetORCriteria(OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
int& nLevel ,
|
|
|
|
|
sal_Bool bHaving)
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
// Runde Klammern um den Ausdruck
|
|
|
|
|
if (pCondition->count() == 3 &&
|
|
|
|
|
SQL_ISPUNCTUATION(pCondition->getChild(0),"(") &&
|
|
|
|
|
SQL_ISPUNCTUATION(pCondition->getChild(2),")"))
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1),nLevel,bHaving);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
// oder Verknuepfung
|
|
|
|
|
// a searchcondition can only look like this: search_condition SQL_TOKEN_OR boolean_term
|
|
|
|
|
else if (SQL_ISRULE(pCondition,search_condition))
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
for (int i = 0; i < 3 && eErrorCode == eOk ; i+=2)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( SQL_ISRULE(pCondition->getChild(i),search_condition) )
|
|
|
|
|
eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(i),nLevel,bHaving);
|
2001-10-11 07:38:14 +00:00
|
|
|
|
else
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(i), nLevel++,bHaving);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = GetANDCriteria( _pView,_pSelectionBrw,pCondition, nLevel, bHaving );
|
|
|
|
|
|
|
|
|
|
return eErrorCode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetANDCriteria( OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
const int nLevel,
|
|
|
|
|
sal_Bool bHaving )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
::com::sun::star::lang::Locale aLocale = _pView->getLocale();
|
|
|
|
|
::rtl::OUString sDecimal = _pView->getDecimalSeparator();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// ich werde ein paar Mal einen gecasteten Pointer auf meinen ::com::sun::star::sdbcx::Container brauchen
|
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(_pView->getController());
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Runde Klammern
|
|
|
|
|
if (SQL_ISRULE(pCondition,boolean_primary))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
int nLevel2 = nLevel;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1), nLevel2,bHaving );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
// Das erste Element ist (wieder) eine AND-Verknuepfung
|
|
|
|
|
else if ( SQL_ISRULE(pCondition,boolean_term) && pCondition->count() == 3 )
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(0), nLevel,bHaving );
|
|
|
|
|
if ( eErrorCode == eOk )
|
|
|
|
|
eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(2), nLevel,bHaving );
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else if (SQL_ISRULE( pCondition, comparison_predicate))
|
|
|
|
|
{
|
2004-03-15 11:43:43 +00:00
|
|
|
|
eErrorCode = ComparisonPredicate(_pView,_pSelectionBrw,pCondition,nLevel,bHaving);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
else if( SQL_ISRULE(pCondition,like_predicate) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if (SQL_ISRULE(pCondition->getChild(0), column_ref ) )
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aColumnName;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString aCondition;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XConnection> xConnection = pController->getConnection();
|
2002-04-09 14:30:33 +00:00
|
|
|
|
if ( xConnection.is() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
// the international doesn't matter I have a string
|
|
|
|
|
pCondition->parseNodeToPredicateStr(aCondition,
|
|
|
|
|
xMetaData,
|
|
|
|
|
pController->getNumberFormatter(),
|
|
|
|
|
aLocale,
|
|
|
|
|
static_cast<sal_Char>(sDecimal.toChar()),
|
|
|
|
|
&pController->getParser()->getContext());
|
|
|
|
|
|
|
|
|
|
pCondition->getChild(0)->parseNodeToPredicateStr( aColumnName,
|
|
|
|
|
xMetaData,
|
|
|
|
|
pController->getNumberFormatter(),
|
|
|
|
|
aLocale,
|
|
|
|
|
static_cast<sal_Char>(sDecimal.toChar()),
|
|
|
|
|
&pController->getParser()->getContext());
|
|
|
|
|
|
|
|
|
|
// don't display the column name
|
|
|
|
|
aCondition = aCondition.copy(aColumnName.getLength());
|
|
|
|
|
aCondition = aCondition.trim();
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
|
|
|
|
if ( eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft) ))
|
2002-02-06 07:08:30 +00:00
|
|
|
|
_pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel);
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = eNoColumnInLike;
|
|
|
|
|
String sError(ModuleRes(STR_QRY_LIKE_LEFT_NO_COLUMN));
|
|
|
|
|
_pView->getController()->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000") ),1000,Any()));
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-19 13:04:20 +00:00
|
|
|
|
else if( SQL_ISRULEOR2(pCondition,test_for_null,in_predicate)
|
|
|
|
|
|| SQL_ISRULEOR2(pCondition,all_or_any_predicate,between_predicate))
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2004-03-15 11:43:43 +00:00
|
|
|
|
if ( SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
|
|
|
|
|
{
|
|
|
|
|
AddFunctionCondition( _pView,
|
|
|
|
|
_pSelectionBrw,
|
|
|
|
|
pCondition,
|
|
|
|
|
nLevel,
|
|
|
|
|
bHaving);
|
|
|
|
|
}
|
|
|
|
|
else if ( SQL_ISRULE(pCondition->getChild(0), column_ref ) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
// parse condition
|
2004-03-15 11:43:43 +00:00
|
|
|
|
::rtl::OUString sCondition = ParseCondition(pController,pCondition,sDecimal,aLocale,1);
|
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
|
|
|
|
if ( eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) )
|
2004-09-09 08:48:21 +00:00
|
|
|
|
_pSelectionBrw->AddCondition(aDragLeft, sCondition, nLevel);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-19 13:04:20 +00:00
|
|
|
|
else if( SQL_ISRULEOR2(pCondition,existence_test,unique_test) )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Funktions-Bedingung parsen
|
2004-03-15 11:43:43 +00:00
|
|
|
|
::rtl::OUString aCondition = ParseCondition(pController,pCondition,sDecimal,aLocale,0);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2004-03-15 11:43:43 +00:00
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aDragLeft->SetField(aCondition);
|
|
|
|
|
aDragLeft->SetFunctionType(FKT_CONDITION);
|
|
|
|
|
|
2002-08-19 07:01:32 +00:00
|
|
|
|
eErrorCode = _pSelectionBrw->InsertField(aDragLeft,BROWSER_INVALIDID,sal_False,sal_True).isValid() ? eOk : eTooManyColumns;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
else //! TODO not supported yet
|
|
|
|
|
eErrorCode = eStatementTooComplex;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Fehler einfach weiterreichen.
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2004-03-15 11:43:43 +00:00
|
|
|
|
SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
|
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
const int nLevel,
|
|
|
|
|
sal_Bool bHaving)
|
|
|
|
|
{
|
|
|
|
|
SqlParseError eErrorCode = eOk;
|
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(_pView->getController());
|
|
|
|
|
OSL_ENSURE(SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ),"Illegal call!");
|
|
|
|
|
::rtl::OUString aCondition;
|
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
|
|
|
|
|
|
|
|
|
OSQLParseNode* pFunction = pCondition->getChild(0);
|
|
|
|
|
|
|
|
|
|
::rtl::OUString aColumnName;
|
|
|
|
|
Reference< XConnection> xConnection = pController->getConnection();
|
|
|
|
|
if(xConnection.is())
|
|
|
|
|
{
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
pCondition->parseNodeToPredicateStr(aCondition,
|
|
|
|
|
xMetaData,
|
|
|
|
|
pController->getNumberFormatter(),
|
|
|
|
|
_pView->getLocale(),
|
|
|
|
|
static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
|
|
|
|
|
&pController->getParser()->getContext());
|
|
|
|
|
|
|
|
|
|
pFunction->parseNodeToPredicateStr(aColumnName,
|
|
|
|
|
xMetaData,
|
|
|
|
|
pController->getNumberFormatter(),
|
|
|
|
|
_pView->getLocale(),
|
|
|
|
|
static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
|
|
|
|
|
&pController->getParser()->getContext());
|
|
|
|
|
// don't display the column name
|
|
|
|
|
aCondition = aCondition.copy(aColumnName.getLength());
|
|
|
|
|
aCondition = aCondition.trim();
|
|
|
|
|
if ( aCondition.indexOf('=',0) == 0 ) // ignore the equal sign
|
|
|
|
|
aCondition = aCondition.copy(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( SQL_ISRULE(pFunction, general_set_fct ) )
|
|
|
|
|
{
|
|
|
|
|
sal_Int32 nFunctionType = FKT_AGGREGATE;
|
|
|
|
|
OSQLParseNode* pParamNode = pFunction->getChild(pFunction->count()-2);
|
|
|
|
|
if ( pParamNode && pParamNode->getTokenValue().toChar() == '*' )
|
|
|
|
|
{
|
|
|
|
|
OJoinTableView::OTableWindowMap* pTabList = _pView->getTableView()->GetTabWinMap();
|
|
|
|
|
OJoinTableView::OTableWindowMap::iterator aIter = pTabList->begin();
|
|
|
|
|
for(;aIter != pTabList->end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
|
|
|
|
|
if (pTabWin->ExistsField( ::rtl::OUString::createFromAscii("*"), aDragLeft ))
|
|
|
|
|
{
|
|
|
|
|
aDragLeft->SetAlias(String());
|
|
|
|
|
aDragLeft->SetTable(String());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if( eOk != ( eErrorCode = FillDragInfo(_pView,pParamNode,aDragLeft))
|
|
|
|
|
&& SQL_ISRULE(pParamNode,num_value_exp) )
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString sParameterValue;
|
|
|
|
|
pParamNode->parseNodeToStr( sParameterValue,
|
|
|
|
|
xConnection->getMetaData(),
|
|
|
|
|
&pController->getParser()->getContext());
|
|
|
|
|
nFunctionType |= FKT_NUMERIC;
|
|
|
|
|
aDragLeft->SetField(sParameterValue);
|
|
|
|
|
eErrorCode = eOk;
|
|
|
|
|
}
|
|
|
|
|
aDragLeft->SetFunctionType(nFunctionType);
|
|
|
|
|
if ( bHaving )
|
|
|
|
|
aDragLeft->SetGroupBy(sal_True);
|
|
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
|
aDragLeft->SetFunction(aColumnName.getToken(0,'(',nIndex));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// bei unbekannten Funktionen wird der gesamte Text in das Field gechrieben
|
|
|
|
|
aDragLeft->SetField(aColumnName);
|
|
|
|
|
if(bHaving)
|
|
|
|
|
aDragLeft->SetGroupBy(sal_True);
|
|
|
|
|
aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
|
|
|
|
|
}
|
|
|
|
|
_pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return eErrorCode;
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode * pCondition,
|
|
|
|
|
const int nLevel,
|
|
|
|
|
sal_Bool bHaving )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(_pView->getController());
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2004-03-15 11:43:43 +00:00
|
|
|
|
DBG_ASSERT(SQL_ISRULE( pCondition, comparison_predicate),"ComparisonPredicate: pCondition ist kein ComparisonPredicate");
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( SQL_ISRULE(pCondition->getChild(0), column_ref )
|
|
|
|
|
|| SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
::rtl::OUString aCondition;
|
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
|
|
|
|
|
if ( SQL_ISRULE(pCondition->getChild(0), column_ref ) && SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
OTableFieldDescRef aDragRight = new OTableFieldDesc();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if (eOk != ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) ||
|
|
|
|
|
eOk != ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(2),aDragRight)))
|
|
|
|
|
return eErrorCode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
OQueryTableConnection* pConn = static_cast<OQueryTableConnection*>(_pView->getTableView()->GetTabConn(static_cast<OQueryTableWindow*>(aDragLeft->GetTabWindow()),
|
|
|
|
|
static_cast<OQueryTableWindow*>(aDragRight->GetTabWindow())));
|
|
|
|
|
if(pConn)
|
|
|
|
|
{
|
|
|
|
|
OConnectionLineDataVec* pLineDataList = pConn->GetData()->GetConnLineDataList();
|
|
|
|
|
OConnectionLineDataVec::iterator aIter = pLineDataList->begin();
|
|
|
|
|
for(;aIter != pLineDataList->end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
if((*aIter)->GetSourceFieldName() == aDragLeft->GetField() ||
|
|
|
|
|
(*aIter)->GetDestFieldName() == aDragLeft->GetField() )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(aIter != pLineDataList->end())
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2004-02-04 12:55:13 +00:00
|
|
|
|
sal_uInt32 nPos = 0;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(SQL_ISRULE(pCondition->getChild(0), column_ref ))
|
|
|
|
|
{
|
|
|
|
|
nPos = 0;
|
|
|
|
|
sal_uInt32 i=1;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// don't display the equal
|
|
|
|
|
if (pCondition->getChild(i)->getNodeType() == SQL_NODE_EQUAL)
|
|
|
|
|
i++;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Bedingung parsen
|
2004-03-15 11:43:43 +00:00
|
|
|
|
aCondition = ParseCondition(pController
|
|
|
|
|
,pCondition
|
|
|
|
|
,_pView->getDecimalSeparator()
|
|
|
|
|
,_pView->getLocale()
|
|
|
|
|
,i);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
else if( SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
nPos = pCondition->count()-1;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2004-03-02 11:46:44 +00:00
|
|
|
|
sal_Int32 i = static_cast<sal_Int32>(pCondition->count() - 2);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
switch (pCondition->getChild(i)->getNodeType())
|
|
|
|
|
{
|
|
|
|
|
case SQL_NODE_EQUAL:
|
|
|
|
|
// don't display the equal
|
|
|
|
|
i--;
|
|
|
|
|
break;
|
|
|
|
|
case SQL_NODE_LESS:
|
|
|
|
|
// take the opposite as we change the order
|
|
|
|
|
i--;
|
|
|
|
|
aCondition = aCondition + ::rtl::OUString::createFromAscii(">");
|
|
|
|
|
break;
|
|
|
|
|
case SQL_NODE_LESSEQ:
|
|
|
|
|
// take the opposite as we change the order
|
|
|
|
|
i--;
|
|
|
|
|
aCondition = aCondition + ::rtl::OUString::createFromAscii(">=");
|
|
|
|
|
break;
|
|
|
|
|
case SQL_NODE_GREAT:
|
|
|
|
|
// take the opposite as we change the order
|
|
|
|
|
i--;
|
|
|
|
|
aCondition = aCondition + ::rtl::OUString::createFromAscii("<");
|
|
|
|
|
break;
|
|
|
|
|
case SQL_NODE_GREATEQ:
|
|
|
|
|
// take the opposite as we change the order
|
|
|
|
|
i--;
|
|
|
|
|
aCondition = aCondition + ::rtl::OUString::createFromAscii("<=");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// go backward
|
|
|
|
|
Reference< XConnection> xConnection = pController->getConnection();
|
|
|
|
|
if(xConnection.is())
|
|
|
|
|
{
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
for (; i >= 0; i--)
|
|
|
|
|
pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
|
|
|
|
|
xMetaData,
|
|
|
|
|
pController->getNumberFormatter(),
|
|
|
|
|
_pView->getLocale(),
|
|
|
|
|
static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
|
|
|
|
|
&pController->getParser()->getContext());
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2004-02-04 12:55:13 +00:00
|
|
|
|
// else ???
|
|
|
|
|
|
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if( eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(nPos),aDragLeft)))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(bHaving)
|
|
|
|
|
aDragLeft->SetGroupBy(sal_True);
|
|
|
|
|
_pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-19 13:04:20 +00:00
|
|
|
|
else if( SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2004-03-15 11:43:43 +00:00
|
|
|
|
AddFunctionCondition( _pView,
|
|
|
|
|
_pSelectionBrw,
|
|
|
|
|
pCondition,
|
|
|
|
|
nLevel,
|
|
|
|
|
bHaving);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else // kann sich nur um einen Expr. Ausdruck handeln
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aName,aCondition;
|
|
|
|
|
|
|
|
|
|
::connectivity::OSQLParseNode *pLhs = pCondition->getChild(0);
|
|
|
|
|
::connectivity::OSQLParseNode *pRhs = pCondition->getChild(2);
|
|
|
|
|
// Feldnamen
|
|
|
|
|
Reference< XConnection> xConnection = pController->getConnection();
|
2001-06-28 13:22:47 +00:00
|
|
|
|
if(xConnection.is())
|
|
|
|
|
{
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
2004-03-15 11:43:43 +00:00
|
|
|
|
pLhs->parseNodeToStr(aName,
|
|
|
|
|
xMetaData,
|
|
|
|
|
&pController->getParser()->getContext(),
|
|
|
|
|
sal_True);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Kriterium
|
|
|
|
|
aCondition = pCondition->getChild(1)->getTokenValue();
|
2004-03-15 11:43:43 +00:00
|
|
|
|
pRhs->parseNodeToPredicateStr(aCondition,
|
|
|
|
|
xMetaData,
|
|
|
|
|
pController->getNumberFormatter(),
|
|
|
|
|
_pView->getLocale(),
|
|
|
|
|
static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
|
|
|
|
|
&pController->getParser()->getContext());
|
2001-06-28 13:22:47 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aDragLeft->SetField(aName);
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// und anh"angen
|
|
|
|
|
_pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
void InsertColumnRef(const OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const ::connectivity::OSQLParseNode * pColumnRef,
|
|
|
|
|
::rtl::OUString& aColumnName,
|
|
|
|
|
const ::rtl::OUString& aColumnAlias,
|
|
|
|
|
::rtl::OUString& aTableRange,
|
|
|
|
|
OTableFieldDescRef& _raInfo,
|
|
|
|
|
OJoinTableView::OTableWindowMap* pTabList)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Tabellennamen zusammen setzen
|
|
|
|
|
::connectivity::OSQLParseTreeIterator& rParseIter = static_cast<OQueryController*>(_pView->getController())->getParseIterator();
|
|
|
|
|
rParseIter.getColumnRange( pColumnRef, aColumnName, aTableRange );
|
|
|
|
|
|
2002-02-19 13:04:20 +00:00
|
|
|
|
sal_Bool bFound(sal_False);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
DBG_ASSERT(aColumnName.getLength(),"Columnname darf nicht leer sein");
|
|
|
|
|
if (!aTableRange.getLength())
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// SELECT column, ...
|
|
|
|
|
OJoinTableView::OTableWindowMap::iterator aIter = pTabList->begin();
|
|
|
|
|
for(;aIter != pTabList->end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
|
2002-02-19 13:04:20 +00:00
|
|
|
|
if (pTabWin && pTabWin->ExistsField( aColumnName, _raInfo ) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
if(aColumnName.toChar() != '*')
|
|
|
|
|
_raInfo->SetFieldAlias(aColumnAlias);
|
|
|
|
|
bFound = sal_True;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-28 13:22:47 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// SELECT range.column, ...
|
|
|
|
|
OQueryTableWindow* pTabWin = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable(aTableRange);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (pTabWin && pTabWin->ExistsField(aColumnName, _raInfo))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(aColumnName.toChar() != '*')
|
|
|
|
|
_raInfo->SetFieldAlias(aColumnAlias);
|
2002-02-19 13:04:20 +00:00
|
|
|
|
bFound = sal_True;
|
2002-09-20 09:25:38 +00:00
|
|
|
|
}
|
2002-02-19 13:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
if (!bFound)
|
|
|
|
|
{
|
|
|
|
|
_raInfo->SetTable(::rtl::OUString());
|
|
|
|
|
_raInfo->SetAlias(::rtl::OUString());
|
|
|
|
|
_raInfo->SetField(aColumnName);
|
|
|
|
|
_raInfo->SetFieldAlias(aColumnAlias); // nyi : hier ein fortlaufendes Expr_1, Expr_2 ...
|
|
|
|
|
_raInfo->SetFunctionType(FKT_OTHER);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-19 13:04:20 +00:00
|
|
|
|
sal_Bool checkJoinConditions( const OQueryDesignView* _pView,
|
|
|
|
|
const ::connectivity::OSQLParseNode* _pNode )
|
|
|
|
|
{
|
|
|
|
|
const ::connectivity::OSQLParseNode* pJoinNode = NULL;
|
|
|
|
|
sal_Bool bRet = sal_True;
|
|
|
|
|
if (SQL_ISRULE(_pNode,qualified_join))
|
|
|
|
|
pJoinNode = _pNode;
|
|
|
|
|
else if (SQL_ISRULE(_pNode, joined_table))
|
|
|
|
|
pJoinNode = _pNode->getChild(1);
|
2002-05-06 08:45:36 +00:00
|
|
|
|
else if (! ( SQL_ISRULE(_pNode, table_ref) &&
|
|
|
|
|
(SQL_ISRULEOR2(_pNode->getChild(0), catalog_name, schema_name) ||
|
|
|
|
|
SQL_ISRULE(_pNode->getChild(0), table_name))))
|
2002-02-19 13:04:20 +00:00
|
|
|
|
bRet = sal_False;
|
|
|
|
|
|
|
|
|
|
if (pJoinNode && !InsertJoin(_pView,pJoinNode))
|
|
|
|
|
bRet = sal_False;
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
sal_Bool InsertJoin(const OQueryDesignView* _pView,
|
|
|
|
|
const ::connectivity::OSQLParseNode *pNode)
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
DBG_ASSERT(SQL_ISRULE(pNode, qualified_join) || SQL_ISRULE(pNode, joined_table),
|
|
|
|
|
"OQueryDesignView::InsertJoin: Fehler im Parse Tree");
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (SQL_ISRULE(pNode,joined_table))
|
|
|
|
|
return InsertJoin(_pView,pNode->getChild(1));
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-19 13:04:20 +00:00
|
|
|
|
// first check the left and right side
|
|
|
|
|
if ( !checkJoinConditions(_pView,pNode->getChild(0)) || !checkJoinConditions(_pView,pNode->getChild(3)))
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return sal_False;
|
2001-09-27 05:19:05 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// named column join wird sp<73>ter vieleicht noch implementiert
|
|
|
|
|
// SQL_ISRULE(pNode->getChild(4),named_columns_join)
|
|
|
|
|
if (SQL_ISRULE(pNode->getChild(4),join_condition))
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
EJoinType eJoinType;
|
|
|
|
|
::connectivity::OSQLParseNode* pJoinType = pNode->getChild(1); // join_type
|
|
|
|
|
if (SQL_ISRULE(pJoinType,join_type) && SQL_ISTOKEN(pJoinType->getChild(0),INNER))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
eJoinType = INNER_JOIN;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2001-09-27 05:19:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (SQL_ISRULE(pJoinType,join_type)) // eine Ebene tiefer
|
|
|
|
|
pJoinType = pJoinType->getChild(0);
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (SQL_ISTOKEN(pJoinType->getChild(0),LEFT))
|
|
|
|
|
eJoinType = LEFT_JOIN;
|
|
|
|
|
else if(SQL_ISTOKEN(pJoinType->getChild(0),RIGHT))
|
|
|
|
|
eJoinType = RIGHT_JOIN;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
else
|
2002-02-06 07:08:30 +00:00
|
|
|
|
eJoinType = FULL_JOIN;
|
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( InsertJoinConnection(_pView,pNode->getChild(4)->getChild(1), eJoinType) != eOk )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return sal_False;
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
else
|
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
|
|
return sal_True;
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-30 10:13:38 +00:00
|
|
|
|
void insertUnUsedFields(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw)
|
|
|
|
|
{
|
|
|
|
|
// now we have to insert the fields which aren't in the statement
|
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(_pView->getController());
|
|
|
|
|
OTableFields& rUnUsedFields = pController->getUnUsedFields();
|
|
|
|
|
for(OTableFields::iterator aIter = rUnUsedFields.begin();aIter != rUnUsedFields.end();++aIter)
|
|
|
|
|
if(_pSelectionBrw->InsertField(*aIter,BROWSER_INVALIDID,sal_False,sal_False).isValid())
|
|
|
|
|
(*aIter) = NULL;
|
|
|
|
|
OTableFields().swap( rUnUsedFields );
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError InitFromParseNodeImpl(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
|
|
|
|
|
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(_pView->getController());
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
_pSelectionBrw->PreFill();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
_pSelectionBrw->SetReadOnly(pController->isReadOnly());
|
2002-02-06 07:08:30 +00:00
|
|
|
|
_pSelectionBrw->Fill();
|
2001-02-05 15:17:40 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::connectivity::OSQLParseTreeIterator& aIterator = pController->getParseIterator();
|
|
|
|
|
const ::connectivity::OSQLParseNode* pParseTree = aIterator.getParseTree();
|
|
|
|
|
const ::connectivity::OSQLParseNode* pTableRefCommaList = 0;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (pParseTree)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if (!pController->isEsacpeProcessing()) // not allowed in this mode
|
|
|
|
|
eErrorCode = eNativeMode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else if (SQL_ISRULE(pParseTree,select_statement))
|
|
|
|
|
{
|
|
|
|
|
::connectivity::OSQLParseNode* pTree = pParseTree->getChild(1);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
const OSQLTables& aMap = aIterator.getTables();
|
|
|
|
|
::comphelper::UStringMixLess aTmp(aMap.key_comp());
|
|
|
|
|
::comphelper::UStringMixEqual aKeyComp(static_cast< ::comphelper::UStringMixLess*>(&aTmp)->isCaseSensitive());
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XConnection> xConnection = pController->getConnection();
|
|
|
|
|
if(xConnection.is())
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
sal_Int32 nMax = 0;
|
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
try
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nMax = xMetaData->getMaxTablesInSelect();
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(!nMax || nMax >= (sal_Int32)aMap.size()) // Anzahl der Tabellen im Select-Statement "uberpr"ufen
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString sComposedName;
|
|
|
|
|
::rtl::OUString aQualifierName;
|
|
|
|
|
::rtl::OUString sAlias;
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableView* pTableView = static_cast<OQueryTableView*>(_pView->getTableView());
|
|
|
|
|
OSQLTables::const_iterator aIter = aMap.begin();
|
|
|
|
|
for(;aIter != aMap.end();++aIter)
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSQLTable xTable = aIter->second;
|
2004-08-02 15:12:50 +00:00
|
|
|
|
sComposedName = ::dbtools::composeTableName(xMetaData,Reference<XPropertySet>(xTable,UNO_QUERY),sal_False,::dbtools::eInDataManipulation);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
sAlias = aIter->first;
|
|
|
|
|
if(aKeyComp(sComposedName,aIter->first))
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString sCatalog,sSchema,sTable;
|
2002-10-07 12:09:48 +00:00
|
|
|
|
::dbtools::qualifiedNameComponents(xMetaData,sComposedName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
sAlias = sTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OQueryTableWindow* pExistentWin = pTableView->FindTable(sAlias);
|
|
|
|
|
if (!pExistentWin)
|
|
|
|
|
{
|
|
|
|
|
pTableView->AddTabWin(sComposedName, sAlias,sal_False);// don't create data here
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// es existiert schon ein Fenster mit dem selben Alias ...
|
|
|
|
|
if (!aKeyComp(pExistentWin->GetData()->GetComposedName(),sComposedName))
|
|
|
|
|
// ... aber anderem Tabellennamen -> neues Fenster
|
|
|
|
|
pTableView->AddTabWin(sComposedName, sAlias);
|
|
|
|
|
}
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
// now delete the data for which we haven't any tablewindow
|
|
|
|
|
OJoinTableView::OTableWindowMap* pTableMap = pTableView->GetTabWinMap();
|
|
|
|
|
OJoinTableView::OTableWindowMap::iterator aIterTableMap = pTableMap->begin();
|
|
|
|
|
for(;aIterTableMap != pTableMap->end();++aIterTableMap)
|
2001-10-11 07:38:14 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(aMap.find(aIterTableMap->second->GetComposedName()) == aMap.end() &&
|
|
|
|
|
aMap.find(aIterTableMap->first) == aMap.end())
|
|
|
|
|
pTableView->RemoveTabWin(aIterTableMap->second);
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2001-02-05 15:17:40 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( eOk == (eErrorCode = FillOuterJoins(_pView,pParseTree->getChild(3)->getChild(0)->getChild(1))) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
// check if we have a distinct statement
|
|
|
|
|
if(SQL_ISTOKEN(pParseTree->getChild(1),DISTINCT))
|
|
|
|
|
{
|
|
|
|
|
pController->setDistinct(sal_True);
|
2004-09-09 08:48:21 +00:00
|
|
|
|
pController->InvalidateFeature(SID_QUERY_DISTINCT_VALUES);
|
2002-05-06 08:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
if ( (eErrorCode = InstallFields(_pView,pParseTree, pTableView->GetTabWinMap())) == eOk )
|
|
|
|
|
{
|
|
|
|
|
// GetSelectionCriteria mu"s vor GetHavingCriteria aufgerufen werden
|
|
|
|
|
int nLevel=0;
|
|
|
|
|
|
|
|
|
|
if ( eOk == (eErrorCode = GetSelectionCriteria(_pView,_pSelectionBrw,pParseTree,nLevel,sal_True)) )
|
|
|
|
|
{
|
|
|
|
|
if ( eOk == (eErrorCode = GetGroupCriteria(_pView,_pSelectionBrw,pParseTree)) )
|
|
|
|
|
{
|
|
|
|
|
if ( eOk == (eErrorCode = GetHavingCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
|
|
|
|
|
{
|
|
|
|
|
if ( eOk == (eErrorCode = GetOrderCriteria(_pView,_pSelectionBrw,pParseTree)) )
|
2002-08-30 10:13:38 +00:00
|
|
|
|
insertUnUsedFields(_pView,_pSelectionBrw);
|
2002-05-06 08:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
2001-10-11 07:38:14 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = eTooManyTables;
|
2001-06-28 13:22:47 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
catch(SQLException&)
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSL_ASSERT(!"getMaxTablesInSelect!");
|
2001-06-28 13:22:47 +00:00
|
|
|
|
}
|
2001-02-05 15:17:40 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = eNoSelectStatement;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// now we have to insert the fields which aren't in the statement
|
|
|
|
|
insertUnUsedFields(_pView,_pSelectionBrw);
|
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Durch das Neuerzeugen wurden wieder Undo-Actions in den Manager gestellt
|
|
|
|
|
pController->getUndoMgr()->Clear();
|
|
|
|
|
_pSelectionBrw->Invalidate();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
/** fillSelectSubList
|
|
|
|
|
@return
|
|
|
|
|
<TRUE/> when columns could be inserted otherwise <FALSE/>
|
|
|
|
|
*/
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
SqlParseError fillSelectSubList( OQueryDesignView* _pView,
|
2002-02-19 13:04:20 +00:00
|
|
|
|
OJoinTableView::OTableWindowMap* _pTabList)
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-19 13:04:20 +00:00
|
|
|
|
sal_Bool bFirstField = sal_True;
|
|
|
|
|
::rtl::OUString sAsterix(RTL_CONSTASCII_USTRINGPARAM("*"));
|
|
|
|
|
OTableFieldDescRef aInfo = new OTableFieldDesc();
|
|
|
|
|
OJoinTableView::OTableWindowMap::iterator aIter = _pTabList->begin();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
for(;aIter != _pTabList->end() && eOk == eErrorCode ;++aIter)
|
2002-02-19 13:04:20 +00:00
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
|
|
|
|
|
|
|
|
|
|
if (pTabWin->ExistsField( sAsterix, aInfo ))
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
|
2002-02-19 13:04:20 +00:00
|
|
|
|
bFirstField = sal_False;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2002-02-19 13:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError InstallFields(OQueryDesignView* _pView,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pNode,
|
|
|
|
|
OJoinTableView::OTableWindowMap* pTabList )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if( pNode==0 || !SQL_ISRULE(pNode,select_statement))
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eNoSelectStatement;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::connectivity::OSQLParseNode* pParseTree = pNode->getChild(2);
|
|
|
|
|
sal_Bool bFirstField = sal_True; // bei der Initialisierung mu<6D> auf alle Faelle das erste Feld neu aktiviert werden
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
|
|
|
|
|
|
|
|
|
if ( pParseTree->isRule() && SQL_ISPUNCTUATION(pParseTree->getChild(0),"*") )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// SELECT * ...
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = fillSelectSubList(_pView,pTabList);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else if (SQL_ISRULE(pParseTree,scalar_exp_commalist) )
|
|
|
|
|
{
|
|
|
|
|
// SELECT column, ...
|
2002-05-06 08:45:36 +00:00
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(_pView->getController());
|
|
|
|
|
Reference< XConnection> xConnection = pController->getConnection();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
::rtl::OUString aColumnName,aTableRange;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
for (sal_uInt32 i = 0; i < pParseTree->count() && eOk == eErrorCode ; ++i)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::connectivity::OSQLParseNode * pColumnRef = pParseTree->getChild(i);
|
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( SQL_ISRULE(pColumnRef,select_sublist) )
|
2004-03-15 11:43:43 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = fillSelectSubList(_pView,pTabList);
|
2004-03-15 11:43:43 +00:00
|
|
|
|
}
|
2003-09-04 07:33:37 +00:00
|
|
|
|
else if ( SQL_ISRULE(pColumnRef,derived_column) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( xConnection.is() )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
|
|
|
|
|
::rtl::OUString aColumnAlias(pController->getParseIterator().getColumnAlias(pColumnRef)); // kann leer sein
|
|
|
|
|
pColumnRef = pColumnRef->getChild(0);
|
2002-02-19 13:04:20 +00:00
|
|
|
|
OTableFieldDescRef aInfo = new OTableFieldDesc();
|
|
|
|
|
|
2004-08-02 15:12:50 +00:00
|
|
|
|
if (
|
|
|
|
|
pColumnRef->count() == 3 &&
|
|
|
|
|
SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") &&
|
|
|
|
|
SQL_ISPUNCTUATION(pColumnRef->getChild(2),")")
|
|
|
|
|
)
|
|
|
|
|
pColumnRef = pColumnRef->getChild(1);
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (SQL_ISRULE(pColumnRef,column_ref))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
InsertColumnRef(_pView,pColumnRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
|
|
|
|
|
eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
|
|
|
|
|
bFirstField = sal_False;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-19 13:04:20 +00:00
|
|
|
|
else if(SQL_ISRULEOR2(pColumnRef,general_set_fct ,set_fct_spec) ||
|
|
|
|
|
SQL_ISRULEOR2(pColumnRef,position_exp,extract_exp) ||
|
2003-09-04 07:33:37 +00:00
|
|
|
|
SQL_ISRULEOR2(pColumnRef,fold,char_substring_fct) ||
|
2002-02-19 13:04:20 +00:00
|
|
|
|
SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
::rtl::OUString aColumns;
|
|
|
|
|
pColumnRef->parseNodeToStr( aColumns,
|
|
|
|
|
xMetaData,
|
|
|
|
|
&pController->getParser()->getContext(),
|
|
|
|
|
sal_True,
|
|
|
|
|
sal_True); // quote is to true because we need quoted elements inside the function
|
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
sal_Int32 nFunctionType = FKT_NONE;
|
2003-03-19 16:57:12 +00:00
|
|
|
|
::connectivity::OSQLParseNode* pParamRef = NULL;
|
|
|
|
|
sal_Int32 nColumnRefPos = pColumnRef->count() - 2;
|
2004-03-02 11:46:44 +00:00
|
|
|
|
if ( nColumnRefPos >= 0 && static_cast<sal_uInt32>(nColumnRefPos) < pColumnRef->count() )
|
2003-03-19 16:57:12 +00:00
|
|
|
|
pParamRef = pColumnRef->getChild(nColumnRefPos);
|
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( SQL_ISRULE(pColumnRef,general_set_fct)
|
|
|
|
|
&& SQL_ISRULE(pParamRef,column_ref) )
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// Parameter auf Columnref pr"ufen
|
2002-05-06 08:45:36 +00:00
|
|
|
|
InsertColumnRef(_pView,pParamRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
|
2001-06-28 13:22:47 +00:00
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
else if ( SQL_ISRULE(pColumnRef,general_set_fct) )
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pParamRef && pParamRef->getTokenValue().toChar() == '*' )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
OJoinTableView::OTableWindowMap::iterator aIter = pTabList->begin();
|
|
|
|
|
for(;aIter != pTabList->end();++aIter)
|
|
|
|
|
{
|
|
|
|
|
OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
|
|
|
|
|
if (pTabWin->ExistsField( ::rtl::OUString::createFromAscii("*"), aInfo ))
|
|
|
|
|
{
|
|
|
|
|
aInfo->SetAlias(String());
|
|
|
|
|
aInfo->SetTable(String());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
::rtl::OUString sFieldName = aColumns;
|
|
|
|
|
if ( pParamRef )
|
|
|
|
|
{ // we got an aggregate function but without column name inside
|
|
|
|
|
// so we set the whole argument of the function as field name
|
|
|
|
|
nFunctionType |= FKT_NUMERIC;
|
|
|
|
|
sFieldName = ::rtl::OUString();
|
|
|
|
|
pParamRef->parseNodeToStr( sFieldName,
|
|
|
|
|
xMetaData,
|
|
|
|
|
&pController->getParser()->getContext(),
|
|
|
|
|
sal_True,
|
|
|
|
|
sal_True); // quote is to true because we need quoted elements inside the function
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aInfo->SetDataType(DataType::DOUBLE);
|
|
|
|
|
aInfo->SetFieldType(TAB_NORMAL_FIELD);
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aInfo->SetField(sFieldName);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
aInfo->SetTabWindow(NULL);
|
|
|
|
|
aInfo->SetFieldAlias(aColumnAlias);
|
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// get the type out of the funtion name
|
|
|
|
|
nFunctionType |= FKT_NUMERIC;
|
|
|
|
|
sal_Int32 nDataType = DataType::DOUBLE;
|
|
|
|
|
::rtl::OUString sFieldName = aColumns;
|
|
|
|
|
OSQLParseNode* pFunctionName = pColumnRef->getChild(0);
|
|
|
|
|
if ( !SQL_ISPUNCTUATION(pFunctionName,"{") )
|
|
|
|
|
{
|
2003-03-19 16:57:12 +00:00
|
|
|
|
if ( SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
|
2002-08-30 10:13:38 +00:00
|
|
|
|
pFunctionName = pFunctionName->getChild(0);
|
|
|
|
|
|
|
|
|
|
::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
|
|
|
|
|
if ( !sFunctionName.getLength() )
|
2003-08-18 14:05:15 +00:00
|
|
|
|
sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_UTF8);
|
2002-08-30 10:13:38 +00:00
|
|
|
|
|
|
|
|
|
nDataType = OSQLParser::getFunctionReturnType(
|
|
|
|
|
sFunctionName
|
|
|
|
|
,&pController->getParser()->getContext());
|
|
|
|
|
}
|
|
|
|
|
aInfo->SetDataType(nDataType);
|
|
|
|
|
aInfo->SetFieldType(TAB_NORMAL_FIELD);
|
|
|
|
|
aInfo->SetField(sFieldName);
|
|
|
|
|
aInfo->SetTabWindow(NULL);
|
|
|
|
|
aInfo->SetFieldAlias(aColumnAlias);
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( SQL_ISRULE(pColumnRef,general_set_fct) )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aInfo->SetFunctionType(nFunctionType|FKT_AGGREGATE);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
String aCol(aColumns);
|
|
|
|
|
aInfo->SetFunction(aCol.GetToken(0,'(').EraseTrailingChars(' '));
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aInfo->SetFunctionType(nFunctionType|FKT_OTHER);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
bFirstField = sal_False;
|
|
|
|
|
}
|
|
|
|
|
else //if(SQL_ISRULE(pColumnRef,num_value_exp) || SQL_ISRULE(pColumnRef,term))
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString aColumns;
|
|
|
|
|
pColumnRef->parseNodeToStr( aColumns,
|
|
|
|
|
xMetaData,
|
|
|
|
|
&pController->getParser()->getContext(),
|
|
|
|
|
sal_True,
|
2004-10-22 08:06:51 +00:00
|
|
|
|
sal_True); // quote is to true because we need quoted elements inside the function
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
aInfo->SetDataType(DataType::DOUBLE);
|
|
|
|
|
aInfo->SetFieldType(TAB_NORMAL_FIELD);
|
|
|
|
|
aInfo->SetTabWindow(NULL);
|
|
|
|
|
aInfo->SetField(aColumns);
|
2001-10-05 05:49:21 +00:00
|
|
|
|
aInfo->SetFieldAlias(aColumnAlias);
|
2002-08-30 10:13:38 +00:00
|
|
|
|
aInfo->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
bFirstField = sal_False;
|
2001-06-28 13:22:47 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = eStatementTooComplex;
|
2001-06-28 13:22:47 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetOrderCriteria( OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pParseRoot )
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (!pParseRoot->getChild(3)->getChild(4)->isLeaf())
|
|
|
|
|
{
|
|
|
|
|
::connectivity::OSQLParseNode* pNode = pParseRoot->getChild(3)->getChild(4)->getChild(2);
|
|
|
|
|
::connectivity::OSQLParseNode* pParamRef = NULL;
|
|
|
|
|
|
|
|
|
|
EOrderDir eOrderDir;
|
|
|
|
|
OTableFieldDescRef aDragLeft = new OTableFieldDesc();
|
|
|
|
|
for( sal_uInt32 i=0 ; i<pNode->count() ; i++ )
|
|
|
|
|
{
|
|
|
|
|
eOrderDir = ORDER_ASC;
|
|
|
|
|
::connectivity::OSQLParseNode* pChild = pNode->getChild( i );
|
|
|
|
|
|
|
|
|
|
if (SQL_ISTOKEN( pChild->getChild(1), DESC ) )
|
|
|
|
|
eOrderDir = ORDER_DESC;
|
|
|
|
|
|
|
|
|
|
if(SQL_ISRULE(pChild->getChild(0),column_ref))
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if( eOk == FillDragInfo(_pView,pChild->getChild(0),aDragLeft))
|
2005-03-10 15:52:55 +00:00
|
|
|
|
_pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
else // it could be a alias name for a field
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString aTableRange,aColumnName;
|
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(_pView->getController());
|
|
|
|
|
|
|
|
|
|
::connectivity::OSQLParseTreeIterator& rParseIter = pController->getParseIterator();
|
|
|
|
|
rParseIter.getColumnRange( pChild->getChild(0), aColumnName, aTableRange );
|
|
|
|
|
|
|
|
|
|
OTableFields& aList = pController->getTableFieldDesc();
|
|
|
|
|
OTableFields::iterator aIter = aList.begin();
|
|
|
|
|
for(;aIter != aList.end();++aIter)
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OTableFieldDescRef pEntry = *aIter;
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if(pEntry.isValid() && pEntry->GetFieldAlias() == aColumnName)
|
2002-02-06 07:08:30 +00:00
|
|
|
|
pEntry->SetOrderDir( eOrderDir );
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
else if(SQL_ISRULE(pChild->getChild(0),general_set_fct) &&
|
|
|
|
|
SQL_ISRULE(pParamRef = pChild->getChild(0)->getChild(pChild->getChild(0)->count()-2),column_ref) &&
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eOk == FillDragInfo(_pView,pParamRef,aDragLeft))
|
2005-03-10 15:52:55 +00:00
|
|
|
|
_pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i );
|
2002-05-06 08:45:36 +00:00
|
|
|
|
else
|
|
|
|
|
eErrorCode = eColumnNotFound;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetHavingCriteria( OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pSelectRoot,
|
|
|
|
|
int &rLevel )
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (!pSelectRoot->getChild(3)->getChild(3)->isLeaf())
|
2002-05-06 08:45:36 +00:00
|
|
|
|
eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSelectRoot->getChild(3)->getChild(3)->getChild(1),rLevel, sal_True);
|
|
|
|
|
return eErrorCode;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError GetGroupCriteria( OQueryDesignView* _pView,
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OSelectionBrowseBox* _pSelectionBrw,
|
|
|
|
|
const ::connectivity::OSQLParseNode* pSelectRoot )
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode = eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (!pSelectRoot->getChild(3)->getChild(2)->isLeaf())
|
|
|
|
|
{
|
|
|
|
|
::connectivity::OSQLParseNode* pGroupBy = pSelectRoot->getChild(3)->getChild(2)->getChild(2);
|
|
|
|
|
OTableFieldDescRef aDragInfo = new OTableFieldDesc();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
for( sal_uInt32 i=0 ; i < pGroupBy->count() && eOk == eErrorCode; ++i )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
::connectivity::OSQLParseNode* pColumnRef = pGroupBy->getChild( i );
|
|
|
|
|
if(SQL_ISRULE(pColumnRef,column_ref))
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( eOk == (eErrorCode = FillDragInfo(_pView,pColumnRef,aDragInfo)) )
|
2001-06-28 13:22:47 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aDragInfo->SetGroupBy(sal_True);
|
2005-03-10 15:52:55 +00:00
|
|
|
|
_pSelectionBrw->AddGroupBy(aDragInfo,i);
|
2001-06-28 13:22:47 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return eErrorCode;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
void showParseError(IEnvironment* _pEnvironment,SqlParseError _eErrorCode)
|
|
|
|
|
{
|
|
|
|
|
USHORT nResId;
|
|
|
|
|
switch(_eErrorCode)
|
|
|
|
|
{
|
|
|
|
|
case eIllegalJoin:
|
|
|
|
|
nResId = STR_QRY_ILLEGAL_JOIN;
|
|
|
|
|
break;
|
|
|
|
|
case eStatementTooLong:
|
|
|
|
|
nResId = STR_QRY_TOO_LONG_STATEMENT;
|
|
|
|
|
break;
|
|
|
|
|
case eNoConnection:
|
|
|
|
|
nResId = STR_QRY_SYNTAX;
|
|
|
|
|
break;
|
|
|
|
|
case eNoSelectStatement:
|
|
|
|
|
nResId = STR_QRY_NOSELECT;
|
|
|
|
|
break;
|
|
|
|
|
case eColumnInLikeNotFound:
|
|
|
|
|
nResId = STR_QRY_SYNTAX;
|
|
|
|
|
break;
|
|
|
|
|
case eNoColumnInLike:
|
|
|
|
|
nResId = STR_QRY_SYNTAX;
|
|
|
|
|
break;
|
|
|
|
|
case eColumnNotFound:
|
|
|
|
|
nResId = STR_QRY_SYNTAX;
|
|
|
|
|
break;
|
|
|
|
|
case eNativeMode:
|
|
|
|
|
nResId = STR_QRY_NATIVE;
|
|
|
|
|
break;
|
|
|
|
|
case eTooManyTables:
|
|
|
|
|
nResId = STR_QRY_TOO_MANY_TABLES;
|
|
|
|
|
break;
|
|
|
|
|
case eTooManyConditions:
|
|
|
|
|
nResId = STR_QRY_TOOMANYCOND;
|
|
|
|
|
break;
|
|
|
|
|
case eTooManyColumns:
|
|
|
|
|
nResId = STR_QRY_TOO_MANY_COLUMNS;
|
|
|
|
|
break;
|
|
|
|
|
case eStatementTooComplex:
|
|
|
|
|
nResId = STR_QRY_TOOCOMPLEX;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
nResId = STR_QRY_SYNTAX;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// ErrorBox( _pWindow, ModuleRes( nResId ) ).Execute();
|
2002-05-10 07:23:32 +00:00
|
|
|
|
ModuleRes aRes(nResId);
|
|
|
|
|
String sError(aRes);
|
2002-05-06 08:45:36 +00:00
|
|
|
|
_pEnvironment->appendError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HY0000") ),1000,Any()));
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
} // end of anonymouse namespace
|
|
|
|
|
|
|
|
|
|
OQueryDesignView::OQueryDesignView( OQueryContainerWindow* _pParent,
|
|
|
|
|
OQueryController* _pController,
|
|
|
|
|
const Reference< XMultiServiceFactory >& _rFactory)
|
|
|
|
|
:OQueryView(_pParent,_pController,_rFactory)
|
|
|
|
|
,m_aSplitter( this )
|
|
|
|
|
,m_eChildFocus(NONE)
|
2002-02-11 12:02:08 +00:00
|
|
|
|
,m_bInKeyEvent(sal_False)
|
2002-05-24 12:03:58 +00:00
|
|
|
|
,m_bInSplitHandler( sal_False )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2002-04-09 14:49:26 +00:00
|
|
|
|
SvtSysLocale aSysLocale;
|
|
|
|
|
m_aLocale = aSysLocale.GetLocaleData().getLocale();
|
|
|
|
|
m_sDecimalSep = aSysLocale.GetLocaleData().getNumDecimalSep();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
catch(Exception&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pSelectionBox = new OSelectionBrowseBox(this);
|
2002-05-06 08:45:36 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
setNoneVisbleRow(static_cast<OQueryController*>(getController())->getVisibleRows());
|
|
|
|
|
m_pSelectionBox->Show();
|
|
|
|
|
// Splitter einrichten
|
|
|
|
|
m_aSplitter.SetSplitHdl(LINK(this, OQueryDesignView,SplitHdl));
|
|
|
|
|
m_aSplitter.Show();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
OQueryDesignView::~OQueryDesignView()
|
|
|
|
|
{
|
2005-03-10 15:52:55 +00:00
|
|
|
|
if ( m_pTableView )
|
|
|
|
|
::dbaui::notifySystemWindow(this,m_pTableView,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
|
2002-05-07 06:19:29 +00:00
|
|
|
|
::std::auto_ptr<Window> aTemp(m_pSelectionBox);
|
|
|
|
|
m_pSelectionBox = NULL;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
IMPL_LINK( OQueryDesignView, SplitHdl, void*, p )
|
|
|
|
|
{
|
2002-02-19 13:04:20 +00:00
|
|
|
|
if (!getController()->isReadOnly())
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-05-24 12:03:58 +00:00
|
|
|
|
m_bInSplitHandler = sal_True;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
long nTest = m_aSplitter.GetPosPixel().Y();
|
|
|
|
|
m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),m_aSplitter.GetSplitPosPixel() ) );
|
2002-02-19 13:04:20 +00:00
|
|
|
|
static_cast<OQueryController*>(getController())->setSplitPos(m_aSplitter.GetSplitPosPixel());
|
|
|
|
|
static_cast<OQueryController*>(getController())->setModified();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
Resize();
|
2002-05-24 12:03:58 +00:00
|
|
|
|
m_bInSplitHandler = sal_True;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
return 0L;
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::Construct()
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
m_pTableView = new OQueryTableView(m_pScrollWindow,this);
|
|
|
|
|
::dbaui::notifySystemWindow(this,m_pTableView,::comphelper::mem_fun(&TaskPaneList::AddWindow));
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryView::Construct();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::initialize()
|
|
|
|
|
{
|
|
|
|
|
if(static_cast<OQueryController*>(getController())->getSplitPos() != -1)
|
|
|
|
|
{
|
|
|
|
|
m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),static_cast<OQueryController*>(getController())->getSplitPos() ) );
|
|
|
|
|
m_aSplitter.SetSplitPosPixel(static_cast<OQueryController*>(getController())->getSplitPos());
|
|
|
|
|
}
|
|
|
|
|
m_pSelectionBox->initialize();
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::resizeDocumentView(Rectangle& _rPlayground)
|
|
|
|
|
{
|
|
|
|
|
Point aPlaygroundPos( _rPlayground.TopLeft() );
|
|
|
|
|
Size aPlaygroundSize( _rPlayground.GetSize() );
|
|
|
|
|
|
|
|
|
|
// calc the split pos, and forward it to the controller
|
|
|
|
|
sal_Int32 nSplitPos = static_cast<OQueryController*>(getController())->getSplitPos();
|
2002-05-24 12:03:58 +00:00
|
|
|
|
if ( 0 != aPlaygroundSize.Height() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-05-24 12:03:58 +00:00
|
|
|
|
if ( ( -1 == nSplitPos )
|
|
|
|
|
|| ( nSplitPos >= aPlaygroundSize.Height() )
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
// let the selection browse box determine an optimal size
|
|
|
|
|
Size aSelectionBoxSize = m_pSelectionBox->CalcOptimalSize( aPlaygroundSize );
|
|
|
|
|
nSplitPos = aPlaygroundSize.Height() - aSelectionBoxSize.Height() - m_aSplitter.GetSizePixel().Height();
|
|
|
|
|
// still an invalid size?
|
|
|
|
|
if ( nSplitPos == -1 || nSplitPos >= aPlaygroundSize.Height() )
|
|
|
|
|
nSplitPos = sal_Int32(aPlaygroundSize.Height()*0.6);
|
|
|
|
|
|
|
|
|
|
static_cast<OQueryController*>(getController())->setSplitPos(nSplitPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !m_bInSplitHandler )
|
|
|
|
|
{ // the resize is triggered by something else than the split handler
|
|
|
|
|
// our main focus is to try to preserve the size of the selectionbrowse box
|
|
|
|
|
Size aSelBoxSize = m_pSelectionBox->GetSizePixel();
|
|
|
|
|
if ( aSelBoxSize.Height() )
|
|
|
|
|
{
|
|
|
|
|
// keep the size of the sel box constant
|
|
|
|
|
nSplitPos = aPlaygroundSize.Height() - m_aSplitter.GetSizePixel().Height() - aSelBoxSize.Height();
|
|
|
|
|
|
|
|
|
|
// and if the box is smaller than the optimal size, try to do something about it
|
|
|
|
|
Size aSelBoxOptSize = m_pSelectionBox->CalcOptimalSize( aPlaygroundSize );
|
|
|
|
|
if ( aSelBoxOptSize.Height() > aSelBoxSize.Height() )
|
|
|
|
|
{
|
|
|
|
|
nSplitPos = aPlaygroundSize.Height() - m_aSplitter.GetSizePixel().Height() - aSelBoxOptSize.Height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static_cast< OQueryController* >(getController())->setSplitPos( nSplitPos );
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// normalize the split pos
|
|
|
|
|
Point aSplitPos = Point( _rPlayground.Left(), nSplitPos );
|
|
|
|
|
Size aSplitSize = Size( _rPlayground.GetSize().Width(), m_aSplitter.GetSizePixel().Height() );
|
|
|
|
|
|
|
|
|
|
if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
|
|
|
|
|
aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
|
|
|
|
|
|
|
|
|
|
if( aSplitPos.Y() <= aPlaygroundPos.Y() )
|
|
|
|
|
aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.2);
|
|
|
|
|
|
|
|
|
|
// position the table
|
|
|
|
|
Size aTableViewSize(aPlaygroundSize.Width(), aSplitPos.Y() - aPlaygroundPos.Y());
|
|
|
|
|
m_pScrollWindow->SetPosSizePixel(aPlaygroundPos, aTableViewSize);
|
|
|
|
|
|
|
|
|
|
// position the selection browse box
|
|
|
|
|
Point aPos( aPlaygroundPos.X(), aSplitPos.Y() + aSplitSize.Height() );
|
|
|
|
|
m_pSelectionBox->SetPosSizePixel( aPos, Size( aPlaygroundSize.Width(), aPlaygroundSize.Height() - aSplitSize.Height() - aTableViewSize.Height() ));
|
|
|
|
|
|
|
|
|
|
// set the size of the splitter
|
|
|
|
|
m_aSplitter.SetPosSizePixel( aSplitPos, aSplitSize );
|
|
|
|
|
m_aSplitter.SetDragRectPixel( _rPlayground );
|
|
|
|
|
|
|
|
|
|
// just for completeness: there is no space left, we occupied it all ...
|
|
|
|
|
_rPlayground.SetPos( _rPlayground.BottomRight() );
|
|
|
|
|
_rPlayground.SetSize( Size( 0, 0 ) );
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::setReadOnly(sal_Bool _bReadOnly)
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->SetReadOnly(_bReadOnly);
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::clear()
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->ClearAll(); // clear the whole selection
|
|
|
|
|
m_pTableView->ClearAll();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::setStatement(const ::rtl::OUString& _rsStatement)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::copy()
|
|
|
|
|
{
|
|
|
|
|
if( m_eChildFocus == SELECTION)
|
|
|
|
|
m_pSelectionBox->copy();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
BOOL OQueryDesignView::IsAddAllowed()
|
|
|
|
|
{
|
|
|
|
|
return m_pTableView->IsAddAllowed();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
sal_Bool OQueryDesignView::isCutAllowed()
|
|
|
|
|
{
|
|
|
|
|
sal_Bool bAllowed = sal_False;
|
|
|
|
|
switch(m_eChildFocus)
|
|
|
|
|
{
|
|
|
|
|
case SELECTION:
|
|
|
|
|
bAllowed = m_pSelectionBox->isCutAllowed();
|
|
|
|
|
break;
|
|
|
|
|
case TABLEVIEW:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return bAllowed;
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
sal_Bool OQueryDesignView::isPasteAllowed()
|
|
|
|
|
{
|
|
|
|
|
sal_Bool bAllowed = sal_False;
|
|
|
|
|
switch(m_eChildFocus)
|
|
|
|
|
{
|
|
|
|
|
case SELECTION:
|
2003-04-01 13:05:00 +00:00
|
|
|
|
bAllowed = m_pSelectionBox->isPasteAllowed();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case TABLEVIEW:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return bAllowed;
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
sal_Bool OQueryDesignView::isCopyAllowed()
|
|
|
|
|
{
|
|
|
|
|
sal_Bool bAllowed = sal_False;
|
|
|
|
|
switch(m_eChildFocus)
|
|
|
|
|
{
|
|
|
|
|
case SELECTION:
|
2003-04-01 13:05:00 +00:00
|
|
|
|
bAllowed = m_pSelectionBox->isCopyAllowed();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case TABLEVIEW:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return bAllowed;
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::stopTimer()
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->stopTimer();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::startTimer()
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->startTimer();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::cut()
|
|
|
|
|
{
|
|
|
|
|
if( m_eChildFocus == SELECTION)
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->cut();
|
|
|
|
|
static_cast<OQueryController*>(getController())->setModified(sal_True);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::paste()
|
|
|
|
|
{
|
|
|
|
|
if( m_eChildFocus == SELECTION)
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->paste();
|
|
|
|
|
static_cast<OQueryController*>(getController())->setModified(sal_True);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::TableDeleted(const ::rtl::OUString& rAliasName)
|
|
|
|
|
{
|
|
|
|
|
// Nachricht, dass Tabelle aus dem Fenster gel"oscht wurde
|
|
|
|
|
DeleteFields(rAliasName);
|
|
|
|
|
static_cast<OQueryController*>(getController())->InvalidateFeature(ID_BROWSER_ADDTABLE); // view nochmal bescheid sagen
|
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::DeleteFields( const ::rtl::OUString& rAliasName )
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->DeleteFields( rAliasName );
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::SaveTabWinUIConfig(OQueryTableWindow* pWin)
|
|
|
|
|
{
|
|
|
|
|
static_cast<OQueryController*>(getController())->SaveTabWinPosSize(pWin, m_pScrollWindow->GetHScrollBar()->GetThumbPos(), m_pScrollWindow->GetVScrollBar()->GetThumbPos());
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError OQueryDesignView::InsertField( const OTableFieldDescRef& rInfo, sal_Bool bVis, sal_Bool bActivate)
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-08-19 07:01:32 +00:00
|
|
|
|
return m_pSelectionBox->InsertField( rInfo, BROWSER_INVALIDID,bVis, bActivate ).isValid() ? eOk : eTooManyColumns;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
sal_Bool OQueryDesignView::getColWidth( const ::rtl::OUString& rAliasName, const ::rtl::OUString& rFieldName, sal_uInt32& nWidth )
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OTableFields& aFields = static_cast<OQueryController*>(getController())->getTableFieldDesc();
|
|
|
|
|
OTableFields::iterator aIter = aFields.begin();
|
|
|
|
|
for(;aIter != aFields.end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-19 13:04:20 +00:00
|
|
|
|
if( rAliasName == (*aIter)->GetFieldAlias() && rFieldName == (*aIter)->GetField())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-19 13:04:20 +00:00
|
|
|
|
nWidth = (*aIter)->GetColWidth();
|
|
|
|
|
return sal_True;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
return sal_False;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-02-06 07:08:30 +00:00
|
|
|
|
void OQueryDesignView::fillValidFields(const ::rtl::OUString& sAliasName, ComboBox* pFieldList)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
DBG_ASSERT(pFieldList != NULL, "OQueryDesignView::FillValidFields : What the hell do you think I can do with a NULL-ptr ? This will crash !");
|
|
|
|
|
pFieldList->Clear();
|
|
|
|
|
|
|
|
|
|
sal_Bool bAllTables = sAliasName.getLength() == 0;
|
|
|
|
|
|
|
|
|
|
OJoinTableView::OTableWindowMap* pTabWins = m_pTableView->GetTabWinMap();
|
|
|
|
|
::rtl::OUString strCurrentPrefix;
|
|
|
|
|
::std::vector< ::rtl::OUString> aFields;
|
|
|
|
|
OJoinTableView::OTableWindowMap::iterator aIter = pTabWins->begin();
|
|
|
|
|
for(;aIter != pTabWins->end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableWindow* pCurrentWin = static_cast<OQueryTableWindow*>(aIter->second);
|
|
|
|
|
if (bAllTables || (pCurrentWin->GetAliasName() == sAliasName))
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
strCurrentPrefix = pCurrentWin->GetAliasName();
|
|
|
|
|
strCurrentPrefix += ::rtl::OUString('.');
|
|
|
|
|
|
|
|
|
|
pCurrentWin->EnumValidFields(aFields);
|
|
|
|
|
|
|
|
|
|
::std::vector< ::rtl::OUString>::iterator aStrIter = aFields.begin();
|
|
|
|
|
for(;aStrIter != aFields.end();++aStrIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (bAllTables || aStrIter->toChar() == '*')
|
|
|
|
|
pFieldList->InsertEntry(::rtl::OUString(strCurrentPrefix) += *aStrIter);
|
|
|
|
|
else
|
|
|
|
|
pFieldList->InsertEntry(*aStrIter);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
if (!bAllTables)
|
|
|
|
|
// das heisst, dass ich in diesen Block kam, weil der Tabellenname genau der gesuchte war, also bin ich fertig
|
|
|
|
|
// (dadurch verhindere ich auch das doppelte Einfuegen von Feldern, wenn eine Tabelle mehrmals als TabWin vorkommt)
|
|
|
|
|
break;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
long OQueryDesignView::PreNotify(NotifyEvent& rNEvt)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
switch (rNEvt.GetType())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
case EVENT_GETFOCUS:
|
2003-04-15 15:03:54 +00:00
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2002-08-30 10:13:38 +00:00
|
|
|
|
{
|
|
|
|
|
Window* pFocus = Application::GetFocusWindow();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if ( m_pSelectionBox && m_pSelectionBox->HasChildPathFocus() )
|
2002-05-06 08:45:36 +00:00
|
|
|
|
m_eChildFocus = SELECTION;
|
|
|
|
|
else
|
|
|
|
|
m_eChildFocus = TABLEVIEW;
|
2002-02-11 12:02:08 +00:00
|
|
|
|
break;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return OQueryView::PreNotify(rNEvt);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// check if the statement is correct when not returning false
|
|
|
|
|
sal_Bool OQueryDesignView::checkStatement()
|
|
|
|
|
{
|
2003-03-19 16:57:12 +00:00
|
|
|
|
sal_Bool bRet = sal_True;
|
|
|
|
|
if ( m_pSelectionBox )
|
|
|
|
|
bRet = m_pSelectionBox->Save(); // a error occured so we return no
|
|
|
|
|
return bRet;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
|
::rtl::OUString OQueryDesignView::getStatement()
|
|
|
|
|
{
|
|
|
|
|
OQueryController* pController = static_cast<OQueryController*>(getController());
|
2002-05-06 08:45:36 +00:00
|
|
|
|
m_pController->clearError();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// used for fields which aren't any longer in the statement
|
|
|
|
|
OTableFields& rUnUsedFields = pController->getUnUsedFields();
|
|
|
|
|
OTableFields().swap( rUnUsedFields );
|
|
|
|
|
|
|
|
|
|
// create the select columns
|
|
|
|
|
sal_uInt32 nFieldcount = 0;
|
|
|
|
|
OTableFields& rFieldList = pController->getTableFieldDesc();
|
|
|
|
|
OTableFields::iterator aIter = rFieldList.begin();
|
|
|
|
|
for(;aIter != rFieldList.end();++aIter)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OTableFieldDescRef pEntryField = *aIter;
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pEntryField->GetField().getLength() && pEntryField->IsVisible() )
|
|
|
|
|
++nFieldcount;
|
|
|
|
|
else if (pEntryField->GetField().getLength() &&
|
2002-02-06 07:08:30 +00:00
|
|
|
|
!pEntryField->HasCriteria() &&
|
2002-08-30 10:13:38 +00:00
|
|
|
|
pEntryField->isNoneFunction() &&
|
2002-02-06 07:08:30 +00:00
|
|
|
|
pEntryField->GetOrderDir() == ORDER_NONE &&
|
2002-08-30 10:13:38 +00:00
|
|
|
|
!pEntryField->GetFunction().getLength() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
rUnUsedFields.push_back(pEntryField);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( !nFieldcount ) // keine Felder sichtbar also zur"uck
|
|
|
|
|
{
|
|
|
|
|
rUnUsedFields = rFieldList;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return ::rtl::OUString();
|
2002-08-30 10:13:38 +00:00
|
|
|
|
}
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
OQueryTableView::OTableWindowMap* pTabList = m_pTableView->GetTabWinMap();
|
|
|
|
|
sal_uInt32 nTabcount = pTabList->size();
|
|
|
|
|
|
|
|
|
|
::rtl::OUString aFieldListStr(GenerateSelectList(this,rFieldList,nTabcount>1));
|
|
|
|
|
if( !aFieldListStr.getLength() )
|
|
|
|
|
return ::rtl::OUString();
|
|
|
|
|
// Ausnahmebehandlung, wenn keine Felder angegeben worden sind
|
|
|
|
|
// Dann darf die Tabpage nicht gewechselt werden
|
|
|
|
|
// Im TabBarSelectHdl wird der SQL-::rtl::OUString auf STATEMENT_NOFIELDS abgefragt
|
|
|
|
|
// und eine Errormeldung erzeugt
|
|
|
|
|
// ----------------- Tabellenliste aufbauen ----------------------
|
|
|
|
|
|
2002-02-19 13:04:20 +00:00
|
|
|
|
const ::std::vector<OTableConnection*>* pConnList = m_pTableView->getTableConnections();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
Reference< XConnection> xConnection = static_cast<OQueryController*>(getController())->getConnection();
|
|
|
|
|
::rtl::OUString aTableListStr(GenerateFromClause(xConnection,pTabList,pConnList));
|
2002-02-06 07:08:30 +00:00
|
|
|
|
DBG_ASSERT(aTableListStr.getLength(), "OQueryDesignView::getStatement() : unerwartet : habe Felder, aber keine Tabellen !");
|
|
|
|
|
// wenn es Felder gibt, koennen die nur durch Einfuegen aus einer schon existenten Tabelle entstanden sein; wenn andererseits
|
|
|
|
|
// eine Tabelle geloescht wird, verschwinden auch die zugehoerigen Felder -> ergo KANN es das nicht geben, dass Felder
|
|
|
|
|
// existieren, aber keine Tabellen (und aFieldListStr hat schon eine Laenge, das stelle ich oben sicher)
|
|
|
|
|
::rtl::OUString aHavingStr,aCriteriaListStr;
|
|
|
|
|
// ----------------- Kriterien aufbauen ----------------------
|
|
|
|
|
if (!GenerateCriterias(this,aCriteriaListStr,aHavingStr,rFieldList, nTabcount > 1))
|
|
|
|
|
return ::rtl::OUString();
|
|
|
|
|
|
|
|
|
|
::rtl::OUString aJoinCrit;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
GenerateInnerJoinCriterias(xConnection,aJoinCrit,pConnList);
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if(aJoinCrit.getLength())
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString aTmp = ::rtl::OUString::createFromAscii("( ");
|
|
|
|
|
aTmp += aJoinCrit;
|
|
|
|
|
aTmp += ::rtl::OUString::createFromAscii(" )");
|
|
|
|
|
if(aCriteriaListStr.getLength())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aTmp += C_AND;
|
|
|
|
|
aTmp += aCriteriaListStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aCriteriaListStr = aTmp;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// ----------------- Statement aufbauen ----------------------
|
|
|
|
|
::rtl::OUString aSqlCmd(::rtl::OUString::createFromAscii("SELECT "));
|
|
|
|
|
if(static_cast<OQueryController*>(getController())->isDistinct())
|
|
|
|
|
aSqlCmd += ::rtl::OUString::createFromAscii(" DISTINCT ");
|
|
|
|
|
aSqlCmd += aFieldListStr;
|
|
|
|
|
aSqlCmd += ::rtl::OUString::createFromAscii(" FROM ");
|
|
|
|
|
aSqlCmd += aTableListStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
if (aCriteriaListStr.getLength())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aSqlCmd += ::rtl::OUString::createFromAscii(" WHERE ");
|
|
|
|
|
aSqlCmd += aCriteriaListStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// ----------------- GroupBy aufbauen und Anh"angen ------------
|
|
|
|
|
Reference<XDatabaseMetaData> xMeta;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( xConnection.is() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
xMeta = xConnection->getMetaData();
|
|
|
|
|
sal_Bool bUseAlias = nTabcount > 1;
|
2002-05-06 08:45:36 +00:00
|
|
|
|
if ( xMeta.is() )
|
2002-02-06 07:08:30 +00:00
|
|
|
|
bUseAlias = bUseAlias || !xMeta->supportsGroupByUnrelated();
|
2002-05-06 08:45:36 +00:00
|
|
|
|
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aSqlCmd += GenerateGroupBy(this,rFieldList,bUseAlias);
|
|
|
|
|
// ----------------- having Anh"angen ------------
|
|
|
|
|
if(aHavingStr.getLength())
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2002-02-06 07:08:30 +00:00
|
|
|
|
aSqlCmd += ::rtl::OUString::createFromAscii(" HAVING ");
|
|
|
|
|
aSqlCmd += aHavingStr;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
// ----------------- Sortierung aufbauen und Anh"angen ------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
::rtl::OUString sOrder;
|
|
|
|
|
SqlParseError eErrorCode = eOk;
|
|
|
|
|
if ( (eErrorCode = GenerateOrder(this,rFieldList,nTabcount > 1,sOrder)) == eOk)
|
|
|
|
|
aSqlCmd += sOrder;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( !m_pController->hasError() ) // fill generell error string
|
|
|
|
|
showParseError(m_pController,eErrorCode);
|
|
|
|
|
|
|
|
|
|
SQLException aError;
|
|
|
|
|
m_pController->getError(aError);
|
|
|
|
|
m_pController->showError(aError);
|
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
|
|
|
|
|
return aSqlCmd;
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable)
|
|
|
|
|
{
|
|
|
|
|
sal_uInt16 nRow;
|
|
|
|
|
switch (_nSlotId)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2004-09-09 08:48:21 +00:00
|
|
|
|
case SID_QUERY_VIEW_FUNCTIONS:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nRow = BROW_FUNCTION_ROW;
|
|
|
|
|
break;
|
2004-09-09 08:48:21 +00:00
|
|
|
|
case SID_QUERY_VIEW_TABLES:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nRow = BROW_TABLE_ROW;
|
|
|
|
|
break;
|
2004-09-09 08:48:21 +00:00
|
|
|
|
case SID_QUERY_VIEW_ALIASES:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nRow = BROW_COLUMNALIAS_ROW;
|
|
|
|
|
break;
|
2004-02-04 12:55:13 +00:00
|
|
|
|
default:
|
|
|
|
|
// ????????????
|
|
|
|
|
nRow = 0;
|
|
|
|
|
break;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
m_pSelectionBox->SetRowVisible(nRow,_bEnable);
|
|
|
|
|
m_pSelectionBox->Invalidate();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
sal_Bool OQueryDesignView::isSlotEnabled(sal_Int32 _nSlotId)
|
|
|
|
|
{
|
|
|
|
|
sal_uInt16 nRow;
|
|
|
|
|
switch (_nSlotId)
|
2001-02-05 08:35:57 +00:00
|
|
|
|
{
|
2004-09-09 08:48:21 +00:00
|
|
|
|
case SID_QUERY_VIEW_FUNCTIONS:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nRow = BROW_FUNCTION_ROW;
|
|
|
|
|
break;
|
2004-09-09 08:48:21 +00:00
|
|
|
|
case SID_QUERY_VIEW_TABLES:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nRow = BROW_TABLE_ROW;
|
|
|
|
|
break;
|
2004-09-09 08:48:21 +00:00
|
|
|
|
case SID_QUERY_VIEW_ALIASES:
|
2002-02-06 07:08:30 +00:00
|
|
|
|
nRow = BROW_COLUMNALIAS_ROW;
|
|
|
|
|
break;
|
2004-02-04 12:55:13 +00:00
|
|
|
|
default:
|
|
|
|
|
// ?????????
|
|
|
|
|
nRow = 0;
|
|
|
|
|
break;
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
2002-02-06 07:08:30 +00:00
|
|
|
|
return m_pSelectionBox->IsRowVisible(nRow);
|
2001-02-05 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::zoomTableView(const Fraction& _rFraction)
|
|
|
|
|
{
|
|
|
|
|
m_pTableView->SetZoom(_rFraction);
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-05 15:17:40 +00:00
|
|
|
|
void OQueryDesignView::SaveUIConfig()
|
|
|
|
|
{
|
2001-02-28 09:18:26 +00:00
|
|
|
|
OQueryController* pCtrl = static_cast<OQueryController*>(getController());
|
2001-02-05 15:17:40 +00:00
|
|
|
|
if (pCtrl)
|
|
|
|
|
{
|
|
|
|
|
pCtrl->SaveTabWinsPosSize( m_pTableView->GetTabWinMap(), m_pScrollWindow->GetHScrollBar()->GetThumbPos(), m_pScrollWindow->GetVScrollBar()->GetThumbPos() );
|
|
|
|
|
// pCtrl->SaveTabFieldsWidth( m_pSelectionBox );
|
|
|
|
|
pCtrl->setVisibleRows( m_pSelectionBox->GetNoneVisibleRows() );
|
|
|
|
|
pCtrl->setSplitPos( m_aSplitter.GetSplitPosPixel() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-10-05 05:49:21 +00:00
|
|
|
|
OSQLParseNode* OQueryDesignView::getPredicateTreeFromEntry(OTableFieldDescRef pEntry,
|
2001-09-27 05:19:05 +00:00
|
|
|
|
const String& _sCriteria,
|
|
|
|
|
::rtl::OUString& _rsErrorMessage,
|
|
|
|
|
Reference<XPropertySet>& _rxColumn)
|
|
|
|
|
{
|
2001-10-05 05:49:21 +00:00
|
|
|
|
OSL_ENSURE(pEntry.isValid(),"Entry is null!");
|
|
|
|
|
if(!pEntry.isValid())
|
2001-09-27 05:19:05 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
Reference< XConnection> xConnection = static_cast<OQueryController*>(getController())->getConnection();
|
|
|
|
|
if(!xConnection.is())
|
|
|
|
|
return NULL;
|
2001-02-05 15:17:40 +00:00
|
|
|
|
|
2001-09-27 05:19:05 +00:00
|
|
|
|
::connectivity::OSQLParser* pParser = static_cast<OQueryController*>(getController())->getParser();
|
|
|
|
|
OQueryTableWindow* pWin = static_cast<OQueryTableWindow*>(pEntry->GetTabWindow());
|
2001-02-05 08:35:57 +00:00
|
|
|
|
|
2001-09-27 05:19:05 +00:00
|
|
|
|
String sTest(_sCriteria);
|
|
|
|
|
// special handling for functions
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pEntry->GetFunctionType() & (FKT_OTHER | FKT_AGGREGATE | FKT_NUMERIC) )
|
2001-09-27 05:19:05 +00:00
|
|
|
|
{
|
|
|
|
|
// we have a function here so we have to distinguish the type of return value
|
|
|
|
|
String sFunction;
|
2002-08-30 10:13:38 +00:00
|
|
|
|
if ( pEntry->isNumericOrAggreateFunction() )
|
2001-09-27 05:19:05 +00:00
|
|
|
|
sFunction = pEntry->GetFunction();
|
|
|
|
|
else
|
|
|
|
|
sFunction = pEntry->GetField();
|
|
|
|
|
|
|
|
|
|
if(sFunction.GetTokenCount('(') > 1)
|
|
|
|
|
sFunction = sFunction.GetToken(0,'('); // this should be the name of the function
|
2002-08-30 10:13:38 +00:00
|
|
|
|
|
2001-09-27 05:19:05 +00:00
|
|
|
|
sal_Int32 nType = ::connectivity::OSQLParser::getFunctionReturnType(sFunction,&pParser->getContext());
|
2004-03-15 11:43:43 +00:00
|
|
|
|
if ( nType == DataType::OTHER || (!sFunction.Len() && pEntry->isNumericOrAggreateFunction()) )
|
|
|
|
|
{
|
|
|
|
|
// first try the international version
|
|
|
|
|
::rtl::OUString sSql;
|
|
|
|
|
sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT * "));
|
|
|
|
|
sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM x WHERE "));
|
|
|
|
|
sSql += pEntry->GetField();
|
|
|
|
|
sSql += _sCriteria;
|
|
|
|
|
OSQLParseNode* pParseNode = pParser->parseTree( _rsErrorMessage,sSql,sal_True);
|
2002-08-30 10:13:38 +00:00
|
|
|
|
nType = DataType::DOUBLE;
|
2004-03-15 11:43:43 +00:00
|
|
|
|
if ( pParseNode )
|
|
|
|
|
{
|
|
|
|
|
OSQLParseNode* pColumnRef = pParseNode->getByRule(OSQLParseNode::column_ref);
|
|
|
|
|
if ( pColumnRef )
|
|
|
|
|
{
|
|
|
|
|
OTableFieldDescRef aField = new OTableFieldDesc();
|
|
|
|
|
if ( eOk == FillDragInfo(this,pColumnRef,aField) )
|
|
|
|
|
{
|
|
|
|
|
nType = aField->GetDataType();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete pParseNode;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-09-27 05:19:05 +00:00
|
|
|
|
|
2003-12-01 09:38:33 +00:00
|
|
|
|
Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
|
2001-09-27 05:19:05 +00:00
|
|
|
|
parse::OParseColumn* pColumn = new parse::OParseColumn( pEntry->GetField(),
|
|
|
|
|
::rtl::OUString(),
|
|
|
|
|
::rtl::OUString(),
|
|
|
|
|
ColumnValue::NULLABLE_UNKNOWN,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
nType,
|
|
|
|
|
sal_False,
|
|
|
|
|
sal_False,
|
2003-12-01 09:38:33 +00:00
|
|
|
|
xMeta.is() && xMeta->storesMixedCaseQuotedIdentifiers());
|
2001-09-27 05:19:05 +00:00
|
|
|
|
_rxColumn = pColumn;
|
|
|
|
|
pColumn->setFunction(sal_True);
|
|
|
|
|
pColumn->setRealName(pEntry->GetField());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (pWin)
|
|
|
|
|
{
|
|
|
|
|
Reference<XNameAccess> xColumns = pWin->GetOriginalColumns();
|
|
|
|
|
if (xColumns.is() && xColumns->hasByName(pEntry->GetField()))
|
|
|
|
|
xColumns->getByName(pEntry->GetField()) >>= _rxColumn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OSQLParseNode* pParseNode = pParser->predicateTree( _rsErrorMessage,
|
|
|
|
|
sTest,
|
|
|
|
|
static_cast<OQueryController*>(getController())->getNumberFormatter(),
|
|
|
|
|
_rxColumn);
|
|
|
|
|
return pParseNode;
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-10-22 08:57:52 +00:00
|
|
|
|
void OQueryDesignView::GetFocus()
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
OQueryView::GetFocus();
|
|
|
|
|
if ( m_pSelectionBox && !m_pSelectionBox->HasChildPathFocus() )
|
2001-10-22 08:57:52 +00:00
|
|
|
|
{
|
2002-05-22 10:31:21 +00:00
|
|
|
|
// first we have to deactivate the current cell to refill when nescessary
|
|
|
|
|
m_pSelectionBox->DeactivateCell();
|
2001-10-22 08:57:52 +00:00
|
|
|
|
m_pSelectionBox->ActivateCell(m_pSelectionBox->GetCurRow(), m_pSelectionBox->GetCurColumnId());
|
2002-05-06 08:45:36 +00:00
|
|
|
|
m_pSelectionBox->GrabFocus();
|
2001-10-22 08:57:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-10-23 11:30:27 +00:00
|
|
|
|
void OQueryDesignView::reset()
|
|
|
|
|
{
|
|
|
|
|
m_pTableView->ClearAll();
|
|
|
|
|
m_pTableView->ReSync();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
void OQueryDesignView::setNoneVisbleRow(sal_Int32 _nRows)
|
|
|
|
|
{
|
|
|
|
|
m_pSelectionBox->SetNoneVisbleRow(_nRows);
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2002-05-06 08:45:36 +00:00
|
|
|
|
sal_Bool OQueryDesignView::InitFromParseNode()
|
2002-02-06 07:08:30 +00:00
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
SqlParseError eErrorCode;
|
|
|
|
|
m_pController->clearError();
|
|
|
|
|
if ( (eErrorCode = InitFromParseNodeImpl(this,m_pSelectionBox)) != eOk )
|
|
|
|
|
{
|
|
|
|
|
if ( !m_pController->hasError() ) // fill generell error string
|
|
|
|
|
showParseError(m_pController,eErrorCode);
|
|
|
|
|
|
|
|
|
|
SQLException aError;
|
|
|
|
|
m_pController->getError(aError);
|
|
|
|
|
m_pController->showError(aError);
|
|
|
|
|
}
|
|
|
|
|
return eErrorCode == eOk;
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
sal_Bool OQueryDesignView::HasTable() const
|
|
|
|
|
{
|
2002-05-06 08:45:36 +00:00
|
|
|
|
return !m_pTableView->GetTabWinMap()->empty();
|
2002-02-06 07:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|