Skip to content

Commit

Permalink
Improvement CORE-5431 - Support for DROP IDENTITY clause.
Browse files Browse the repository at this point in the history
  • Loading branch information
asfernandes committed Dec 28, 2016
1 parent 9fd55f7 commit 127dddf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,9 @@

## Improvements

* [CORE-5430](http://tracker.firebirdsql.org/browse/CORE-5431): Support for DROP IDENTITY clause
Contributor(s): Adriano dos Santos Fernandes

* [CORE-5430](http://tracker.firebirdsql.org/browse/CORE-5430): Support for INCREMENT option in identity columns
Contributor(s): Adriano dos Santos Fernandes

Expand Down
9 changes: 8 additions & 1 deletion doc/sql.extensions/README.identity_columns.txt
Expand Up @@ -19,7 +19,8 @@ Syntax:

<alter column definition> ::=
<name> RESTART [ WITH <value> ] |
<name> SET INCREMENT [ BY ] <value>
<name> SET INCREMENT [ BY ] <value> |
<name> DROP IDENTITY

Syntax rules:
- The type of an identity column must be an exact number type with zero scale. That includes:
Expand Down Expand Up @@ -74,3 +75,9 @@ select * from objects order by id;
2 Book
10 Computer
15 Pencil

alter table objects
alter id set increment by 2;

alter table objects
alter id drop identity;
15 changes: 15 additions & 0 deletions src/dsql/DdlNodes.epp
Expand Up @@ -7847,6 +7847,21 @@ void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlSc
}
END_MODIFY
}
else if (clause->dropIdentity)
{
if (RFR.RDB$GENERATOR_NAME.NULL)
{
// msg 285: "Column @1 is not an identity column"
status_exception::raise(Arg::PrivateDyn(285) << field->fld_name);
}

DropSequenceNode::deleteIdentity(tdbb, transaction, RFR.RDB$GENERATOR_NAME);

MODIFY RFR
RFR.RDB$GENERATOR_NAME.NULL = TRUE;
RFR.RDB$IDENTITY_TYPE.NULL = TRUE;
END_MODIFY
}
else if (clause->identityRestart || clause->identityIncrement.specified)
{
bool found = false;
Expand Down
2 changes: 2 additions & 0 deletions src/dsql/DdlNodes.h
Expand Up @@ -1383,6 +1383,7 @@ class RelationNode : public DdlNode
field(NULL),
defaultValue(NULL),
dropDefault(false),
dropIdentity(false),
identityRestart(false),
computed(NULL)
{
Expand All @@ -1391,6 +1392,7 @@ class RelationNode : public DdlNode
dsql_fld* field;
NestConst<ValueSourceClause> defaultValue;
bool dropDefault;
bool dropIdentity;
bool identityRestart;
Nullable<SINT64> identityRestartValue;
Nullable<SINT64> identityIncrement;
Expand Down
8 changes: 8 additions & 0 deletions src/dsql/parse.y
Expand Up @@ -3944,6 +3944,14 @@ alter_op($relationNode)
clause->identityIncrement = $6;
$relationNode->clauses.add(clause);
}
| col_opt symbol_column_name DROP IDENTITY
{
RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>();
clause->field = newNode<dsql_fld>();
clause->field->fld_name = *$2;
clause->dropIdentity = true;
$relationNode->clauses.add(clause);
}
| ALTER SQL SECURITY DEFINER
{
RelationNode::AlterSqlSecurityClause* clause =
Expand Down

0 comments on commit 127dddf

Please sign in to comment.