Skip to content

Commit

Permalink
Fixed CORE-4315 - Usage of field's alias in view WITH CHECK OPTION le…
Browse files Browse the repository at this point in the history
…ads to incorrect compile error or incorrect internal triggers.
  • Loading branch information
asfernandes committed Jan 14, 2014
1 parent 13965d5 commit fc6110d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/dsql/DdlNodes.epp
Expand Up @@ -8085,6 +8085,7 @@ void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratc

RelationSourceNode* baseRelation = FB_NEW(pool) RelationSourceNode(pool,
sourceNode->dsqlName.identifier);
baseRelation->alias = sourceNode->alias;

dsqlScratch->appendUChar(blr_for);

Expand Down Expand Up @@ -8194,7 +8195,9 @@ void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratc
newContext->ctx_flags |= CTX_system;

if (triggerType == PRE_STORE_TRIGGER)
newContext->ctx_flags |= CTX_view_with_check;
newContext->ctx_flags |= CTX_view_with_check_store;
else
newContext->ctx_flags |= CTX_view_with_check_modify;
}

// Replace the view's field names by the base table field names. Save the original names
Expand Down
15 changes: 9 additions & 6 deletions src/dsql/ExprNodes.cpp
Expand Up @@ -4893,19 +4893,22 @@ ValueExprNode* FieldNode::internalDsqlPass(DsqlCompilerScratch* dsqlScratch, Rec
}
}

if ((context->ctx_flags & CTX_view_with_check) && !field)
if ((context->ctx_flags & CTX_view_with_check_store) && !field)
{
node = FB_NEW(*tdbb->getDefaultPool()) NullNode(*tdbb->getDefaultPool());
node->line = line;
node->column = column;
}
else if (dsqlQualifier.hasData() && !field)
{
// If a qualifier was present and we didn't find
// a matching field then we should stop searching.
// Column unknown error will be raised at bottom of function.
done = true;
break;
if (!(context->ctx_flags & CTX_view_with_check_modify))
{
// If a qualifier was present and we didn't find
// a matching field then we should stop searching.
// Column unknown error will be raised at bottom of function.
done = true;
break;
}
}
else if (field || usingField)
{
Expand Down
13 changes: 7 additions & 6 deletions src/dsql/dsql.h
Expand Up @@ -757,12 +757,13 @@ class dsql_ctx : public pool_alloc<dsql_type_ctx>

// Flag values for ctx_flags

const USHORT CTX_outer_join = 0x01; // reference is part of an outer join
const USHORT CTX_system = 0x02; // Context generated by system (NEW/OLD in triggers, check-constraint, RETURNING)
const USHORT CTX_null = 0x04; // Fields of the context should be resolved to NULL constant
const USHORT CTX_returning = 0x08; // Context generated by RETURNING
const USHORT CTX_recursive = 0x10; // Context has secondary number (ctx_recursive) generated for recursive UNION
const USHORT CTX_view_with_check = 0x20; // Context of WITH CHECK OPTION view's triggers
const USHORT CTX_outer_join = 0x01; // reference is part of an outer join
const USHORT CTX_system = 0x02; // Context generated by system (NEW/OLD in triggers, check-constraint, RETURNING)
const USHORT CTX_null = 0x04; // Fields of the context should be resolved to NULL constant
const USHORT CTX_returning = 0x08; // Context generated by RETURNING
const USHORT CTX_recursive = 0x10; // Context has secondary number (ctx_recursive) generated for recursive UNION
const USHORT CTX_view_with_check_store = 0x20; // Context of WITH CHECK OPTION view's store trigger
const USHORT CTX_view_with_check_modify = 0x40; // Context of WITH CHECK OPTION view's modify trigger

//! Aggregate/union map block to map virtual fields to their base
//! TMN: NOTE! This datatype should definitely be renamed!
Expand Down

0 comments on commit fc6110d

Please sign in to comment.