diff --git a/src/common/classes/Nullable.h b/src/common/classes/Nullable.h index a83798cf5d..46fe099c8e 100644 --- a/src/common/classes/Nullable.h +++ b/src/common/classes/Nullable.h @@ -39,28 +39,6 @@ public: } }; -// NullableClear specializations. - -template <> -class NullableClear // string especialization for NullableClear -{ -public: - static void clear(Firebird::string& v) - { - v = ""; - } -}; - -template <> -class NullableClear // MetaName especialization for NullableClear -{ -public: - static void clear(Firebird::MetaName& v) - { - v = ""; - } -}; - // Nullable support without constructor, to allow usage in unions (used in the parser). template class BaseNullable @@ -93,6 +71,39 @@ public: }; +// NullableClear specializations. + +template <> +class NullableClear // string especialization for NullableClear +{ +public: + static void clear(Firebird::string& v) + { + v = ""; + } +}; + +template <> +class NullableClear // MetaName especialization for NullableClear +{ +public: + static void clear(Firebird::MetaName& v) + { + v = ""; + } +}; + +template +class NullableClear > +{ +public: + static void clear(BaseNullable& v) + { + v.specified = false; + } +}; + + // Actual Nullable template. template class Nullable : public BaseNullable { diff --git a/src/dsql/DdlNodes.epp b/src/dsql/DdlNodes.epp index 8dd8aa8432..fe4dfbce3d 100644 --- a/src/dsql/DdlNodes.epp +++ b/src/dsql/DdlNodes.epp @@ -4941,7 +4941,7 @@ bool CreateAlterSequenceNode::executeAlter(thread_db* tdbb, DsqlCompilerScratch* executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE, DDL_TRIGGER_ALTER_SEQUENCE, name); - fb_assert(value.specified); + fb_assert(restartSpecified && value.specified); const SINT64 val = value.specified ? value.value : 0; if (step.specified) { @@ -4981,8 +4981,7 @@ bool CreateAlterSequenceNode::executeAlter(thread_db* tdbb, DsqlCompilerScratch* } const SLONG id = X.RDB$GENERATOR_ID; - const SINT64 val = value.specified ? - value.value : (!X.RDB$INITIAL_VALUE.NULL ? X.RDB$INITIAL_VALUE : 0); + if (step.specified) { const SLONG newStep = step.value; @@ -4997,7 +4996,13 @@ bool CreateAlterSequenceNode::executeAlter(thread_db* tdbb, DsqlCompilerScratch* } } - transaction->getGenIdCache()->put(id, val); + if (restartSpecified) + { + const SINT64 val = value.specified ? + value.value : (!X.RDB$INITIAL_VALUE.NULL ? X.RDB$INITIAL_VALUE : 0); + transaction->getGenIdCache()->put(id, val); + } + dsc desc; desc.makeText((USHORT) name.length(), ttype_metadata, (UCHAR*) name.c_str()); DFW_post_work(transaction, dfw_set_generator, &desc, id); diff --git a/src/dsql/DdlNodes.h b/src/dsql/DdlNodes.h index 60b8bea952..5553200c95 100644 --- a/src/dsql/DdlNodes.h +++ b/src/dsql/DdlNodes.h @@ -916,6 +916,7 @@ public: create(true), alter(false), legacy(false), + restartSpecified(false), name(pool, aName), value(aValue), step(aStep) @@ -959,6 +960,7 @@ public: bool create; bool alter; bool legacy; + bool restartSpecified; const Firebird::MetaName name; const BaseNullable value; const BaseNullable step; diff --git a/src/dsql/parse.y b/src/dsql/parse.y index ad62dad7d5..b5baff0ed5 100644 --- a/src/dsql/parse.y +++ b/src/dsql/parse.y @@ -607,6 +607,7 @@ using namespace Firebird; SINT64 int64Val; FB_UINT64 uint64Val; BaseNullable nullableInt64Val; + BaseNullable > nullableNullableInt64Val; BaseNullable nullableUint64Val; Jrd::ScaledNumber scaledNumber; UCHAR blrOp; @@ -1508,6 +1509,7 @@ replace_sequence_clause { CreateAlterSequenceNode* node = newNode(*$1, $2, $3); node->alter = true; + node->restartSpecified = true; $$ = node; } ; @@ -1524,9 +1526,10 @@ alter_sequence_clause { if (!$2.specified && !$3.specified) yyerrorIncompleteCmd(); - CreateAlterSequenceNode* node = newNode(*$1, $2, $3); + CreateAlterSequenceNode* node = newNode(*$1, $2.value, $3); node->create = false; node->alter = true; + node->restartSpecified = $2.specified; $$ = node; } ; @@ -1537,10 +1540,10 @@ restart_value_opt | RESTART WITH sequence_value { $$ = Nullable::val($3); } ; -%type restart_value_opt2 +%type restart_value_opt2 restart_value_opt2 - : /* nothing */ { $$ = Nullable::empty(); } - | restart_value_opt + : /* nothing */ { $$ = Nullable >::empty(); } + | restart_value_opt { $$ = Nullable > ::val($1); } ; @@ -1553,6 +1556,7 @@ set_generator_clause node->create = false; node->alter = true; node->legacy = true; + node->restartSpecified = true; $$ = node; } ;