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"
|
|
|
|
#include "../dsql/dsql.h"
|
|
|
|
|
|
|
|
namespace Jrd {
|
|
|
|
|
|
|
|
class CompilerScratch;
|
2009-10-21 02:42:38 +02:00
|
|
|
class TypeClause;
|
2008-05-19 15:47:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Node : public Firebird::PermanentStorage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Node(MemoryPool& pool)
|
|
|
|
: PermanentStorage(pool),
|
2008-05-24 05:19:52 +02:00
|
|
|
compiledStatement(NULL)
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Node()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2008-05-25 17:41:54 +02:00
|
|
|
Node* dsqlPass(CompiledStatement* aCompiledStatement)
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
2008-05-24 05:19:52 +02:00
|
|
|
compiledStatement = aCompiledStatement;
|
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:
|
2008-05-24 05:19:52 +02:00
|
|
|
CompiledStatement* compiledStatement;
|
2008-05-19 15:47:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DdlNode : public Node
|
|
|
|
{
|
|
|
|
public:
|
2009-10-21 02:42:38 +02:00
|
|
|
explicit DdlNode(MemoryPool& pool, const Firebird::string& aSqlText)
|
|
|
|
: Node(pool),
|
|
|
|
sqlText(pool, aSqlText)
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
public:
|
|
|
|
const Firebird::string& getSqlText()
|
|
|
|
{
|
|
|
|
return sqlText;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum DdlTriggerWhen { DTW_BEFORE, DTW_AFTER };
|
|
|
|
static void executeDdlTrigger(thread_db* tdbb, jrd_tra* transaction,
|
|
|
|
DdlTriggerWhen when, int action, const Firebird::MetaName& objectName,
|
|
|
|
const Firebird::string& sqlText);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void checkEmptyName(const Firebird::MetaName& name);
|
|
|
|
static Firebird::MetaName nameInMetaCharSet(thread_db* tdbb, const Firebird::MetaName& name);
|
|
|
|
static Firebird::MetaName nameInUserCharSet(thread_db* tdbb, const Firebird::MetaName& name);
|
|
|
|
static void storeTextBlob(thread_db* tdbb, jrd_tra* transaction, bid* blobId,
|
|
|
|
const Firebird::string& text);
|
|
|
|
static void storeBlob(thread_db* tdbb, jrd_tra* transaction, bid* blobId,
|
|
|
|
const UCHAR* data, unsigned length);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
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();
|
|
|
|
|
2008-05-25 17:41:54 +02:00
|
|
|
protected:
|
2009-10-21 02:42:38 +02:00
|
|
|
virtual Node* internalDsqlPass()
|
2008-05-19 15:47:48 +02:00
|
|
|
{
|
2008-05-25 17:41:54 +02:00
|
|
|
compiledStatement->req_type = REQ_DDL;
|
|
|
|
return this;
|
2008-05-19 15:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void execute(thread_db* tdbb, jrd_tra* transaction) = 0;
|
2009-10-21 02:42:38 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Firebird::string sqlText;
|
2008-05-19 15:47:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
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;
|
|
|
|
virtual jrd_nod* execute(thread_db* tdbb, jrd_req* request) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
jrd_nod* node;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class StmtNode : public DmlNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit StmtNode(MemoryPool& pool)
|
|
|
|
: DmlNode(pool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-30 15:24:16 +01:00
|
|
|
// Used to represent nodes that doesn't have a specific BLR verb, i.e.,
|
|
|
|
// does 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-30 11:43:42 +01:00
|
|
|
jrd_nod* execute(thread_db* /*tdbb*/, jrd_req* /*request*/)
|
2009-10-24 19:45:33 +02:00
|
|
|
{
|
|
|
|
fb_assert(false);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
// Common node for all "code blocks" (i.e.: procedures, triggers and execute block)
|
|
|
|
class BlockNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~BlockNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void genReturn() = 0;
|
|
|
|
virtual dsql_nod* resolveVariable(const dsql_str* varName) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-19 15:47:48 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif // DSQL_NODES_H
|