Files
libreoffice/include/connectivity/sqlnode.hxx

464 lines
20 KiB
C++
Raw Normal View History

2010-10-27 13:11:31 +01:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-12 22:04:38 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_CONNECTIVITY_SQLNODE_HXX
#define INCLUDED_CONNECTIVITY_SQLNODE_HXX
2000-09-18 15:18:56 +00:00
#include <connectivity/dbtoolsdllapi.hxx>
#include <connectivity/dbmetadata.hxx>
#include <com/sun/star/sdbc/SQLException.hpp>
#include <com/sun/star/uno/Reference.hxx>
2000-09-18 15:18:56 +00:00
#include <com/sun/star/util/XNumberFormatTypes.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <functional>
#include <memory>
#include <set>
#include <vector>
CWS-TOOLING: integrate CWS dbaperf2 2009-06-22 11:04:36 +0200 msc r273202 : #100000# fix to run this test 2009-06-22 09:41:04 +0200 msc r273200 : #100000# correct case 2009-06-22 09:02:42 +0200 msc r273199 : new SRB 2009-06-22 08:53:26 +0200 msc r273198 : #100000 2009-06-15 12:36:32 +0200 oj r272976 : test 2009-06-12 14:23:23 +0200 msc r272918 : #101587# unused feature was removed 2009-06-12 06:45:17 +0200 oj r272903 : use GUI instead of OS 2009-06-11 09:12:30 +0200 oj r272845 : remove unused dep 2009-06-11 09:11:09 +0200 oj r272844 : ColumnAliasInOrderBy not supported 2009-06-11 08:27:00 +0200 oj r272843 : CWS-TOOLING: rebase CWS dbaperf2 to trunk@272827 (milestone: DEV300:m50) 2009-06-10 15:30:17 +0200 msc r272822 : #100000 2009-06-10 15:27:40 +0200 msc r272820 : #102515# new function for the database type list 2009-06-10 15:26:09 +0200 msc r272818 : move file to dbaccess/tools/dbcreatetools.inc 2009-06-10 15:20:10 +0200 msc r272816 : #102515# new function for the database type list 2009-06-10 12:34:46 +0200 oj r272803 : #i101587# check extension 2009-06-10 11:53:45 +0200 oj r272800 : remove unused code 2009-06-09 09:57:25 +0200 oj r272752 : #i101587# EscapeDateTime moved into features section 2009-06-09 09:56:26 +0200 oj r272751 : enable finish 2009-06-08 11:50:37 +0200 oj r272726 : #i102588# move convert tzo saveDataSource 2009-06-05 11:54:20 +0200 jsk r272676 : #i102515# - NEW: Functions to retrieve Database names from API 2009-06-05 10:52:22 +0200 jsk r272671 : NEW: Functions to retrieve Database names from API 2009-06-05 09:36:54 +0200 oj r272666 : handle win and unx differently 2009-06-05 09:36:28 +0200 oj r272665 : handle win and unx differently 2009-06-04 13:41:56 +0200 oj r272625 : #i101268# make use of stringbuffer instead of oustring 2009-06-04 10:18:14 +0200 oj r272612 : add SAL_DLLPUBLIC_EXPORT 2009-05-28 10:56:33 +0200 oj r272381 : #i101587# create langpacks 2009-05-28 10:41:59 +0200 oj r272380 : #i101587# create langpacks 2009-05-28 10:29:30 +0200 oj r272379 : #i101587# create langpacks 2009-05-07 10:11:46 +0200 oj r271635 : fix compile warnings 2009-05-07 07:01:31 +0200 oj r271619 : change type from int32 to PathID 2009-05-07 06:53:19 +0200 oj r271618 : add all 2009-05-06 14:57:02 +0200 oj r271595 : add missing lib 2009-05-06 14:56:54 +0200 oj r271594 : no used anymore 2009-05-06 14:56:08 +0200 oj r271593 : no used anymore 2009-05-06 14:54:25 +0200 oj r271592 : no used anymore 2009-05-06 14:45:59 +0200 oj r271591 : add missing lib 2009-05-06 14:41:54 +0200 oj r271590 : change wnt 2009-05-06 14:22:21 +0200 oj r271589 : #i101587# use config for the drivers 2009-05-06 14:21:39 +0200 oj r271588 : #i101587# add new set for metadata and config data for driver 2009-05-06 14:19:36 +0200 oj r271587 : #i101587# handle metadata and props of driver 2009-05-06 10:11:11 +0200 oj r271570 : #i101587# correct wrong use of reference 2009-05-06 09:24:33 +0200 oj r271567 : #i101587# add new set for metadata 2009-05-06 08:52:06 +0200 oj r271563 : #i101587# add driver configuration 2009-05-06 08:51:04 +0200 oj r271562 : #i101587# add driver configuration 2009-05-04 10:24:41 +0200 oj r271442 : CWS-TOOLING: rebase CWS dbaperf2 to trunk@271427 (milestone: DEV300:m47) 2009-04-28 07:06:22 +0200 oj r271303 : compile error 2009-04-27 14:12:48 +0200 oj r271270 : #i101268# make use of stringbuffer instead of oustring 2009-04-27 14:12:27 +0200 oj r271269 : #i101268# make use of stringbuffer instead of oustring 2009-04-27 09:30:10 +0200 oj r271255 : use string buffer when possible 2009-04-24 11:56:01 +0200 oj r271207 : #i101268# remove end() call from loop 2009-04-23 14:24:03 +0200 oj r271171 : add dep 2009-04-23 13:25:25 +0200 oj r271164 : #i101268# add config entries for database drivers 2009-04-23 13:07:13 +0200 oj r271161 : #i101268# add config entries for database drivers 2009-04-23 13:06:33 +0200 oj r271160 : #i101268# add parent url pattern entry for driver node 2009-04-23 13:05:39 +0200 oj r271159 : #i101268# add config entry for driver node 2009-04-23 13:04:09 +0200 oj r271157 : #i101268# add config entry for driver node 2009-04-23 06:41:32 +0200 oj r271142 : #i101268# add new configuration file Drivers 2009-04-22 13:49:19 +0200 oj r271103 : convert EOL 2009-04-22 13:29:17 +0200 oj r271101 : #i101268# use of driver configuration entries for features and properties 2009-04-22 13:28:08 +0200 oj r271100 : #i101268# use of driver configuration entries for features and properties 2009-04-22 13:15:26 +0200 oj r271098 : #i101268# add new configuration file Drivers 2009-04-22 13:14:43 +0200 oj r271097 : #i101268# use of driver configuration entries for features and properties
2009-07-03 12:24:35 +00:00
#include <rtl/ustrbuf.hxx>
#include <osl/diagnose.h>
2000-09-18 15:18:56 +00:00
namespace com
{
namespace sun
{
namespace star
{
namespace beans
{
class XPropertySet;
}
namespace util
{
class XNumberFormatter;
}
namespace container
{
class XNameAccess;
}
2000-09-18 15:18:56 +00:00
}
}
}
#define ORDER_BY_CHILD_POS 5
#define TABLE_EXPRESSION_CHILD_COUNT 9
CWS-TOOLING: integrate CWS evoab2def 2009-05-28 16:00:19 +0200 fs r272412 : don't use createFalse - Evo 2.22 simply hangs when ask for all contacts without a first name. Instead, in the WHERE 0=1 case, simply create an empty result set 2009-05-22 14:25:51 +0200 fs r272193 : #i10000# 2009-05-22 14:25:37 +0200 fs r272192 : oops, ENABLE_EVOAB2 for some platforms only, not generically 2009-05-22 14:19:00 +0200 fs r272191 : #i10000# 2009-05-22 12:42:38 +0200 fs r272183 : when sorting, properly use a syslocale collator, instead of comparing the numerical values of the string's UTF-16 code points 2009-05-20 15:09:00 +0200 fs r272131 : clear/getWarnings: also allowed without cache 2009-05-20 14:11:19 +0200 fs r272128 : removed debug traces 2009-05-20 14:03:31 +0200 fs r272126 : #i55701# +STR_SORT_BY_COL_ONLY 2009-05-20 14:02:29 +0200 fs r272125 : implement sorting 2009-05-20 10:10:19 +0200 fs r272107 : #i10000# 2009-05-19 16:02:17 +0200 fs r272089 : #i10000# 2009-05-19 16:02:02 +0200 fs r272088 : #i55701# strings for new error condition DATA_CANNOT_SELECT_UNFILTERED 2009-05-19 16:01:31 +0200 fs r272087 : #i55701# use DATA_CANNOT_SELECT_UNFILTERED as standardized error code 2009-05-19 15:59:59 +0200 fs r272086 : #i55701# +DATA_CANNOT_SELECT_UNFILTERED 2009-05-19 15:46:12 +0200 fs r272084 : #i55701# recognize the DATA_CANNOT_SELECT_UNFILTERED error condition, and allow filtering in this case, even when the result set is empty 2009-05-19 09:06:50 +0200 fs r272059 : merging changes from CWS dba32b, to prevent future conflicts with upcoming local changes 2009-05-18 21:48:58 +0200 fs r272054 : accessing a non-local unfiltered address book now returns an empty result set, and reports a warning, instead of ungracefully failing 2009-05-18 21:48:42 +0200 fs r272053 : accessing a non-local unfiltered address book now returns an empty result set, and reports a warning, instead of ungracefully failing 2009-05-18 21:47:41 +0200 fs r272052 : +setExternalWarnings 2009-05-18 21:47:12 +0200 fs r272051 : #i55701# when re/loading the form, display any possible warnings 2009-05-18 21:43:26 +0200 fs r272050 : #i55701# implement XWarningsSupplier, exposing the warnings of our result set 2009-05-18 21:42:51 +0200 fs r272049 : #i55701# implement XWarningsSupplier, exposing the warnings of our aggregate RowSet 2009-05-18 17:53:59 +0200 fs r272041 : #i55701# moved the (I)WarningsContainer from dbaccess to connectivity, to be able to use it in the latter module, too 2009-05-18 17:24:10 +0200 fs r272040 : #i55701# properly enable the various Evolution types 2009-05-18 14:52:19 +0200 fs r272024 : #i55701# properly enable the Evolution types 2009-05-18 13:57:10 +0200 fs r272018 : fixed/extended whereAnalysis (column searching still not enabled, as neither LIKE nor = seem to work with my (somewhat older) Evolution version) 2009-05-18 13:56:08 +0200 fs r272017 : extended showParseTree 2009-05-18 13:55:25 +0200 fs r272016 : extended showParseTree 2009-05-18 11:40:16 +0200 fs r272008 : #i55701# 2009-05-18 11:39:02 +0200 fs r272006 : let the PreparedStatement return proper meta data, too 2009-05-18 10:05:37 +0200 fs r271999 : moved the XStatement interface to from OCommonStatement to OStatement - the former class is also the base for other classes which should not have this interface 2009-05-15 21:53:22 +0200 fs r271973 : collectColumnInformation: report invalid meta data as assertion 2009-05-15 21:51:40 +0200 fs r271972 : showParseTree should be const 2009-05-15 21:51:26 +0200 fs r271971 : showParseTree should be const 2009-05-15 21:51:03 +0200 fs r271970 : properly recognize the 'WHERE 0 = 1' clause, this way having proper statement meta data, this way saving much much calls from the DBA framework 2009-05-15 20:29:03 +0200 fs r271969 : cleaned up the mess with the statement classes 2009-05-15 15:51:11 +0200 fs r271944 : let the result set properly init its meta data 2009-05-15 15:29:54 +0200 fs r271939 : proper property implementations for the resultset class 2009-05-15 15:01:31 +0200 fs r271936 : proper property implementations for the statement class 2009-05-08 14:46:33 +0200 fs r271717 : component_foo must be PUBLIC 2009-05-06 09:20:05 +0200 fs r271565 : #i10000# (warnings on unxlngi6) 2009-05-06 09:01:30 +0200 fs r271564 : #i101493# 2009-05-05 23:08:12 +0200 fs r271560 : #i55701# merging the changes from the ancient (CVS-based) CWS evoab2default into this CWS here
2009-06-05 12:31:05 +00:00
2000-09-18 15:18:56 +00:00
namespace connectivity
{
class OSQLParser;
2000-09-18 15:18:56 +00:00
class OSQLParseNode;
2002-09-27 10:01:52 +00:00
class IParseContext;
2000-09-18 15:18:56 +00:00
enum class SQLNodeType { Rule, ListRule, CommaListRule,
Keyword, Name,
String, IntNum, ApproxNum,
Equal, Less, Great, LessEq, GreatEq, NotEqual,
Punctuation, AccessDate, Concat};
2000-09-18 15:18:56 +00:00
typedef ::std::set< OUString > QueryNameSet;
//= SQLParseNodeParameter
CWS-TOOLING: integrate CWS sb102 2008-12-11 16:18:12 +0100 sb r265332 : #i95065# cleanup, to make Windows linking work 2008-12-11 16:16:03 +0100 sb r265331 : #i95065# missing SAL_DLLPUBLIC_EXPORT 2008-12-09 17:40:28 +0100 sb r265122 : #i94469# move CJK specific configuration data to brand layer 2008-12-09 16:09:08 +0100 sb r265112 : #i96959# use PTHREAD_MUTEX_RECURSIVE on all platforms 2008-12-09 15:54:31 +0100 sb r265110 : #i95065# do not derive apphelper::LifeTimeGuard from osl::ResettableMutexGuard to avoid problems with VISIBILITY_HIDDEN=TRUE on MSC 2008-12-09 15:40:51 +0100 sb r265104 : #i95065# add VISIBILITY_HIDDEN=TRUE to connectivity/source/drivers/mozab 2008-12-09 15:36:21 +0100 sb r265102 : #i95501# updated SDK_HOME 2008-12-09 15:31:46 +0100 sb r265099 : typo (temppath vs. tmppath) 2008-12-08 11:48:08 +0100 sb r264979 : #i95065# removed spurious ExplicitCategoriesProvider.obj (ExplicitCategoriesProvider.cxx is not in this directory) 2008-12-07 19:41:07 +0100 sb r264960 : #i96994# erroneously doubled backslash caused visibility feature to be disabled for all GCC versions on Mac OS X 2008-12-06 23:54:49 +0100 sb r264948 : changes from trunk that CWS-TOOLING's rebase to DEV300:m37 (r264891) had missed, as files had been moved around on this CWS 2008-12-05 20:29:23 +0100 sb r264919 : #i85508# versions of flex apparently differ in whether input() resp. yyinput() returns zero or EOF upon end of file 2008-12-05 15:37:23 +0100 sb r264908 : #i95315# removed obsolete jut 2008-12-05 15:34:59 +0100 sb r264907 : #i95531# removed empty obsolete directories 2008-12-05 10:09:23 +0100 sb r264891 : CWS-TOOLING: rebase CWS sb102 to trunk@264807 (milestone: DEV300:m37) 2008-12-04 14:50:20 +0100 sb r264845 : #i95065# introduced VISIBILITY_HIDDEN makefile flag to reduce duplications; made additional libraries use VISIBILITY_HIDDEN=TRUE to avoid warnings with recent GCC 4 versions (had to split certain code directories to make changes that would otherwise erroneously affect multiple libraries built in the same makefile); changed connectivity::ORefVector to no longer derive from std::vector, as that caused problems with the MSC implementation of VISIBILITY_HIDDEN=TRUE; replaced uses of JNIEXPORT with SAL_DLLPUBLIC_EXPORT, as the former does not expand to visibility attributes on some platforms where the latter does 2008-12-03 11:29:38 +0100 sb r264759 : #i94583# remove unnecessary (and wrong) assertion check for rtl_getAppCommandArg return value (which is guaranteed to return osl_Process_E_None or not return at all) 2008-12-02 17:18:31 +0100 sb r264724 : #i96809# silenced GCC 4.3.2 warning 2008-12-02 13:29:34 +0100 sb r264695 : #i96797# make get_tmp_dir fail less often 2008-11-28 17:19:24 +0100 sb r264566 : #i95691# inadvertently missing from -c 264564 2008-11-28 17:07:50 +0100 sb r264564 : #i95691# only structs of exactly 1, 2, 4, or 8 bytes are returned through registers 2008-11-25 13:28:08 +0100 sb r264291 : #i96427# support for SAL_EXCEPTION_DLLPUBLIC_EXPORT (patch by np) 2008-11-21 14:45:22 +0100 sb r264140 : #i95428# added SAL_EXCEPTION_DLLPUBLIC_EXPORT and SAL_EXCEPTION_DLLPRIVATE 2008-11-19 13:19:37 +0100 sb r263984 : #i95525# removed erroneous application/octet-stream svn:mime-type properties
2008-12-30 13:32:01 +00:00
struct OOO_DLLPUBLIC_DBTOOLS SQLParseNodeParameter
{
const css::lang::Locale& rLocale;
::dbtools::DatabaseMetaData aMetaData;
OSQLParser* pParser;
std::shared_ptr< QueryNameSet > pSubQueryHistory;
css::uno::Reference< css::util::XNumberFormatter > xFormatter;
css::uno::Reference< css::beans::XPropertySet > xField;
OUString sPredicateTableAlias;
css::uno::Reference< css::container::XNameAccess > xQueries; // see bParseToSDBCLevel
const IParseContext& m_rContext;
sal_Char cDecSep;
bool bQuote : 1; /// should we quote identifiers?
bool bInternational : 1; /// should we internationalize keywords and placeholders?
bool bPredicate : 1; /// are we going to parse a mere predicate?
bool bParseToSDBCLevel : 1; /// should we create an SDBC-level statement (e.g. with substituted sub queries)?
SQLParseNodeParameter(
const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
const css::uno::Reference< css::util::XNumberFormatter >& _xFormatter,
const css::uno::Reference< css::beans::XPropertySet >& _xField,
const OUString &_sPredicateTableAlias,
const css::lang::Locale& _rLocale,
const IParseContext* _pContext,
bool _bIntl,
bool _bQuote,
sal_Char _cDecSep,
bool _bPredicate,
bool _bParseToSDBC
);
~SQLParseNodeParameter();
};
2000-09-18 15:18:56 +00:00
//= OSQLParseNode
CWS-TOOLING: integrate CWS sb102 2008-12-11 16:18:12 +0100 sb r265332 : #i95065# cleanup, to make Windows linking work 2008-12-11 16:16:03 +0100 sb r265331 : #i95065# missing SAL_DLLPUBLIC_EXPORT 2008-12-09 17:40:28 +0100 sb r265122 : #i94469# move CJK specific configuration data to brand layer 2008-12-09 16:09:08 +0100 sb r265112 : #i96959# use PTHREAD_MUTEX_RECURSIVE on all platforms 2008-12-09 15:54:31 +0100 sb r265110 : #i95065# do not derive apphelper::LifeTimeGuard from osl::ResettableMutexGuard to avoid problems with VISIBILITY_HIDDEN=TRUE on MSC 2008-12-09 15:40:51 +0100 sb r265104 : #i95065# add VISIBILITY_HIDDEN=TRUE to connectivity/source/drivers/mozab 2008-12-09 15:36:21 +0100 sb r265102 : #i95501# updated SDK_HOME 2008-12-09 15:31:46 +0100 sb r265099 : typo (temppath vs. tmppath) 2008-12-08 11:48:08 +0100 sb r264979 : #i95065# removed spurious ExplicitCategoriesProvider.obj (ExplicitCategoriesProvider.cxx is not in this directory) 2008-12-07 19:41:07 +0100 sb r264960 : #i96994# erroneously doubled backslash caused visibility feature to be disabled for all GCC versions on Mac OS X 2008-12-06 23:54:49 +0100 sb r264948 : changes from trunk that CWS-TOOLING's rebase to DEV300:m37 (r264891) had missed, as files had been moved around on this CWS 2008-12-05 20:29:23 +0100 sb r264919 : #i85508# versions of flex apparently differ in whether input() resp. yyinput() returns zero or EOF upon end of file 2008-12-05 15:37:23 +0100 sb r264908 : #i95315# removed obsolete jut 2008-12-05 15:34:59 +0100 sb r264907 : #i95531# removed empty obsolete directories 2008-12-05 10:09:23 +0100 sb r264891 : CWS-TOOLING: rebase CWS sb102 to trunk@264807 (milestone: DEV300:m37) 2008-12-04 14:50:20 +0100 sb r264845 : #i95065# introduced VISIBILITY_HIDDEN makefile flag to reduce duplications; made additional libraries use VISIBILITY_HIDDEN=TRUE to avoid warnings with recent GCC 4 versions (had to split certain code directories to make changes that would otherwise erroneously affect multiple libraries built in the same makefile); changed connectivity::ORefVector to no longer derive from std::vector, as that caused problems with the MSC implementation of VISIBILITY_HIDDEN=TRUE; replaced uses of JNIEXPORT with SAL_DLLPUBLIC_EXPORT, as the former does not expand to visibility attributes on some platforms where the latter does 2008-12-03 11:29:38 +0100 sb r264759 : #i94583# remove unnecessary (and wrong) assertion check for rtl_getAppCommandArg return value (which is guaranteed to return osl_Process_E_None or not return at all) 2008-12-02 17:18:31 +0100 sb r264724 : #i96809# silenced GCC 4.3.2 warning 2008-12-02 13:29:34 +0100 sb r264695 : #i96797# make get_tmp_dir fail less often 2008-11-28 17:19:24 +0100 sb r264566 : #i95691# inadvertently missing from -c 264564 2008-11-28 17:07:50 +0100 sb r264564 : #i95691# only structs of exactly 1, 2, 4, or 8 bytes are returned through registers 2008-11-25 13:28:08 +0100 sb r264291 : #i96427# support for SAL_EXCEPTION_DLLPUBLIC_EXPORT (patch by np) 2008-11-21 14:45:22 +0100 sb r264140 : #i95428# added SAL_EXCEPTION_DLLPUBLIC_EXPORT and SAL_EXCEPTION_DLLPRIVATE 2008-11-19 13:19:37 +0100 sb r263984 : #i95525# removed erroneous application/octet-stream svn:mime-type properties
2008-12-30 13:32:01 +00:00
class OOO_DLLPUBLIC_DBTOOLS OSQLParseNode
2000-09-18 15:18:56 +00:00
{
friend class OSQLParser;
std::vector< std::unique_ptr<OSQLParseNode> >
m_aChildren;
OSQLParseNode* m_pParent; // pParent for reverse linkage in the tree
OUString m_aNodeValue; // token name, or empty in case of rules,
// or OUString in case of
// OUString, INT, etc.
SQLNodeType m_eNodeType; // see above
sal_uInt32 m_nNodeID; // Rule ID (if IsRule())
// or Token ID (if !IsRule())
// Rule IDs and Token IDs can't
// be distinguished by their values,
2011-01-31 11:12:04 +00:00
// IsRule has to be used for that!
2000-09-18 15:18:56 +00:00
public:
enum Rule
{
UNKNOWN_RULE = 0, // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID)
// we make sure it is 0 so that it is the default-constructor value of this enum
// and std::map<foo,Rule>::operator[](bar) default-inserts UNKNOWN_RULE rather than select_statement (!)
select_statement,
2000-09-18 15:18:56 +00:00
table_exp,
table_ref_commalist,
table_ref,
2001-01-09 12:11:07 +00:00
catalog_name,
schema_name,
2000-09-18 15:18:56 +00:00
table_name,
opt_column_commalist,
column_commalist,
column_ref_commalist,
column_ref,
opt_order_by_clause,
ordering_spec_commalist,
ordering_spec,
opt_asc_desc,
where_clause,
opt_where_clause,
search_condition,
comparison,
2000-09-18 15:18:56 +00:00
comparison_predicate,
between_predicate,
like_predicate,
opt_escape,
test_for_null,
scalar_exp_commalist,
scalar_exp,
parameter_ref,
parameter,
general_set_fct,
range_variable,
column,
delete_statement_positioned,
delete_statement_searched,
update_statement_positioned,
update_statement_searched,
assignment_commalist,
assignment,
values_or_query_spec,
insert_statement,
insert_atom_commalist,
insert_atom,
from_clause,
qualified_join,
cross_union,
select_sublist,
derived_column,
column_val,
set_fct_spec,
boolean_term,
boolean_primary,
num_value_exp,
join_type,
position_exp,
extract_exp,
length_exp,
char_value_fct,
odbc_call_spec,
in_predicate,
existence_test,
unique_test,
all_or_any_predicate,
named_columns_join,
join_condition,
joined_table,
2000-09-18 15:18:56 +00:00
boolean_factor,
sql_not,
2000-09-18 15:18:56 +00:00
manipulative_statement,
subquery,
value_exp_commalist,
odbc_fct_spec,
union_statement,
outer_join_type,
char_value_exp,
term,
value_exp_primary,
value_exp,
2002-07-15 06:14:04 +00:00
selection,
fold,
char_substring_fct,
factor,
base_table_def,
base_table_element_commalist,
data_type,
column_def,
table_node,
as_clause,
opt_as,
op_column_commalist,
table_primary_as_range_column,
datetime_primary,
concatenation,
char_factor,
bit_value_fct,
comparison_predicate_part_2,
parenthesized_boolean_value_expression,
character_string_type,
other_like_predicate_part_2,
between_predicate_part_2,
null_predicate_part_2,
2010-12-10 12:42:03 +01:00
cast_spec,
window_function,
rule_count // last value
2000-09-18 15:18:56 +00:00
};
// must be ascii encoding for the value
OSQLParseNode(const sal_Char* _pValueStr,
SQLNodeType _eNodeType,
sal_uInt32 _nNodeID = 0);
OSQLParseNode(const OString& _rValue,
2000-09-18 15:18:56 +00:00
SQLNodeType eNewNodeType,
sal_uInt32 nNewNodeID=0);
OSQLParseNode(const OUString& _rValue,
2000-09-18 15:18:56 +00:00
SQLNodeType _eNodeType,
sal_uInt32 _nNodeID = 0);
2011-01-31 11:12:04 +00:00
// copies the respective ParseNode
2000-09-18 15:18:56 +00:00
OSQLParseNode(const OSQLParseNode& rParseNode);
OSQLParseNode& operator=(const OSQLParseNode& rParseNode);
bool operator==(OSQLParseNode const & rParseNode) const;
2000-09-18 15:18:56 +00:00
// destructor destructs the tree recursively
2000-09-18 15:18:56 +00:00
virtual ~OSQLParseNode();
OSQLParseNode* getParent() const {return m_pParent;};
void setParent(OSQLParseNode* pParseNode) {m_pParent = pParseNode;};
size_t count() const {return m_aChildren.size();};
2000-09-18 15:18:56 +00:00
inline OSQLParseNode* getChild(sal_uInt32 nPos) const;
void append(OSQLParseNode* pNewSubTree);
void insert(sal_uInt32 nPos, OSQLParseNode* pNewSubTree);
OSQLParseNode* replace(OSQLParseNode* pOldSubTree, OSQLParseNode* pNewSubTree);
OSQLParseNode* removeAt(sal_uInt32 nPos);
void replaceNodeValue(const OUString& rTableAlias,const OUString& rColumnName);
2000-09-18 15:18:56 +00:00
/** parses the node to a string which can be passed to a driver's connection for execution
Any particles of the parse tree which represent application-level features - such
2011-10-29 07:54:41 +02:00
as queries appearing in the FROM part - are substituted, so that the resulting statement can
be executed at an SDBC-level connection.
@param _out_rString
is an output parameter taking the resulting SQL statement
@param _rxConnection
the connection relative to which to parse. This must be an SDB-level connection (e.g.
support the XQueriesSupplier interface) for the method to be able to do all necessary
substitutions.
@param _rParser
the SQLParser used to create the node. This is needed in case we need to parse
sub queries which are present in the SQL statement - those sub queries need to be parsed,
too, to check whether they contain nested sub queries.
@param _pErrorHolder
2010-12-04 13:16:21 +09:00
takes the error which occurred while generating the statement, if any. Might be <NULL/>,
in this case the error is not reported back, and can only be recognized by examing the
return value.
@return
<TRUE/> if and only if the parsing was successful.<br/>
Currently, there's only one condition how this method can fail: If it contains a nested
query which causes a cycle. E.g., consider a statement <code>SELECT * from "foo"</code>,
2011-10-29 07:55:06 +02:00
where <code>foo</code> is a query defined as <code>SELECT * FROM "bar"</code>, where
<code>bar</code> is defined as <code>SELECT * FROM "foo"</code>. This statement obviously
cannot be parsed to an executable statement.
If this method returns <FALSE/>, you're encouraged to check and handle the error in
<arg>_pErrorHolder</arg>.
*/
bool parseNodeToExecutableStatement( OUString& _out_rString,
const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
OSQLParser& _rParser,
css::sdbc::SQLException* _pErrorHolder ) const;
void parseNodeToStr(OUString& rString,
const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
const IParseContext* pContext = nullptr,
bool _bIntl = false,
bool _bQuote= true) const;
2000-09-18 15:18:56 +00:00
// quoted and internationalised
void parseNodeToPredicateStr(OUString& rString,
const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
const css::uno::Reference< css::util::XNumberFormatter > & xFormatter,
const css::lang::Locale& rIntl,
2000-10-19 10:47:14 +00:00
sal_Char _cDec,
const IParseContext* pContext = nullptr ) const;
2000-09-18 15:18:56 +00:00
void parseNodeToPredicateStr(OUString& rString,
const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
const css::uno::Reference< css::util::XNumberFormatter > & xFormatter,
const css::uno::Reference< css::beans::XPropertySet > & _xField,
const OUString &_sTableAlias,
const css::lang::Locale& rIntl,
2000-10-19 10:47:14 +00:00
sal_Char _cDec,
const IParseContext* pContext = nullptr ) const;
2000-09-18 15:18:56 +00:00
OSQLParseNode* getByRule(OSQLParseNode::Rule eRule) const;
2011-11-18 08:56:49 +00:00
#if OSL_DEBUG_LEVEL > 1
// shows the ParseTree with tabs and linefeeds
void showParseTree( OUString& rString ) const;
void showParseTree( OUStringBuffer& _inout_rBuf, sal_uInt32 nLevel ) const;
#endif
2000-09-18 15:18:56 +00:00
SQLNodeType getNodeType() const {return m_eNodeType;};
// RuleId returns the RuleID of the node's rule (only if IsRule())
2000-09-18 15:18:56 +00:00
sal_uInt32 getRuleID() const {return m_nNodeID;}
/** returns the ID of the rule represented by the node
If the node does not represent a rule, UNKNOWN_RULE is returned
*/
Rule getKnownRuleID() const;
// returns the TokenId of the node's token (only if !isRule())
2000-09-18 15:18:56 +00:00
sal_uInt32 getTokenID() const {return m_nNodeID;}
2011-01-31 11:12:04 +00:00
// IsRule tests whether a node is a rule (NonTerminal)
// ATTENTION: rules can be leaves, for example empty lists
bool isRule() const
{ return (m_eNodeType == SQLNodeType::Rule) || (m_eNodeType == SQLNodeType::ListRule)
|| (m_eNodeType == SQLNodeType::CommaListRule);}
2000-09-18 15:18:56 +00:00
// IsToken tests whether a Node is a Token (Terminal but not a rule)
bool isToken() const {return !isRule();}
2000-09-18 15:18:56 +00:00
const OUString& getTokenValue() const {return m_aNodeValue;}
2000-09-18 15:18:56 +00:00
bool isLeaf() const {return m_aChildren.empty();}
2000-09-18 15:18:56 +00:00
// negate only a searchcondition, any other rule could cause a gpf
static void negateSearchCondition(OSQLParseNode*& pSearchCondition, bool bNegate=false);
2000-09-18 15:18:56 +00:00
// normalize a logic form
// e.q. (a or b) and (c or d) <=> a and c or a and d or b and c or b and d
static void disjunctiveNormalForm(OSQLParseNode*& pSearchCondition);
// Simplifies logic expressions
// a and a = a
// a or a = a
// a and ( a + b) = a
// a or a and b = a
2000-09-18 15:18:56 +00:00
static void absorptions(OSQLParseNode*& pSearchCondition);
// erase unnecessary braces
2000-09-18 15:18:56 +00:00
static void eraseBraces(OSQLParseNode*& pSearchCondition);
// makes the logic formula a little smaller
2000-09-18 15:18:56 +00:00
static void compress(OSQLParseNode*& pSearchCondition);
2001-01-09 12:11:07 +00:00
// return the catalog, schema and tablename form this node
// _pTableNode must be a rule of that above or a SQL_TOKEN_NAME
static bool getTableComponents(const OSQLParseNode* _pTableNode,
css::uno::Any &_rCatalog,
OUString &_rSchema,
OUString &_rTable,
const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _xMetaData);
2000-09-18 15:18:56 +00:00
// substitute all occurrences of :var or [name] into the dynamic parameter ?
// _pNode will be modified if parameters exists
static void substituteParameterNames(OSQLParseNode const * _pNode);
/** return a table range when it exists.
*/
static OUString getTableRange(const OSQLParseNode* _pTableRef);
2000-09-18 15:18:56 +00:00
protected:
// ParseNodeToStr concatenates all Tokens (leaves) of the ParseNodes.
void parseNodeToStr(OUString& rString,
const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
const css::uno::Reference< css::util::XNumberFormatter > & xFormatter,
const css::uno::Reference< css::beans::XPropertySet > & _xField,
const OUString &_sPredicateTableAlias,
const css::lang::Locale& rIntl,
2002-09-27 10:01:52 +00:00
const IParseContext* pContext,
bool _bIntl,
bool _bQuote,
2000-10-19 10:47:14 +00:00
sal_Char _cDecSep,
bool _bPredicate) const;
2000-09-18 15:18:56 +00:00
private:
void impl_parseNodeToString_throw( OUStringBuffer& rString, const SQLParseNodeParameter& rParam, bool bSimple=true ) const;
void impl_parseLikeNodeToString_throw( OUStringBuffer& rString, const SQLParseNodeParameter& rParam, bool bSimple=true ) const;
void impl_parseTableRangeNodeToString_throw( OUStringBuffer& rString, const SQLParseNodeParameter& rParam ) const;
/** parses a table_name node into a SQL statement particle.
@return
<TRUE/> if and only if parsing was successful, <FALSE/> if default handling should
be applied.
*/
bool impl_parseTableNameNodeToString_throw( OUStringBuffer& rString, const SQLParseNodeParameter& rParam ) const;
bool addDateValue(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const;
static OUString convertDateTimeString(const SQLParseNodeParameter& rParam, const OUString& rString);
static OUString convertDateString(const SQLParseNodeParameter& rParam, const OUString& rString);
static OUString convertTimeString(const SQLParseNodeParameter& rParam, const OUString& rString);
void parseLeaf(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const;
2000-09-18 15:18:56 +00:00
};
inline OSQLParseNode* OSQLParseNode::getChild(sal_uInt32 nPos) const
{
return m_aChildren[nPos].get();
2000-09-18 15:18:56 +00:00
}
// utilities to query for a specific rule, token or punctuation
#define SQL_ISRULE(pParseNode, eRule) ((pParseNode)->isRule() && (pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::eRule))
#define SQL_ISRULEOR2(pParseNode, e1, e2) ((pParseNode)->isRule() && ( \
(pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e1) || \
(pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e2)))
#define SQL_ISRULEOR3(pParseNode, e1, e2, e3) ((pParseNode)->isRule() && ( \
(pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e1) || \
(pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e2) || \
(pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e3)))
2000-09-18 15:18:56 +00:00
#define SQL_ISTOKEN(pParseNode, token) ((pParseNode)->isToken() && (pParseNode)->getTokenID() == SQL_TOKEN_##token)
#define SQL_ISTOKENOR2(pParseNode, tok0, tok1) ((pParseNode)->isToken() && ( (pParseNode)->getTokenID() == SQL_TOKEN_##tok0 || (pParseNode)->getTokenID() == SQL_TOKEN_##tok1 ))
#define SQL_ISTOKENOR3(pParseNode, tok0, tok1, tok2) ((pParseNode)->isToken() && ( (pParseNode)->getTokenID() == SQL_TOKEN_##tok0 || (pParseNode)->getTokenID() == SQL_TOKEN_##tok1 || (pParseNode)->getTokenID() == SQL_TOKEN_##tok2 ))
#define SQL_ISPUNCTUATION(pParseNode, aString) ((pParseNode)->getNodeType() == SQLNodeType::Punctuation && (pParseNode)->getTokenValue() == (aString))
2000-09-18 15:18:56 +00:00
}
#endif // INCLUDED_CONNECTIVITY_SQLNODE_HXX
2010-10-27 13:11:31 +01:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */