8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 10:00:38 +01:00

Allow to set more than one ALTER identity option in the same command - CORE-5430.

This commit is contained in:
Adriano dos Santos Fernandes 2016-12-30 13:55:34 -02:00
parent 74bfb8f90f
commit efc155f4b3
5 changed files with 56 additions and 44 deletions

View File

@ -18,10 +18,13 @@ Syntax:
INCREMENT [ BY ] <value> INCREMENT [ BY ] <value>
<alter column definition> ::= <alter column definition> ::=
<name> RESTART [ WITH <value> ] | <name> <alter identity column option>... |
<name> SET INCREMENT [ BY ] <value> |
<name> DROP IDENTITY <name> DROP IDENTITY
<alter identity column option> ::=
RESTART [ WITH <value> ] |
SET INCREMENT [ BY ] <value>
Syntax rules: Syntax rules:
- The type of an identity column must be an exact number type with zero scale. That includes: - The type of an identity column must be an exact number type with zero scale. That includes:
smallint, integer, bigint, numeric(x, 0) and decimal(x, 0). smallint, integer, bigint, numeric(x, 0) and decimal(x, 0).

View File

@ -6214,7 +6214,7 @@ void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
ObjectsArray<CreateDropConstraint> constraints; ObjectsArray<CreateDropConstraint> constraints;
bool notNullFlag = false; bool notNullFlag = false;
if (clause->identity) if (clause->identityOptions)
notNullFlag = true; // identity columns are implicitly not null notNullFlag = true; // identity columns are implicitly not null
for (ObjectsArray<AddConstraintClause>::iterator ptr = clause->constraints.begin(); for (ObjectsArray<AddConstraintClause>::iterator ptr = clause->constraints.begin();
@ -6277,9 +6277,9 @@ void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
if (clause->collate.hasData()) if (clause->collate.hasData())
DDL_resolve_intl_type(dsqlScratch, field, clause->collate); DDL_resolve_intl_type(dsqlScratch, field, clause->collate);
if (clause->identity) if (clause->identityOptions)
{ {
if (clause->identity->increment.orElse(1) == 0) if (clause->identityOptions->increment.orElse(1) == 0)
{ {
status_exception::raise(Arg::Gds(isc_dyn_cant_use_zero_inc_ident) << status_exception::raise(Arg::Gds(isc_dyn_cant_use_zero_inc_ident) <<
Arg::Str(field->fld_name) << Arg::Str(field->fld_name) <<
@ -6299,8 +6299,8 @@ void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
CreateAlterSequenceNode::store(tdbb, transaction, fieldDefinition.identitySequence, CreateAlterSequenceNode::store(tdbb, transaction, fieldDefinition.identitySequence,
fb_sysflag_identity_generator, fb_sysflag_identity_generator,
clause->identity->start.orElse(0), clause->identityOptions->startValue.orElse(0),
clause->identity->increment.orElse(1)); clause->identityOptions->increment.orElse(1));
} }
BlrDebugWriter::BlrData defaultValue; BlrDebugWriter::BlrData defaultValue;
@ -7862,7 +7862,7 @@ void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlSc
RFR.RDB$IDENTITY_TYPE.NULL = TRUE; RFR.RDB$IDENTITY_TYPE.NULL = TRUE;
END_MODIFY END_MODIFY
} }
else if (clause->identityRestart || clause->identityIncrement.specified) else if (clause->identityOptions)
{ {
bool found = false; bool found = false;
AutoRequest request2; AutoRequest request2;
@ -7874,27 +7874,26 @@ void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlSc
const SLONG id = GEN.RDB$GENERATOR_ID; const SLONG id = GEN.RDB$GENERATOR_ID;
const MetaName genName(RFR.RDB$GENERATOR_NAME); const MetaName genName(RFR.RDB$GENERATOR_NAME);
if (clause->identityRestart) if (clause->identityOptions->restart)
{ {
const SINT64 val = clause->identityRestartValue.specified ? const SINT64 val = clause->identityOptions->startValue
clause->identityRestartValue.value : .orElse(!GEN.RDB$INITIAL_VALUE.NULL ? GEN.RDB$INITIAL_VALUE : 0);
(!GEN.RDB$INITIAL_VALUE.NULL ? GEN.RDB$INITIAL_VALUE : 0);
transaction->getGenIdCache()->put(id, val); transaction->getGenIdCache()->put(id, val);
} }
else if (clause->identityIncrement.specified)
if (clause->identityOptions->increment.specified)
{ {
if (clause->identityIncrement.value == 0) if (clause->identityOptions->increment.value == 0)
{ {
status_exception::raise(Arg::Gds(isc_dyn_cant_use_zero_inc_ident) << status_exception::raise(Arg::Gds(isc_dyn_cant_use_zero_inc_ident) <<
Arg::Str(field->fld_name) << Arg::Str(field->fld_name) <<
Arg::Str(name)); Arg::Str(name));
} }
MET_update_generator_increment(tdbb, id, clause->identityIncrement.value); MET_update_generator_increment(tdbb, id,
clause->identityOptions->increment.value);
} }
else
fb_assert(false);
dsc desc; dsc desc;
desc.makeText((USHORT) genName.length(), ttype_metadata, desc.makeText((USHORT) genName.length(), ttype_metadata,

View File

@ -1307,11 +1307,13 @@ public:
struct IdentityOptions struct IdentityOptions
{ {
IdentityOptions(MemoryPool&) IdentityOptions(MemoryPool&)
: restart(false)
{ {
} }
Nullable<SINT64> start; Nullable<SINT64> startValue;
Nullable<SLONG> increment; Nullable<SLONG> increment;
bool restart; // used in ALTER
}; };
struct AddColumnClause : public Clause struct AddColumnClause : public Clause
@ -1323,7 +1325,7 @@ public:
constraints(p), constraints(p),
collate(p), collate(p),
computed(NULL), computed(NULL),
identity(NULL), identityOptions(NULL),
notNullSpecified(false) notNullSpecified(false)
{ {
} }
@ -1333,7 +1335,7 @@ public:
Firebird::ObjectsArray<AddConstraintClause> constraints; Firebird::ObjectsArray<AddConstraintClause> constraints;
Firebird::MetaName collate; Firebird::MetaName collate;
NestConst<ValueSourceClause> computed; NestConst<ValueSourceClause> computed;
NestConst<IdentityOptions> identity; NestConst<IdentityOptions> identityOptions;
bool notNullSpecified; bool notNullSpecified;
}; };
@ -1384,7 +1386,7 @@ public:
defaultValue(NULL), defaultValue(NULL),
dropDefault(false), dropDefault(false),
dropIdentity(false), dropIdentity(false),
identityRestart(false), identityOptions(NULL),
computed(NULL) computed(NULL)
{ {
} }
@ -1393,9 +1395,7 @@ public:
NestConst<ValueSourceClause> defaultValue; NestConst<ValueSourceClause> defaultValue;
bool dropDefault; bool dropDefault;
bool dropIdentity; bool dropIdentity;
bool identityRestart; NestConst<IdentityOptions> identityOptions;
Nullable<SINT64> identityRestartValue;
Nullable<SINT64> identityIncrement;
NestConst<ValueSourceClause> computed; NestConst<ValueSourceClause> computed;
}; };

View File

@ -1 +1 @@
44 shift/reduce conflicts, 17 reduce/reduce conflicts. 45 shift/reduce conflicts, 17 reduce/reduce conflicts.

View File

@ -2149,7 +2149,7 @@ column_def($relationNode)
newNode<RelationNode::AddColumnClause>(); newNode<RelationNode::AddColumnClause>();
clause->field = $2; clause->field = $2;
clause->field->fld_name = *$1; clause->field->fld_name = *$1;
clause->identity = $3; clause->identityOptions = $3;
$relationNode->clauses.add(clause); $relationNode->clauses.add(clause);
} }
column_constraint_clause(NOTRIAL($<addColumnClause>4)) collate_clause column_constraint_clause(NOTRIAL($<addColumnClause>4)) collate_clause
@ -2200,7 +2200,7 @@ identity_clause_options($identityOptions)
%type identity_clause_option(<identityOptions>) %type identity_clause_option(<identityOptions>)
identity_clause_option($identityOptions) identity_clause_option($identityOptions)
: START WITH sequence_value : START WITH sequence_value
{ setClause($identityOptions->start, "START WITH", $3); } { setClause($identityOptions->startValue, "START WITH", $3); }
| INCREMENT by_noise signed_long_integer | INCREMENT by_noise signed_long_integer
{ setClause($identityOptions->increment, "INCREMENT BY", $3); } { setClause($identityOptions->increment, "INCREMENT BY", $3); }
; ;
@ -3927,23 +3927,16 @@ alter_op($relationNode)
clause->dropDefault = true; clause->dropDefault = true;
$relationNode->clauses.add(clause); $relationNode->clauses.add(clause);
} }
| col_opt symbol_column_name RESTART with_opt | col_opt symbol_column_name
{ { $<identityOptions>$ = newNode<RelationNode::IdentityOptions>(); }
RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>(); alter_identity_clause_options($<identityOptions>3)
clause->field = newNode<dsql_fld>(); {
clause->field->fld_name = *$2; RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>();
clause->identityRestart = true; clause->field = newNode<dsql_fld>();
clause->identityRestartValue = $4; clause->field->fld_name = *$2;
$relationNode->clauses.add(clause); clause->identityOptions = $<identityOptions>3;
} $relationNode->clauses.add(clause);
| col_opt symbol_column_name SET INCREMENT by_noise signed_long_integer }
{
RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>();
clause->field = newNode<dsql_fld>();
clause->field->fld_name = *$2;
clause->identityIncrement = $6;
$relationNode->clauses.add(clause);
}
| col_opt symbol_column_name DROP IDENTITY | col_opt symbol_column_name DROP IDENTITY
{ {
RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>(); RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>();
@ -4082,6 +4075,23 @@ alter_data_type_or_domain
} }
; ;
%type alter_identity_clause_options(<identityOptions>)
alter_identity_clause_options($identityOptions)
: alter_identity_clause_options alter_identity_clause_option($identityOptions)
| alter_identity_clause_option($identityOptions)
;
%type alter_identity_clause_option(<identityOptions>)
alter_identity_clause_option($identityOptions)
: RESTART with_opt
{
setClause($identityOptions->restart, "RESTART");
$identityOptions->startValue = $2;
}
| SET INCREMENT by_noise signed_long_integer
{ setClause($identityOptions->increment, "SET INCREMENT BY", $4); }
;
%type <boolVal> drop_behaviour %type <boolVal> drop_behaviour
drop_behaviour drop_behaviour
: { $$ = false; } : { $$ = false; }