mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 17:23:03 +01:00
Allow to set more than one ALTER identity option in the same command - CORE-5430.
This commit is contained in:
parent
74bfb8f90f
commit
efc155f4b3
@ -18,10 +18,13 @@ Syntax:
|
||||
INCREMENT [ BY ] <value>
|
||||
|
||||
<alter column definition> ::=
|
||||
<name> RESTART [ WITH <value> ] |
|
||||
<name> SET INCREMENT [ BY ] <value> |
|
||||
<name> <alter identity column option>... |
|
||||
<name> DROP IDENTITY
|
||||
|
||||
<alter identity column option> ::=
|
||||
RESTART [ WITH <value> ] |
|
||||
SET INCREMENT [ BY ] <value>
|
||||
|
||||
Syntax rules:
|
||||
- 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).
|
||||
|
@ -6214,7 +6214,7 @@ void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
|
||||
ObjectsArray<CreateDropConstraint> constraints;
|
||||
bool notNullFlag = false;
|
||||
|
||||
if (clause->identity)
|
||||
if (clause->identityOptions)
|
||||
notNullFlag = true; // identity columns are implicitly not null
|
||||
|
||||
for (ObjectsArray<AddConstraintClause>::iterator ptr = clause->constraints.begin();
|
||||
@ -6277,9 +6277,9 @@ void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
|
||||
if (clause->collate.hasData())
|
||||
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) <<
|
||||
Arg::Str(field->fld_name) <<
|
||||
@ -6299,8 +6299,8 @@ void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
|
||||
|
||||
CreateAlterSequenceNode::store(tdbb, transaction, fieldDefinition.identitySequence,
|
||||
fb_sysflag_identity_generator,
|
||||
clause->identity->start.orElse(0),
|
||||
clause->identity->increment.orElse(1));
|
||||
clause->identityOptions->startValue.orElse(0),
|
||||
clause->identityOptions->increment.orElse(1));
|
||||
}
|
||||
|
||||
BlrDebugWriter::BlrData defaultValue;
|
||||
@ -7862,7 +7862,7 @@ void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlSc
|
||||
RFR.RDB$IDENTITY_TYPE.NULL = TRUE;
|
||||
END_MODIFY
|
||||
}
|
||||
else if (clause->identityRestart || clause->identityIncrement.specified)
|
||||
else if (clause->identityOptions)
|
||||
{
|
||||
bool found = false;
|
||||
AutoRequest request2;
|
||||
@ -7874,27 +7874,26 @@ void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlSc
|
||||
const SLONG id = GEN.RDB$GENERATOR_ID;
|
||||
const MetaName genName(RFR.RDB$GENERATOR_NAME);
|
||||
|
||||
if (clause->identityRestart)
|
||||
if (clause->identityOptions->restart)
|
||||
{
|
||||
const SINT64 val = clause->identityRestartValue.specified ?
|
||||
clause->identityRestartValue.value :
|
||||
(!GEN.RDB$INITIAL_VALUE.NULL ? GEN.RDB$INITIAL_VALUE : 0);
|
||||
const SINT64 val = clause->identityOptions->startValue
|
||||
.orElse(!GEN.RDB$INITIAL_VALUE.NULL ? GEN.RDB$INITIAL_VALUE : 0);
|
||||
|
||||
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) <<
|
||||
Arg::Str(field->fld_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;
|
||||
desc.makeText((USHORT) genName.length(), ttype_metadata,
|
||||
|
@ -1307,11 +1307,13 @@ public:
|
||||
struct IdentityOptions
|
||||
{
|
||||
IdentityOptions(MemoryPool&)
|
||||
: restart(false)
|
||||
{
|
||||
}
|
||||
|
||||
Nullable<SINT64> start;
|
||||
Nullable<SINT64> startValue;
|
||||
Nullable<SLONG> increment;
|
||||
bool restart; // used in ALTER
|
||||
};
|
||||
|
||||
struct AddColumnClause : public Clause
|
||||
@ -1323,7 +1325,7 @@ public:
|
||||
constraints(p),
|
||||
collate(p),
|
||||
computed(NULL),
|
||||
identity(NULL),
|
||||
identityOptions(NULL),
|
||||
notNullSpecified(false)
|
||||
{
|
||||
}
|
||||
@ -1333,7 +1335,7 @@ public:
|
||||
Firebird::ObjectsArray<AddConstraintClause> constraints;
|
||||
Firebird::MetaName collate;
|
||||
NestConst<ValueSourceClause> computed;
|
||||
NestConst<IdentityOptions> identity;
|
||||
NestConst<IdentityOptions> identityOptions;
|
||||
bool notNullSpecified;
|
||||
};
|
||||
|
||||
@ -1384,7 +1386,7 @@ public:
|
||||
defaultValue(NULL),
|
||||
dropDefault(false),
|
||||
dropIdentity(false),
|
||||
identityRestart(false),
|
||||
identityOptions(NULL),
|
||||
computed(NULL)
|
||||
{
|
||||
}
|
||||
@ -1393,9 +1395,7 @@ public:
|
||||
NestConst<ValueSourceClause> defaultValue;
|
||||
bool dropDefault;
|
||||
bool dropIdentity;
|
||||
bool identityRestart;
|
||||
Nullable<SINT64> identityRestartValue;
|
||||
Nullable<SINT64> identityIncrement;
|
||||
NestConst<IdentityOptions> identityOptions;
|
||||
NestConst<ValueSourceClause> computed;
|
||||
};
|
||||
|
||||
|
@ -1 +1 @@
|
||||
44 shift/reduce conflicts, 17 reduce/reduce conflicts.
|
||||
45 shift/reduce conflicts, 17 reduce/reduce conflicts.
|
||||
|
@ -2149,7 +2149,7 @@ column_def($relationNode)
|
||||
newNode<RelationNode::AddColumnClause>();
|
||||
clause->field = $2;
|
||||
clause->field->fld_name = *$1;
|
||||
clause->identity = $3;
|
||||
clause->identityOptions = $3;
|
||||
$relationNode->clauses.add(clause);
|
||||
}
|
||||
column_constraint_clause(NOTRIAL($<addColumnClause>4)) collate_clause
|
||||
@ -2200,7 +2200,7 @@ identity_clause_options($identityOptions)
|
||||
%type identity_clause_option(<identityOptions>)
|
||||
identity_clause_option($identityOptions)
|
||||
: START WITH sequence_value
|
||||
{ setClause($identityOptions->start, "START WITH", $3); }
|
||||
{ setClause($identityOptions->startValue, "START WITH", $3); }
|
||||
| INCREMENT by_noise signed_long_integer
|
||||
{ setClause($identityOptions->increment, "INCREMENT BY", $3); }
|
||||
;
|
||||
@ -3927,23 +3927,16 @@ alter_op($relationNode)
|
||||
clause->dropDefault = true;
|
||||
$relationNode->clauses.add(clause);
|
||||
}
|
||||
| col_opt symbol_column_name RESTART with_opt
|
||||
{
|
||||
RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>();
|
||||
clause->field = newNode<dsql_fld>();
|
||||
clause->field->fld_name = *$2;
|
||||
clause->identityRestart = true;
|
||||
clause->identityRestartValue = $4;
|
||||
$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
|
||||
{ $<identityOptions>$ = newNode<RelationNode::IdentityOptions>(); }
|
||||
alter_identity_clause_options($<identityOptions>3)
|
||||
{
|
||||
RelationNode::AlterColTypeClause* clause = newNode<RelationNode::AlterColTypeClause>();
|
||||
clause->field = newNode<dsql_fld>();
|
||||
clause->field->fld_name = *$2;
|
||||
clause->identityOptions = $<identityOptions>3;
|
||||
$relationNode->clauses.add(clause);
|
||||
}
|
||||
| col_opt symbol_column_name DROP IDENTITY
|
||||
{
|
||||
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
|
||||
drop_behaviour
|
||||
: { $$ = false; }
|
||||
|
Loading…
Reference in New Issue
Block a user