2008-05-19 15:47:48 +02:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.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.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Adriano dos Santos Fernandes
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Adriano dos Santos Fernandes <adrianosf@uol.com.br>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DSQL_NODES_H
|
|
|
|
#define DSQL_NODES_H
|
|
|
|
|
|
|
|
#include "../jrd/common.h"
|
2010-08-27 04:18:00 +02:00
|
|
|
#include "../dsql/DsqlCompilerScratch.h"
|
2010-02-13 21:29:29 +01:00
|
|
|
#include "../dsql/node.h"
|
|
|
|
#include "../dsql/Visitors.h"
|
|
|
|
#include "../common/classes/array.h"
|
2010-08-09 17:48:51 +02:00
|
|
|
#include "../common/classes/NestConst.h"
|
2008-05-19 15:47:48 +02:00
|
|
|
|
|
|
|
namespace Jrd {
|
|
|
|
|
2010-02-13 21:29:29 +01:00
|
|
|
class AggregateSort;
|
2008-05-19 15:47:48 +02:00
|
|
|
class CompilerScratch;
|
2010-02-22 17:00:49 +01:00
|
|
|
class Cursor;
|
2010-02-13 21:29:29 +01:00
|
|
|
class dsql_nod;
|
|
|
|
class ExprNode;
|
|
|
|
class jrd_nod;
|
2010-08-24 05:25:01 +02:00
|
|
|
class RseNode;
|
2010-02-16 01:26:53 +01:00
|
|
|
class SlidingWindow;
|
2009-10-21 02:42:38 +02:00
|
|
|
class TypeClause;
|
2008-05-19 15:47:48 +02:00
|
|
|
|
|
|
|
|
2010-02-13 21:29:29 +01:00
|
|
|
template <typename T>
|
|
|
|
class RegisterNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit RegisterNode(UCHAR blr)
|
|
|
|
{
|
|
|
|
PAR_register(blr, T::parse);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-19 15:47:48 +02:00
|
|
|
class Node : public Firebird::PermanentStorage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Node(MemoryPool& pool)
|
|
|
|
: PermanentStorage(pool),
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch(NULL)
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Node()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2009-12-20 22:01:10 +01:00
|
|
|
Node* dsqlPass(DsqlCompilerScratch* aDsqlScratch)
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch = aDsqlScratch;
|
2009-10-21 02:42:38 +02:00
|
|
|
return internalDsqlPass();
|
2008-05-19 15:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const = 0;
|
|
|
|
|
|
|
|
protected:
|
2009-10-21 02:42:38 +02:00
|
|
|
virtual Node* internalDsqlPass()
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2009-12-20 22:01:10 +01:00
|
|
|
DsqlCompilerScratch* dsqlScratch;
|
2008-05-19 15:47:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DdlNode : public Node
|
|
|
|
{
|
|
|
|
public:
|
2010-08-05 02:47:06 +02:00
|
|
|
explicit DdlNode(MemoryPool& pool)
|
|
|
|
: Node(pool)
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-26 04:37:57 +02:00
|
|
|
static bool deleteSecurityClass(thread_db* tdbb, jrd_tra* transaction,
|
|
|
|
const Firebird::MetaName& secClass);
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
public:
|
2010-03-06 20:10:48 +01:00
|
|
|
// Set the scratch's transaction when executing a node. Fact of accessing the scratch during
|
|
|
|
// execution is a hack.
|
|
|
|
void executeDdl(thread_db* tdbb, jrd_tra* transaction)
|
|
|
|
{
|
2010-07-26 04:37:57 +02:00
|
|
|
using namespace Firebird;
|
|
|
|
|
2010-03-06 20:10:48 +01:00
|
|
|
dsqlScratch->setTransaction(transaction);
|
2010-07-26 04:37:57 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
execute(tdbb, transaction);
|
|
|
|
}
|
|
|
|
catch (status_exception& ex)
|
|
|
|
{
|
|
|
|
// Rethrow an exception with isc_no_meta_update and prefix codes.
|
|
|
|
|
|
|
|
Arg::StatusVector newVector;
|
|
|
|
newVector << Arg::Gds(isc_no_meta_update);
|
|
|
|
putErrorPrefix(newVector);
|
|
|
|
|
|
|
|
const ISC_STATUS* status = ex.value();
|
|
|
|
|
|
|
|
if (status[1] == isc_no_meta_update)
|
|
|
|
status += 2;
|
|
|
|
|
|
|
|
newVector.append(Arg::StatusVector(status));
|
|
|
|
|
|
|
|
status_exception::raise(newVector);
|
|
|
|
}
|
2010-03-06 20:10:48 +01:00
|
|
|
}
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
public:
|
|
|
|
enum DdlTriggerWhen { DTW_BEFORE, DTW_AFTER };
|
2010-07-26 04:37:57 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
static void executeDdlTrigger(thread_db* tdbb, jrd_tra* transaction,
|
|
|
|
DdlTriggerWhen when, int action, const Firebird::MetaName& objectName,
|
|
|
|
const Firebird::string& sqlText);
|
|
|
|
|
|
|
|
protected:
|
2010-07-26 04:37:57 +02:00
|
|
|
// Return exception code based on combination of create and alter clauses.
|
|
|
|
static ISC_STATUS createAlterCode(bool create, bool alter, ISC_STATUS createCode,
|
|
|
|
ISC_STATUS alterCode, ISC_STATUS createOrAlterCode)
|
|
|
|
{
|
|
|
|
if (create && alter)
|
|
|
|
return createOrAlterCode;
|
2010-08-09 13:50:12 +02:00
|
|
|
|
|
|
|
if (create)
|
2010-07-26 04:37:57 +02:00
|
|
|
return createCode;
|
2010-08-09 13:50:12 +02:00
|
|
|
|
|
|
|
if (alter)
|
2010-07-26 04:37:57 +02:00
|
|
|
return alterCode;
|
2010-08-09 13:50:12 +02:00
|
|
|
|
|
|
|
fb_assert(false);
|
|
|
|
return 0;
|
2010-07-26 04:37:57 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
void executeDdlTrigger(thread_db* tdbb, jrd_tra* transaction,
|
|
|
|
DdlTriggerWhen when, int action, const Firebird::MetaName& objectName);
|
|
|
|
void putType(const TypeClause& type, bool useSubType);
|
|
|
|
void resetContextStack();
|
2010-07-26 04:37:57 +02:00
|
|
|
void storeGlobalField(thread_db* tdbb, jrd_tra* transaction, Firebird::MetaName& name,
|
|
|
|
const TypeClause& field,
|
|
|
|
const Firebird::string& computedSource = "",
|
|
|
|
const BlrWriter::BlrData& computedValue = BlrWriter::BlrData());
|
2009-10-21 02:42:38 +02:00
|
|
|
|
2008-05-25 17:41:54 +02:00
|
|
|
protected:
|
2009-12-20 22:01:10 +01:00
|
|
|
virtual DdlNode* internalDsqlPass()
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
2009-12-23 01:57:08 +01:00
|
|
|
dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_DDL);
|
2008-05-25 17:41:54 +02:00
|
|
|
return this;
|
2008-05-19 15:47:48 +02:00
|
|
|
}
|
|
|
|
|
2010-07-26 04:37:57 +02:00
|
|
|
// Prefix DDL exceptions. To be implemented in each command.
|
|
|
|
virtual void putErrorPrefix(Firebird::Arg::StatusVector& statusVector) = 0;
|
|
|
|
|
2008-05-19 15:47:48 +02:00
|
|
|
public:
|
|
|
|
virtual void execute(thread_db* tdbb, jrd_tra* transaction) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DmlNode : public Node
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit DmlNode(MemoryPool& pool)
|
2009-10-21 02:42:38 +02:00
|
|
|
: Node(pool),
|
|
|
|
node(NULL)
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2010-02-21 02:47:54 +01:00
|
|
|
virtual DmlNode* pass1(thread_db* tdbb, CompilerScratch* csb, jrd_nod* aNode);
|
2008-05-19 15:47:48 +02:00
|
|
|
virtual DmlNode* pass2(thread_db* tdbb, CompilerScratch* csb, jrd_nod* aNode);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void genBlr() = 0;
|
|
|
|
virtual DmlNode* pass1(thread_db* tdbb, CompilerScratch* csb) = 0;
|
|
|
|
virtual DmlNode* pass2(thread_db* tdbb, CompilerScratch* csb) = 0;
|
|
|
|
|
|
|
|
protected:
|
2010-08-09 17:48:51 +02:00
|
|
|
NestConst<jrd_nod> node;
|
2008-05-19 15:47:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-02-13 21:29:29 +01:00
|
|
|
template <typename T, typename T::Type typeConst>
|
|
|
|
class TypedNode : public T
|
|
|
|
{
|
|
|
|
public:
|
2010-02-16 09:53:31 +01:00
|
|
|
explicit TypedNode(MemoryPool& pool)
|
2010-02-13 21:29:29 +01:00
|
|
|
: T(typeConst, pool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
const static typename T::Type TYPE = typeConst;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ExprNode : public DmlNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
TYPE_AGGREGATE,
|
Refactor a number of expression nodes: nod_add, nod_divide, nod_multiply, nod_negate, nod_user_name, nod_subtract, nod_current_date, nod_current_time, nod_current_timestamp, nod_add2, nod_subtract2, nod_multiply2, nod_divide2, nod_current_role, nod_internal_info
2010-09-04 23:36:41 +02:00
|
|
|
TYPE_ARITHMETIC,
|
2010-02-13 21:29:29 +01:00
|
|
|
TYPE_CONCATENATE,
|
Refactor a number of expression nodes: nod_add, nod_divide, nod_multiply, nod_negate, nod_user_name, nod_subtract, nod_current_date, nod_current_time, nod_current_timestamp, nod_add2, nod_subtract2, nod_multiply2, nod_divide2, nod_current_role, nod_internal_info
2010-09-04 23:36:41 +02:00
|
|
|
TYPE_CURRENT_DATE,
|
|
|
|
TYPE_CURRENT_TIME,
|
|
|
|
TYPE_CURRENT_TIMESTAMP,
|
|
|
|
TYPE_CURRENT_ROLE,
|
|
|
|
TYPE_CURRENT_USER,
|
|
|
|
TYPE_INTERNAL_INFO,
|
|
|
|
TYPE_NEGATE,
|
2010-02-21 02:47:54 +01:00
|
|
|
TYPE_OVER,
|
2010-04-05 20:43:11 +02:00
|
|
|
TYPE_SUBSTRING_SIMILAR,
|
|
|
|
TYPE_SYSFUNC_CALL,
|
|
|
|
TYPE_UDF_CALL
|
2010-02-13 21:29:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit ExprNode(Type aType, MemoryPool& pool)
|
|
|
|
: DmlNode(pool),
|
|
|
|
type(aType),
|
|
|
|
dsqlCompatDialectVerb(NULL),
|
|
|
|
dsqlChildNodes(pool),
|
|
|
|
jrdChildNodes(pool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> T* as()
|
|
|
|
{
|
|
|
|
return type == T::TYPE ? (T*) this : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> const T* as() const
|
|
|
|
{
|
|
|
|
return type == T::TYPE ? (T*) this : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> bool is() const
|
|
|
|
{
|
|
|
|
return type == T::TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename LegacyType> static T* as(LegacyType* node)
|
|
|
|
{
|
|
|
|
ExprNode* obj = T::fromLegacy(node);
|
|
|
|
return obj ? obj->as<T>() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename LegacyType> static const T* as(const LegacyType* node)
|
|
|
|
{
|
2010-03-21 23:06:17 +01:00
|
|
|
const ExprNode* obj = T::fromLegacy(node);
|
|
|
|
return obj ? obj->as<T>() : NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-13 21:29:29 +01:00
|
|
|
template <typename T, typename LegacyType> static bool is(const LegacyType* node)
|
|
|
|
{
|
2010-03-22 00:01:30 +01:00
|
|
|
const ExprNode* obj = T::fromLegacy(node);
|
2010-02-13 21:29:29 +01:00
|
|
|
return obj ? obj->is<T>() : false;
|
|
|
|
}
|
|
|
|
|
2010-03-21 23:06:17 +01:00
|
|
|
static ExprNode* fromLegacy(const dsql_nod* node);
|
2010-08-09 17:48:51 +02:00
|
|
|
static const ExprNode* fromLegacy(const jrd_nod* node);
|
|
|
|
static ExprNode* fromLegacy(jrd_nod* node);
|
2010-02-13 21:29:29 +01:00
|
|
|
|
|
|
|
virtual bool dsqlAggregateFinder(AggregateFinder& visitor)
|
|
|
|
{
|
|
|
|
return dsqlVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool dsqlAggregate2Finder(Aggregate2Finder& visitor)
|
|
|
|
{
|
|
|
|
return dsqlVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool dsqlFieldFinder(FieldFinder& visitor)
|
|
|
|
{
|
|
|
|
return dsqlVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool dsqlInvalidReferenceFinder(InvalidReferenceFinder& visitor)
|
|
|
|
{
|
|
|
|
return dsqlVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool dsqlSubSelectFinder(SubSelectFinder& visitor)
|
|
|
|
{
|
|
|
|
return dsqlVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool dsqlFieldRemapper(FieldRemapper& visitor)
|
|
|
|
{
|
|
|
|
return dsqlVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool jrdPossibleUnknownFinder(PossibleUnknownFinder& visitor)
|
|
|
|
{
|
|
|
|
return jrdVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool jrdStreamFinder(StreamFinder& visitor)
|
|
|
|
{
|
|
|
|
return jrdVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool jrdStreamsCollector(StreamsCollector& visitor)
|
|
|
|
{
|
|
|
|
return jrdVisit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool jrdUnmappedNodeGetter(UnmappedNodeGetter& visitor)
|
|
|
|
{
|
|
|
|
visitor.nodeFound = node;
|
Refactor a number of expression nodes: nod_add, nod_divide, nod_multiply, nod_negate, nod_user_name, nod_subtract, nod_current_date, nod_current_time, nod_current_timestamp, nod_add2, nod_subtract2, nod_multiply2, nod_divide2, nod_current_role, nod_internal_info
2010-09-04 23:36:41 +02:00
|
|
|
|
|
|
|
for (NestConst<NestConst<jrd_nod> >* i = jrdChildNodes.begin(); i != jrdChildNodes.end(); ++i)
|
|
|
|
{
|
|
|
|
if (!visitor.visit(**i))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-02-13 21:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const;
|
|
|
|
virtual bool dsqlMatch(const ExprNode* other, bool ignoreMapCast) const;
|
|
|
|
virtual ExprNode* pass1(thread_db* tdbb, CompilerScratch* csb);
|
|
|
|
virtual ExprNode* pass2(thread_db* tdbb, CompilerScratch* csb);
|
|
|
|
|
2010-02-16 09:53:31 +01:00
|
|
|
virtual bool setParameterType(DsqlCompilerScratch* /*dsqlScratch*/,
|
|
|
|
dsql_nod* /*node*/, bool /*forceVarChar*/) const
|
2010-02-13 21:29:29 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setParameterName(dsql_par* parameter) const = 0;
|
|
|
|
virtual void make(dsc* desc, dsql_nod* nullReplacement) = 0;
|
|
|
|
|
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc) = 0;
|
2010-08-09 17:48:51 +02:00
|
|
|
virtual ExprNode* copy(thread_db* tdbb, NodeCopier& copier) = 0;
|
2010-02-13 21:29:29 +01:00
|
|
|
virtual dsc* execute(thread_db* tdbb, jrd_req* request) const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool dsqlVisit(ConstDsqlNodeVisitor& visitor);
|
|
|
|
virtual bool dsqlVisit(NonConstDsqlNodeVisitor& visitor);
|
|
|
|
virtual bool jrdVisit(JrdNodeVisitor& visitor);
|
|
|
|
|
2010-08-09 17:48:51 +02:00
|
|
|
void addChildNode(dsql_nod*& dsqlNode, NestConst<jrd_nod>& jrdNode)
|
2010-02-13 21:29:29 +01:00
|
|
|
{
|
|
|
|
dsqlChildNodes.add(&dsqlNode);
|
|
|
|
jrdChildNodes.add(&jrdNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addChildNode(dsql_nod*& dsqlNode)
|
|
|
|
{
|
|
|
|
dsqlChildNodes.add(&dsqlNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
const Type type;
|
|
|
|
const char* dsqlCompatDialectVerb;
|
|
|
|
Firebird::Array<dsql_nod**> dsqlChildNodes;
|
2010-08-09 18:06:23 +02:00
|
|
|
Firebird::Array<NestConst<NestConst<jrd_nod> > > jrdChildNodes;
|
2010-02-13 21:29:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class AggNode : public TypedNode<ExprNode, ExprNode::TYPE_AGGREGATE>
|
|
|
|
{
|
2010-02-14 20:08:22 +01:00
|
|
|
protected:
|
2010-02-13 21:29:29 +01:00
|
|
|
struct AggInfo
|
|
|
|
{
|
2010-02-14 20:08:22 +01:00
|
|
|
AggInfo(const char* aName, UCHAR aBlr, UCHAR aDistinctBlr)
|
|
|
|
: name(aName),
|
|
|
|
blr(aBlr),
|
|
|
|
distinctBlr(aDistinctBlr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-02-15 01:43:04 +01:00
|
|
|
const char* const name;
|
|
|
|
const UCHAR blr;
|
|
|
|
const UCHAR distinctBlr;
|
2010-02-13 21:29:29 +01:00
|
|
|
};
|
|
|
|
|
2010-02-14 20:08:22 +01:00
|
|
|
public:
|
|
|
|
template <typename T>
|
|
|
|
class Register : public AggInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Register(const char* aName, UCHAR blr, UCHAR blrDistinct)
|
|
|
|
: AggInfo(aName, blr, blrDistinct),
|
|
|
|
registerNode1(blr),
|
|
|
|
registerNode2(blrDistinct)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit Register(const char* aName, UCHAR blr)
|
|
|
|
: AggInfo(aName, blr, blr),
|
|
|
|
registerNode1(blr),
|
|
|
|
registerNode2(blr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RegisterNode<T> registerNode1, registerNode2;
|
|
|
|
};
|
|
|
|
|
2010-02-13 21:29:29 +01:00
|
|
|
explicit AggNode(MemoryPool& pool, const AggInfo& aAggInfo, bool aDistinct, bool aDialect1,
|
|
|
|
dsql_nod* aArg = NULL);
|
|
|
|
|
|
|
|
virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const;
|
|
|
|
|
|
|
|
virtual bool dsqlAggregateFinder(AggregateFinder& visitor);
|
|
|
|
virtual bool dsqlAggregate2Finder(Aggregate2Finder& visitor);
|
|
|
|
virtual bool dsqlInvalidReferenceFinder(InvalidReferenceFinder& visitor);
|
|
|
|
virtual bool dsqlSubSelectFinder(SubSelectFinder& visitor);
|
|
|
|
virtual bool dsqlFieldRemapper(FieldRemapper& visitor);
|
|
|
|
|
|
|
|
virtual bool dsqlMatch(const ExprNode* other, bool ignoreMapCast) const;
|
|
|
|
virtual void setParameterName(dsql_par* parameter) const;
|
|
|
|
virtual void genBlr();
|
|
|
|
|
|
|
|
virtual ExprNode* pass2(thread_db* tdbb, CompilerScratch* csb);
|
|
|
|
|
2010-02-16 09:53:31 +01:00
|
|
|
virtual bool jrdPossibleUnknownFinder(PossibleUnknownFinder& /*visitor*/)
|
2010-02-13 21:29:29 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-16 09:53:31 +01:00
|
|
|
virtual bool jrdStreamFinder(StreamFinder& /*visitor*/)
|
2010-02-13 21:29:29 +01:00
|
|
|
{
|
|
|
|
// ASF: Although in v2.5 the visitor happens normally for the node childs, nod_count has
|
|
|
|
// been set to 0 in CMP_pass2, so that doesn't happens.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-16 09:53:31 +01:00
|
|
|
virtual bool jrdStreamsCollector(StreamsCollector& /*visitor*/)
|
2010-02-13 21:29:29 +01:00
|
|
|
{
|
|
|
|
// ASF: Although in v2.5 the visitor happens normally for the node childs, nod_count has
|
|
|
|
// been set to 0 in CMP_pass2, so that doesn't happens.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool jrdUnmappedNodeGetter(UnmappedNodeGetter& visitor)
|
|
|
|
{
|
|
|
|
visitor.invalid = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void checkOrderedWindowCapable() const
|
|
|
|
{
|
|
|
|
if (distinct)
|
|
|
|
{
|
|
|
|
Firebird::status_exception::raise(
|
|
|
|
Firebird::Arg::Gds(isc_wish_list) <<
|
|
|
|
Firebird::Arg::Gds(isc_random) <<
|
|
|
|
"DISTINCT is not supported in ordered windows");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-14 20:08:22 +01:00
|
|
|
virtual bool shouldCallWinPass() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-16 09:53:31 +01:00
|
|
|
virtual dsc* winPass(thread_db* /*tdbb*/, jrd_req* /*request*/, SlidingWindow* /*window*/) const
|
2010-02-14 20:08:22 +01:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-13 21:29:29 +01:00
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const = 0; // pure, but defined
|
|
|
|
virtual void aggFinish(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual dsc* execute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const = 0;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ExprNode* internalDsqlPass();
|
|
|
|
virtual AggNode* dsqlCopy() const = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
const AggInfo& aggInfo;
|
|
|
|
bool distinct;
|
|
|
|
bool dialect1;
|
|
|
|
dsql_nod* dsqlArg;
|
2010-08-09 17:48:51 +02:00
|
|
|
NestConst<jrd_nod> arg;
|
2010-04-07 17:31:32 +02:00
|
|
|
const AggregateSort* asb;
|
2010-02-13 21:29:29 +01:00
|
|
|
bool indexed;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-02-15 01:43:04 +01:00
|
|
|
// Base class for window functions.
|
2010-02-14 20:08:22 +01:00
|
|
|
class WinFuncNode : public AggNode
|
|
|
|
{
|
|
|
|
private:
|
2010-02-15 01:43:04 +01:00
|
|
|
// Base factory to create instance of subclasses.
|
2010-02-14 20:08:22 +01:00
|
|
|
class Factory : public AggInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Factory(const char* aName)
|
|
|
|
: AggInfo(aName, 0, 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual WinFuncNode* newInstance(MemoryPool& pool) const = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
const Factory* next;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2010-02-15 01:43:04 +01:00
|
|
|
// Concrete implementation of the factory.
|
2010-02-14 20:08:22 +01:00
|
|
|
template <typename T>
|
|
|
|
class Register : public Factory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Register(const char* aName)
|
|
|
|
: Factory(aName)
|
|
|
|
{
|
|
|
|
next = factories;
|
|
|
|
factories = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
WinFuncNode* newInstance(MemoryPool& pool) const
|
|
|
|
{
|
|
|
|
return new T(pool);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit WinFuncNode(MemoryPool& pool, const AggInfo& aAggInfo, dsql_nod* aArg = NULL);
|
|
|
|
|
|
|
|
static DmlNode* parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb, UCHAR blrOp);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static Factory* factories;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-19 15:47:48 +02:00
|
|
|
class StmtNode : public DmlNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit StmtNode(MemoryPool& pool)
|
|
|
|
: DmlNode(pool)
|
|
|
|
{
|
|
|
|
}
|
2010-02-13 21:29:29 +01:00
|
|
|
|
|
|
|
public:
|
2010-08-24 05:25:01 +02:00
|
|
|
virtual void pass2Cursor(RseNode*& /*rsePtr*/, Cursor**& /*cursorPtr*/)
|
2010-02-22 17:00:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-09 17:48:51 +02:00
|
|
|
virtual const jrd_nod* execute(thread_db* tdbb, jrd_req* request) const = 0;
|
2008-05-19 15:47:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-31 04:33:45 +01:00
|
|
|
// Used to represent nodes that don't have a specific BLR verb, i.e.,
|
|
|
|
// do not use RegisterNode.
|
2009-10-24 19:45:33 +02:00
|
|
|
class DsqlOnlyStmtNode : public StmtNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit DsqlOnlyStmtNode(MemoryPool& pool)
|
|
|
|
: StmtNode(pool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2009-10-30 11:43:42 +01:00
|
|
|
DsqlOnlyStmtNode* pass1(thread_db* /*tdbb*/, CompilerScratch* /*csb*/)
|
2009-10-24 19:45:33 +02:00
|
|
|
{
|
|
|
|
fb_assert(false);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2009-10-30 11:43:42 +01:00
|
|
|
DsqlOnlyStmtNode* pass2(thread_db* /*tdbb*/, CompilerScratch* /*csb*/)
|
2009-10-24 19:45:33 +02:00
|
|
|
{
|
|
|
|
fb_assert(false);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2010-08-09 17:48:51 +02:00
|
|
|
const jrd_nod* execute(thread_db* /*tdbb*/, jrd_req* /*request*/) const
|
2009-10-24 19:45:33 +02:00
|
|
|
{
|
|
|
|
fb_assert(false);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-05 18:32:42 +01:00
|
|
|
// This class (via the make method) does the job that pass1_savepoint does for the legacy nodes.
|
|
|
|
class SavepointEncloseNode : public DsqlOnlyStmtNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SavepointEncloseNode(MemoryPool& pool, StmtNode* aStmt)
|
|
|
|
: DsqlOnlyStmtNode(pool),
|
|
|
|
stmt(aStmt)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static StmtNode* make(MemoryPool& pool, DsqlCompilerScratch* dsqlScratch, StmtNode* node);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const;
|
|
|
|
virtual void genBlr();
|
|
|
|
|
|
|
|
private:
|
|
|
|
StmtNode* stmt;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-19 15:47:48 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif // DSQL_NODES_H
|