mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 07:23:04 +01:00
Give names to the old and new streams in triggers.
This commit is contained in:
parent
5852ddbe2d
commit
5013cc4f16
@ -3145,7 +3145,7 @@ void CreateAlterTriggerNode::compile(thread_db* /*tdbb*/, DsqlCompilerScratch* d
|
||||
|
||||
if (hasOldContext(type.value))
|
||||
{
|
||||
relationNode->alias = OLD_CONTEXT;
|
||||
relationNode->alias = OLD_CONTEXT_NAME;
|
||||
dsql_ctx* oldContext = PASS1_make_context(dsqlScratch, relationNode);
|
||||
oldContext->ctx_flags |= CTX_system;
|
||||
}
|
||||
@ -3154,7 +3154,7 @@ void CreateAlterTriggerNode::compile(thread_db* /*tdbb*/, DsqlCompilerScratch* d
|
||||
|
||||
if (hasNewContext(type.value))
|
||||
{
|
||||
relationNode->alias = NEW_CONTEXT;
|
||||
relationNode->alias = NEW_CONTEXT_NAME;
|
||||
dsql_ctx* newContext = PASS1_make_context(dsqlScratch, relationNode);
|
||||
newContext->ctx_flags |= CTX_system;
|
||||
}
|
||||
@ -6042,11 +6042,11 @@ void RelationNode::defineCheckConstraintTrigger(DsqlCompilerScratch* dsqlScratch
|
||||
// errors in pre_store and pre_modify triggers. Also, what sense can I make from NEW in
|
||||
// pre_delete? However, we clash at JRD with "no current record for fetch operation".
|
||||
|
||||
dsqlNode->alias = OLD_CONTEXT;
|
||||
dsqlNode->alias = OLD_CONTEXT_NAME;
|
||||
dsql_ctx* oldContext = PASS1_make_context(dsqlScratch, dsqlNode);
|
||||
oldContext->ctx_flags |= CTX_system;
|
||||
|
||||
dsqlNode->alias = NEW_CONTEXT;
|
||||
dsqlNode->alias = NEW_CONTEXT_NAME;
|
||||
dsql_ctx* newContext = PASS1_make_context(dsqlScratch, dsqlNode);
|
||||
newContext->ctx_flags |= CTX_system;
|
||||
|
||||
@ -8096,13 +8096,13 @@ void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratc
|
||||
rse->dsqlStreams->items[0] = doDsqlPass(dsqlScratch, rse->dsqlStreams->items[0]);
|
||||
rse->dsqlWhere = doDsqlPass(dsqlScratch, querySpec->dsqlWhere);
|
||||
|
||||
dsqlScratch->contextNumber = 0; // OLD context
|
||||
dsqlScratch->contextNumber = OLD_CONTEXT_VALUE;
|
||||
|
||||
dsql_ctx* oldContext;
|
||||
|
||||
{ /// scope
|
||||
AutoSetRestore<string> autoAlias(&relationNode->alias, sourceNode->alias);
|
||||
relationNode->alias = OLD_CONTEXT;
|
||||
relationNode->alias = OLD_CONTEXT_NAME;
|
||||
|
||||
oldContext = PASS1_make_context(dsqlScratch, relationNode);
|
||||
oldContext->ctx_flags |= CTX_system;
|
||||
@ -8161,7 +8161,7 @@ void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratc
|
||||
{
|
||||
FieldNode* oldValueNode = FB_NEW(pool) FieldNode(pool);
|
||||
oldValueNode->dsqlName = (aliasNode ? aliasNode->name : valueNode->dsqlName);
|
||||
oldValueNode->dsqlQualifier = OLD_CONTEXT;
|
||||
oldValueNode->dsqlQualifier = OLD_CONTEXT_NAME;
|
||||
|
||||
valueNod = oldValueNode->dsqlPass(dsqlScratch);
|
||||
fieldNod = fieldNode->dsqlPass(dsqlScratch);
|
||||
@ -8179,7 +8179,7 @@ void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratc
|
||||
// ASF: We'll now map the view's base table into the trigger's NEW context.
|
||||
|
||||
++dsqlScratch->scopeLevel;
|
||||
dsqlScratch->contextNumber = 1; // NEW context
|
||||
dsqlScratch->contextNumber = NEW_CONTEXT_VALUE;
|
||||
|
||||
dsql_ctx* newContext;
|
||||
|
||||
|
@ -5103,9 +5103,9 @@ dsql_fld* FieldNode::resolveContext(DsqlCompilerScratch* dsqlScratch, const Meta
|
||||
// If a qualifier is present and it's equal to the alias then we've already the right table-name
|
||||
if (!(qualifier.hasData() && qualifier == table_name))
|
||||
{
|
||||
if (strcmp(table_name, NEW_CONTEXT) == 0)
|
||||
if (strcmp(table_name, NEW_CONTEXT_NAME) == 0)
|
||||
table_name = NULL;
|
||||
else if (strcmp(table_name, OLD_CONTEXT) == 0)
|
||||
else if (strcmp(table_name, OLD_CONTEXT_NAME) == 0)
|
||||
{
|
||||
// Only use the OLD context if it is explicit used. That means the
|
||||
// qualifer should hold the "OLD" alias.
|
||||
|
@ -159,9 +159,9 @@ namespace
|
||||
newContext->ctx_flags |= CTX_null;
|
||||
}
|
||||
|
||||
oldContext->ctx_alias = oldContext->ctx_internal_alias = OLD_CONTEXT;
|
||||
oldContext->ctx_alias = oldContext->ctx_internal_alias = OLD_CONTEXT_NAME;
|
||||
|
||||
newContext->ctx_alias = newContext->ctx_internal_alias = NEW_CONTEXT;
|
||||
newContext->ctx_alias = newContext->ctx_internal_alias = NEW_CONTEXT_NAME;
|
||||
newContext->ctx_flags |= CTX_returning;
|
||||
scratch->context->push(newContext);
|
||||
}
|
||||
@ -351,11 +351,11 @@ AssignmentNode* AssignmentNode::pass1(thread_db* tdbb, CompilerScratch* csb)
|
||||
tail = &csb->csb_rpt[stream];
|
||||
|
||||
// Assignments to the OLD context are prohibited for all trigger types.
|
||||
if ((tail->csb_flags & csb_trigger) && stream == 0)
|
||||
if ((tail->csb_flags & csb_trigger) && stream == OLD_CONTEXT_VALUE)
|
||||
ERR_post(Arg::Gds(isc_read_only_field));
|
||||
|
||||
// Assignments to the NEW context are prohibited for post-action triggers.
|
||||
if ((tail->csb_flags & csb_trigger) && stream == 1 &&
|
||||
if ((tail->csb_flags & csb_trigger) && stream == NEW_CONTEXT_VALUE &&
|
||||
(csb->csb_g_flags & csb_post_trigger))
|
||||
{
|
||||
ERR_post(Arg::Gds(isc_read_only_field));
|
||||
@ -6242,7 +6242,7 @@ StmtNode* StoreNode::internalDsqlPass(DsqlCompilerScratch* dsqlScratch, bool upd
|
||||
// marks it with CTX_null so all fields be resolved to NULL constant.
|
||||
dsql_ctx* old_context = FB_NEW(dsqlScratch->getPool()) dsql_ctx(dsqlScratch->getPool());
|
||||
*old_context = *context;
|
||||
old_context->ctx_alias = old_context->ctx_internal_alias = OLD_CONTEXT;
|
||||
old_context->ctx_alias = old_context->ctx_internal_alias = OLD_CONTEXT_NAME;
|
||||
old_context->ctx_flags |= CTX_system | CTX_null | CTX_returning;
|
||||
dsqlScratch->context->push(old_context);
|
||||
|
||||
@ -6250,7 +6250,7 @@ StmtNode* StoreNode::internalDsqlPass(DsqlCompilerScratch* dsqlScratch, bool upd
|
||||
dsql_ctx* new_context = FB_NEW(dsqlScratch->getPool()) dsql_ctx(dsqlScratch->getPool());
|
||||
*new_context = *context;
|
||||
new_context->ctx_scope_level = ++dsqlScratch->scopeLevel;
|
||||
new_context->ctx_alias = new_context->ctx_internal_alias = NEW_CONTEXT;
|
||||
new_context->ctx_alias = new_context->ctx_internal_alias = NEW_CONTEXT_NAME;
|
||||
new_context->ctx_flags |= CTX_system | CTX_returning;
|
||||
dsqlScratch->context->push(new_context);
|
||||
}
|
||||
|
@ -64,8 +64,11 @@ DEFINE_TRACE_ROUTINE(dsql_trace);
|
||||
#include "../jrd/EngineInterface.h"
|
||||
|
||||
// Context aliases used in triggers
|
||||
const char* const OLD_CONTEXT = "OLD";
|
||||
const char* const NEW_CONTEXT = "NEW";
|
||||
const char* const OLD_CONTEXT_NAME = "OLD";
|
||||
const char* const NEW_CONTEXT_NAME = "NEW";
|
||||
|
||||
const int OLD_CONTEXT_VALUE = 0;
|
||||
const int NEW_CONTEXT_VALUE = 1;
|
||||
|
||||
namespace Jrd
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user