|
From: <asf...@us...> - 2015-04-02 02:26:54
|
Revision: 61204
http://sourceforge.net/p/firebird/code/61204
Author: asfernandes
Date: 2015-04-02 02:26:46 +0000 (Thu, 02 Apr 2015)
Log Message:
-----------
Changes related to CORE-1180: change syntax and semantics to the standard SQL, and also manage RDB$RELATION_CONSTRAINTS records correctly.
Modified Paths:
--------------
firebird/trunk/doc/sql.extensions/README.ddl.txt
firebird/trunk/src/dsql/DdlNodes.epp
firebird/trunk/src/dsql/parse.y
Modified: firebird/trunk/doc/sql.extensions/README.ddl.txt
===================================================================
--- firebird/trunk/doc/sql.extensions/README.ddl.txt 2015-04-02 00:14:14 UTC (rev 61203)
+++ firebird/trunk/doc/sql.extensions/README.ddl.txt 2015-04-02 02:26:46 UTC (rev 61204)
@@ -357,9 +357,9 @@
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.
Modified: firebird/trunk/src/dsql/DdlNodes.epp
===================================================================
--- firebird/trunk/src/dsql/DdlNodes.epp 2015-04-02 00:14:14 UTC (rev 61203)
+++ firebird/trunk/src/dsql/DdlNodes.epp 2015-04-02 02:26:46 UTC (rev 61204)
@@ -7159,10 +7159,6 @@
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 @@
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
Modified: firebird/trunk/src/dsql/parse.y
===================================================================
--- firebird/trunk/src/dsql/parse.y 2015-04-02 00:14:14 UTC (rev 61203)
+++ firebird/trunk/src/dsql/parse.y 2015-04-02 02:26:46 UTC (rev 61204)
@@ -3647,10 +3647,10 @@
{ 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 @@
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;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|