| 
      
      
      From: <asf...@us...> - 2013-09-04 15:54:22
      
     | 
| Revision: 58569
          http://sourceforge.net/p/firebird/code/58569
Author:   asfernandes
Date:     2013-09-04 15:54:19 +0000 (Wed, 04 Sep 2013)
Log Message:
-----------
Improvement CORE-4199 - Add optional START WITH clause to identity columns.
Modified Paths:
--------------
    firebird/trunk/doc/sql.extensions/README.identity_columns.txt
    firebird/trunk/src/dsql/DdlNodes.epp
    firebird/trunk/src/dsql/DdlNodes.h
    firebird/trunk/src/dsql/parse.y
    firebird/trunk/src/isql/extract.epp
Modified: firebird/trunk/doc/sql.extensions/README.identity_columns.txt
===================================================================
--- firebird/trunk/doc/sql.extensions/README.identity_columns.txt	2013-09-04 15:39:30 UTC (rev 58568)
+++ firebird/trunk/doc/sql.extensions/README.identity_columns.txt	2013-09-04 15:54:19 UTC (rev 58569)
@@ -11,7 +11,7 @@
 
 Syntax:
     <column definition> ::=
-        <name> <type> GENERATED BY DEFAULT AS IDENTITY <constraints>
+        <name> <type> GENERATED BY DEFAULT AS IDENTITY [ (START WITH <value>) ] <constraints>
 
 Syntax rules:
     - The type of an identity column must be an exact number type with zero scale. That includes:
Modified: firebird/trunk/src/dsql/DdlNodes.epp
===================================================================
--- firebird/trunk/src/dsql/DdlNodes.epp	2013-09-04 15:39:30 UTC (rev 58568)
+++ firebird/trunk/src/dsql/DdlNodes.epp	2013-09-04 15:54:19 UTC (rev 58569)
@@ -4890,14 +4890,8 @@
 	executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE, DDL_TRIGGER_CREATE_SEQUENCE, name);
 
 	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);
 }
 
@@ -5012,6 +5006,10 @@
 
 	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;
 }
 
@@ -5546,7 +5544,7 @@
 			DYN_UTIL_generate_generator_name(tdbb, fieldDefinition.identitySequence);
 
 			CreateAlterSequenceNode::store(tdbb, transaction, fieldDefinition.identitySequence,
-				fb_sysflag_identity_generator, 0);
+				fb_sysflag_identity_generator, clause->identityStart);
 		}
 
 		BlrDebugWriter::BlrData defaultValue;
Modified: firebird/trunk/src/dsql/DdlNodes.h
===================================================================
--- firebird/trunk/src/dsql/DdlNodes.h	2013-09-04 15:39:30 UTC (rev 58568)
+++ firebird/trunk/src/dsql/DdlNodes.h	2013-09-04 15:54:19 UTC (rev 58569)
@@ -1168,7 +1168,8 @@
 			  constraints(p),
 			  collate(p),
 			  computed(NULL),
-			  identity(false)
+			  identity(false),
+			  identityStart(0)
 		{
 		}
 
@@ -1178,6 +1179,7 @@
 		Firebird::MetaName collate;
 		NestConst<ValueSourceClause> computed;
 		bool identity;
+		SINT64 identityStart;
 	};
 
 	struct AlterColNameClause : public Clause
Modified: firebird/trunk/src/dsql/parse.y
===================================================================
--- firebird/trunk/src/dsql/parse.y	2013-09-04 15:39:30 UTC (rev 58568)
+++ firebird/trunk/src/dsql/parse.y	2013-09-04 15:54:19 UTC (rev 58569)
@@ -1466,10 +1466,15 @@
 
 %type <nullableInt64Val> start_with_opt
 start_with_opt
-	: /* nothing */					{ $$ = Nullable<SINT64>::empty(); }
-	| START WITH sequence_value		{ $$ = Nullable<SINT64>::val($3); }
+	: /* nothing */		{ $$ = Nullable<SINT64>::empty(); }
+	| start_with		{ $$ = Nullable<SINT64>::val($1); }
 	;
 
+%type <int64Val> start_with
+start_with
+	: START WITH sequence_value		{ $$ = $3; }
+	;
+
 %type <createAlterSequenceNode> replace_sequence_clause
 replace_sequence_clause
 	: symbol_generator_name replace_sequence_options
@@ -1805,6 +1810,7 @@
 				clause->field = $2;
 				clause->field->fld_name = *$1;
 				clause->identity = true;
+				clause->identityStart = $3;
 				$relationNode->clauses.add(clause);
 			}
 		column_constraint_clause(NOTRIAL($<addColumnClause>4)) collate_clause
@@ -1832,10 +1838,17 @@
 		}
 	;
 
+%type <int64Val> 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.
 
 %type <valueSourceClause> def_computed
Modified: firebird/trunk/src/isql/extract.epp
===================================================================
--- firebird/trunk/src/isql/extract.epp	2013-09-04 15:39:30 UTC (rev 58568)
+++ firebird/trunk/src/isql/extract.epp	2013-09-04 15:54:19 UTC (rev 58569)
@@ -510,12 +510,17 @@
 
 		if (ENCODE_ODS(isqlGlob.major_ods, isqlGlob.minor_ods) >= ODS_12_0)
 		{
-			FOR RFR2 IN RDB$RELATION_FIELDS
-				WITH RFR2.RDB$RELATION_NAME = RFR.RDB$RELATION_NAME AND
+			FOR RFR2 IN RDB$RELATION_FIELDS CROSS
+				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
+					 
 			{
-				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
 			ON_ERROR
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |