]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add CYCLE support to Sequence() and docstrings for NO MINVALUE and NO MAXVALUE
authorjakeogh <github.com@v6y.net>
Sat, 27 Jun 2015 20:49:46 +0000 (20:49 +0000)
committerjakeogh <github.com@v6y.net>
Sat, 27 Jun 2015 20:49:46 +0000 (20:49 +0000)
lib/sqlalchemy/engine/interfaces.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/schema.py
test/sql/test_defaults.py

index 9a31f05ae0a95433fe2707be218b18e3aa36d2bc..3bad765dfe466be22e413fc03916200fdab2d598 100644 (file)
@@ -253,7 +253,8 @@ class Dialect(object):
         sequence
           a dictionary of the form
               {'name' : str, 'start' :int, 'increment': int, 'minvalue': int,
-               'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool}
+               'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool,
+               'cycle': bool}
 
         Additional column attributes may be present.
         """
index f7aa0210504d217285fa3651c02dc656247c67f3..d2fa1d553679dbfbe608e98dbb97010985ba06d8 100644 (file)
@@ -2304,9 +2304,11 @@ class DDLCompiler(Compiled):
         if create.element.maxvalue is not None:
             text += " MAXVALUE %d" % create.element.maxvalue
         if create.element.nominvalue is not None:
-            text += " NO MINVALUE" % create.element.nominvalue
+            text += " NO MINVALUE"
         if create.element.nomaxvalue is not None:
-            text += " NO MAXVALUE" % create.element.nomaxvalue
+            text += " NO MAXVALUE"
+        if create.element.cycle is not None:
+            text += " CYCLE"
         return text
 
     def visit_drop_sequence(self, drop):
index ccec74a35cbd1980f393a8ddfb597af93ee63477..ecfa5767630a6ac6fc26c353c5586bfd0bcf357e 100644 (file)
@@ -2041,8 +2041,9 @@ class Sequence(DefaultGenerator):
     is_sequence = True
 
     def __init__(self, name, start=None, increment=None, minvalue=None,
-                 maxvalue=None, nominvalue=None, nomaxvalue=None, schema=None,
-                 optional=False, quote=None, metadata=None, quote_schema=None,
+                 maxvalue=None, nominvalue=None, nomaxvalue=None, cycle=None,
+                 schema=None, optional=False, quote=None, metadata=None,
+                 quote_schema=None,
                  for_update=False):
         """Construct a :class:`.Sequence` object.
 
@@ -2069,6 +2070,26 @@ class Sequence(DefaultGenerator):
          the clause is omitted, which on most platforms indicates a
          maxvalue of 2^63-1 and -1 for ascending and descending sequences,
          respectively.
+        :param nominvalue: no minimum value of the sequence.  This
+         value is used when the CREATE SEQUENCE command is emitted to
+         the database as the value of the "NO MINVALUE" clause.  If ``None``,
+         the clause is omitted, which on most platforms indicates a
+         minvalue of 1 and -2^63-1 for ascending and descending sequences,
+         respectively.
+        :param nomaxvalue: no maximum value of the sequence.  This
+         value is used when the CREATE SEQUENCE command is emitted to
+         the database as the value of the "NO MAXVALUE" clause.  If ``None``,
+         the clause is omitted, which on most platforms indicates a
+         maxvalue of 2^63-1 and -1 for ascending and descending sequences,
+         respectively.
+        :param cycle: allows the sequence to wrap around when the maxvalue
+         or minvalue has been reached by an ascending or descending sequence
+         respectively.  This value is used when the CREATE SEQUENCE command
+         is emitted to the database as the "CYCLE" clause.  If the limit is
+         reached, the next number generated will be the minvalue or maxvalue,
+         respectively.  If cycle=False (the default) any calls to nextval
+         after the sequence has reached its maximum value will return an
+         error.
         :param schema: Optional schema name for the sequence, if located
          in a schema other than the default.
         :param optional: boolean value, when ``True``, indicates that this
@@ -2114,6 +2135,10 @@ class Sequence(DefaultGenerator):
         self.start = start
         self.increment = increment
         self.minvalue = minvalue
+        self.maxvalue = maxvalue
+        self.nominvalue = nominvalue
+        self.nomaxvalue = nomaxvalue
+        self.cycle = cycle
         self.optional = optional
         if metadata is not None and schema is None and metadata.schema:
             self.schema = schema = metadata.schema
index 53eb6c500132176fd18c0e4d7d9f82c27ffbefff..da91ed212a2f2f4f38e06407c3223e5916ac183a 100644 (file)
@@ -816,6 +816,12 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
             "CREATE SEQUENCE foo_seq INCREMENT BY 2 START WITH 0 NO MINVALUE",
         )
 
+        self.assert_compile(
+            CreateSequence(Sequence(
+                            'foo_seq', start=1, maxvalue=10, cycle=True)),
+            "CREATE SEQUENCE foo_seq START WITH 1 MAXVALUE 10 CYCLE",
+        )
+
         self.assert_compile(
             DropSequence(Sequence('foo_seq')),
             "DROP SEQUENCE foo_seq",