8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 17:23:03 +01:00

Changes related to CORE-1180: change syntax and semantics to the standard SQL, and also manage RDB$RELATION_CONSTRAINTS records correctly.

This commit is contained in:
asfernandes 2015-04-02 02:26:46 +00:00
parent 2a0db82304
commit edb4192e67
3 changed files with 40 additions and 13 deletions

View File

@ -357,9 +357,9 @@ SQL>
Nullability of a table field or a domain can now be changed with the ALTER command. Syntax:
ALTER TABLE <table name> ALTER <field name> [NOT] NULL
ALTER TABLE <table name> ALTER <field name> {DROP | SET} NOT NULL
ALTER DOMAIN <domain name> [NOT] NULL
ALTER DOMAIN <domain name> {DROP | SET} NOT NULL
A change in a table from NULL to NOT NULL is subject to a full data validation on the table.
A change in a domain changes and validates all the tables using the domain.

View File

@ -7159,10 +7159,6 @@ void AlterRelationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratc
const AlterColNullClause* clause =
static_cast<const AlterColNullClause*>(i->getObject());
//// FIXME: This clause allows inconsistencies like setting a field with a
//// not null CONSTRAINT as nullable, or setting a field based on a not null
//// domain as nullable (while ISQL shows it as not null).
AutoRequest request;
bool found = false;
@ -7174,13 +7170,44 @@ void AlterRelationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratc
found = true;
MODIFY RFL
{
if (!clause->notNullFlag && !RFL.RDB$GENERATOR_NAME.NULL)
{
// msg 274: Identity column @1 of table @2 cannot be changed to NULLable
status_exception::raise(Arg::PrivateDyn(274) << clause->name << name);
}
RFL.RDB$NULL_FLAG = SSHORT(clause->notNullFlag);
if (clause->notNullFlag)
{
RFL.RDB$NULL_FLAG.NULL = FALSE;
RFL.RDB$NULL_FLAG = TRUE;
Constraint nullConstraint(*tdbb->getDefaultPool());
nullConstraint.type = Constraint::TYPE_NOT_NULL;
nullConstraint.columns.add(clause->name);
defineConstraint(tdbb, dsqlScratch, transaction, nullConstraint);
}
else
{
RFL.RDB$NULL_FLAG.NULL = TRUE;
AutoRequest request2;
FOR(REQUEST_HANDLE request2 TRANSACTION_HANDLE transaction)
RCL IN RDB$RELATION_CONSTRAINTS CROSS
CHK IN RDB$CHECK_CONSTRAINTS
WITH RCL.RDB$RELATION_NAME EQ name.c_str() AND
RCL.RDB$CONSTRAINT_TYPE EQ NOT_NULL_CNSTRT AND
CHK.RDB$CONSTRAINT_NAME EQ RCL.RDB$CONSTRAINT_NAME AND
CHK.RDB$TRIGGER_NAME EQ clause->name.c_str()
{
// ASF: Record in RDB$CHECK_CONSTRAINTS is deleted by a
// system trigger.
ERASE RCL;
}
END_FOR
}
}
END_MODIFY
}
END_FOR

View File

@ -3647,10 +3647,10 @@ alter_domain_op($alterDomainNode)
{ setClause($alterDomainNode->dropDefault, "DOMAIN DROP DEFAULT"); }
| DROP CONSTRAINT
{ setClause($alterDomainNode->dropConstraint, "DOMAIN DROP CONSTRAINT"); }
| KW_NULL
{ setClause($alterDomainNode->notNullFlag, "[NOT] NULL", false); }
| NOT KW_NULL
{ setClause($alterDomainNode->notNullFlag, "[NOT] NULL", true); }
| DROP NOT KW_NULL
{ setClause($alterDomainNode->notNullFlag, "{SET | DROP} NOT NULL", false); }
| SET NOT KW_NULL
{ setClause($alterDomainNode->notNullFlag, "{SET | DROP} NOT NULL", true); }
| TO symbol_column_name
{ setClause($alterDomainNode->renameTo, "DOMAIN NAME", *$2); }
| KW_TYPE non_array_type
@ -3700,14 +3700,14 @@ alter_op($relationNode)
clause->toName = *$4;
$relationNode->clauses.add(clause);
}
| col_opt alter_column_name KW_NULL
| col_opt alter_column_name DROP NOT KW_NULL
{
RelationNode::AlterColNullClause* clause = newNode<RelationNode::AlterColNullClause>();
clause->name = *$2;
clause->notNullFlag = false;
$relationNode->clauses.add(clause);
}
| col_opt alter_column_name NOT KW_NULL
| col_opt alter_column_name SET NOT KW_NULL
{
RelationNode::AlterColNullClause* clause = newNode<RelationNode::AlterColNullClause>();
clause->name = *$2;