mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 00:03:02 +01:00
Improvement CORE-4199 - Add optional START WITH clause to identity columns.
This commit is contained in:
parent
4097497416
commit
4789ba1672
@ -11,7 +11,7 @@ Description:
|
|||||||
|
|
||||||
Syntax:
|
Syntax:
|
||||||
<column definition> ::=
|
<column definition> ::=
|
||||||
<name> <type> GENERATED BY DEFAULT AS IDENTITY <constraints>
|
<name> <type> GENERATED BY DEFAULT AS IDENTITY [ (START WITH <value>) ] <constraints>
|
||||||
|
|
||||||
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:
|
||||||
|
@ -4890,13 +4890,7 @@ void CreateAlterSequenceNode::executeCreate(thread_db* tdbb, DsqlCompilerScratch
|
|||||||
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE, DDL_TRIGGER_CREATE_SEQUENCE, name);
|
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE, DDL_TRIGGER_CREATE_SEQUENCE, name);
|
||||||
|
|
||||||
const SINT64 val = value.specified ? value.value : 0;
|
const SINT64 val = value.specified ? value.value : 0;
|
||||||
|
store(tdbb, transaction, name, fb_sysflag_user, val);
|
||||||
const SSHORT id = store(tdbb, transaction, name, fb_sysflag_user, val);
|
|
||||||
fb_assert(id > 0);
|
|
||||||
|
|
||||||
// the store() call above has caused the DFW item to be posted,
|
|
||||||
// so we just adjust the cached generator value
|
|
||||||
transaction->getGenIdCache()->put(id, val);
|
|
||||||
|
|
||||||
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_AFTER, DDL_TRIGGER_CREATE_SEQUENCE, name);
|
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_AFTER, DDL_TRIGGER_CREATE_SEQUENCE, name);
|
||||||
}
|
}
|
||||||
@ -5012,6 +5006,10 @@ SSHORT CreateAlterSequenceNode::store(thread_db* tdbb, jrd_tra* transaction, con
|
|||||||
|
|
||||||
storePrivileges(tdbb, transaction, name, obj_generator, USAGE_PRIVILEGES);
|
storePrivileges(tdbb, transaction, name, obj_generator, USAGE_PRIVILEGES);
|
||||||
|
|
||||||
|
// The STORE above has caused the DFW item to be posted, so we just adjust the cached
|
||||||
|
// generator value.
|
||||||
|
transaction->getGenIdCache()->put(storedId, val);
|
||||||
|
|
||||||
return storedId;
|
return storedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5546,7 +5544,7 @@ void RelationNode::defineField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
|
|||||||
DYN_UTIL_generate_generator_name(tdbb, fieldDefinition.identitySequence);
|
DYN_UTIL_generate_generator_name(tdbb, fieldDefinition.identitySequence);
|
||||||
|
|
||||||
CreateAlterSequenceNode::store(tdbb, transaction, fieldDefinition.identitySequence,
|
CreateAlterSequenceNode::store(tdbb, transaction, fieldDefinition.identitySequence,
|
||||||
fb_sysflag_identity_generator, 0);
|
fb_sysflag_identity_generator, clause->identityStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlrDebugWriter::BlrData defaultValue;
|
BlrDebugWriter::BlrData defaultValue;
|
||||||
|
@ -1168,7 +1168,8 @@ public:
|
|||||||
constraints(p),
|
constraints(p),
|
||||||
collate(p),
|
collate(p),
|
||||||
computed(NULL),
|
computed(NULL),
|
||||||
identity(false)
|
identity(false),
|
||||||
|
identityStart(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1178,6 +1179,7 @@ public:
|
|||||||
Firebird::MetaName collate;
|
Firebird::MetaName collate;
|
||||||
NestConst<ValueSourceClause> computed;
|
NestConst<ValueSourceClause> computed;
|
||||||
bool identity;
|
bool identity;
|
||||||
|
SINT64 identityStart;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AlterColNameClause : public Clause
|
struct AlterColNameClause : public Clause
|
||||||
|
@ -1467,7 +1467,12 @@ generator_clause
|
|||||||
%type <nullableInt64Val> start_with_opt
|
%type <nullableInt64Val> start_with_opt
|
||||||
start_with_opt
|
start_with_opt
|
||||||
: /* nothing */ { $$ = Nullable<SINT64>::empty(); }
|
: /* nothing */ { $$ = Nullable<SINT64>::empty(); }
|
||||||
| START WITH sequence_value { $$ = Nullable<SINT64>::val($3); }
|
| start_with { $$ = Nullable<SINT64>::val($1); }
|
||||||
|
;
|
||||||
|
|
||||||
|
%type <int64Val> start_with
|
||||||
|
start_with
|
||||||
|
: START WITH sequence_value { $$ = $3; }
|
||||||
;
|
;
|
||||||
|
|
||||||
%type <createAlterSequenceNode> replace_sequence_clause
|
%type <createAlterSequenceNode> replace_sequence_clause
|
||||||
@ -1805,6 +1810,7 @@ column_def($relationNode)
|
|||||||
clause->field = $2;
|
clause->field = $2;
|
||||||
clause->field->fld_name = *$1;
|
clause->field->fld_name = *$1;
|
||||||
clause->identity = true;
|
clause->identity = true;
|
||||||
|
clause->identityStart = $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
|
||||||
@ -1832,8 +1838,15 @@ column_def($relationNode)
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
%type <int64Val> identity_clause
|
||||||
identity_clause
|
identity_clause
|
||||||
: GENERATED BY DEFAULT AS IDENTITY
|
: GENERATED BY DEFAULT AS IDENTITY identity_clause_options { $$ = $6; }
|
||||||
|
;
|
||||||
|
|
||||||
|
%type <int64Val> identity_clause_options
|
||||||
|
identity_clause_options
|
||||||
|
: /* nothing */ { $$ = 0; }
|
||||||
|
| '(' start_with ')' { $$ = $2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
// value does allow parens around it, but there is a problem getting the source text.
|
// value does allow parens around it, but there is a problem getting the source text.
|
||||||
|
@ -510,12 +510,17 @@ int EXTRACT_list_table(const SCHAR* relation_name,
|
|||||||
|
|
||||||
if (ENCODE_ODS(isqlGlob.major_ods, isqlGlob.minor_ods) >= ODS_12_0)
|
if (ENCODE_ODS(isqlGlob.major_ods, isqlGlob.minor_ods) >= ODS_12_0)
|
||||||
{
|
{
|
||||||
FOR RFR2 IN RDB$RELATION_FIELDS
|
FOR RFR2 IN RDB$RELATION_FIELDS CROSS
|
||||||
WITH RFR2.RDB$RELATION_NAME = RFR.RDB$RELATION_NAME AND
|
GEN IN RDB$GENERATORS
|
||||||
|
WITH GEN.RDB$GENERATOR_NAME = RFR2.RDB$GENERATOR_NAME AND
|
||||||
|
RFR2.RDB$RELATION_NAME = RFR.RDB$RELATION_NAME AND
|
||||||
RFR2.RDB$FIELD_NAME = RFR.RDB$FIELD_NAME
|
RFR2.RDB$FIELD_NAME = RFR.RDB$FIELD_NAME
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!RFR2.RDB$GENERATOR_NAME.NULL)
|
|
||||||
isqlGlob.printf(" GENERATED BY DEFAULT AS IDENTITY");
|
isqlGlob.printf(" GENERATED BY DEFAULT AS IDENTITY");
|
||||||
|
|
||||||
|
if (!GEN.RDB$INITIAL_VALUE.NULL && GEN.RDB$INITIAL_VALUE != 0)
|
||||||
|
isqlGlob.printf(" (START WITH %" SQUADFORMAT ")", GEN.RDB$INITIAL_VALUE);
|
||||||
}
|
}
|
||||||
END_FOR
|
END_FOR
|
||||||
ON_ERROR
|
ON_ERROR
|
||||||
|
Loading…
Reference in New Issue
Block a user