]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add support for CACHE and ORDER to sequences
authorDavid Moore <davidm@j5int.com>
Wed, 5 Jul 2017 19:06:49 +0000 (15:06 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Jul 2017 20:23:13 +0000 (16:23 -0400)
Added new keywords :paramref:`.Sequence.cache` and
:paramref:`.Sequence.order` to :class:`.Sequence`, to allow rendering
of the CACHE parameter understood by Oracle and PostgreSQL, and the
ORDER parameter understood by Oracle.  Pull request
courtesy David Moore.

Change-Id: I082c3f8ef56ef89dbaad5da9d5695be5313b0614
Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/96
(cherry picked from commit faa6609dac2ce6e55e0f690df3ba88c13133ec5c)

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/engine/interfaces.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/schema.py
test/sql/test_defaults.py

index 1f2dfd9d20c34c6a6ad19a8a010ce3638476a612..14606f86cfc70e9755be51d3c0e45f6eeac8d706 100644 (file)
 .. changelog::
     :version: 1.1.12
 
+    .. change:: cache_order_sequence
+        :tags: feature, oracle, posgresql
+        :versions: 1.2.0b1
+
+        Added new keywords :paramref:`.Sequence.cache` and
+        :paramref:`.Sequence.order` to :class:`.Sequence`, to allow rendering
+        of the CACHE parameter understood by Oracle and PostgreSQL, and the
+        ORDER parameter understood by Oracle.  Pull request
+        courtesy David Moore.
+
 .. changelog::
     :version: 1.1.11
     :released: Monday, June 19, 2017
index d0eff1cb1bda4b9d68f8527513d896cef1c4a3da..afa3c0fe29b0718615be3a9ccb7ad9e162e7d763 100644 (file)
@@ -254,7 +254,7 @@ class Dialect(object):
           a dictionary of the form
               {'name' : str, 'start' :int, 'increment': int, 'minvalue': int,
                'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool,
-               'cycle': bool}
+               'cycle': bool, 'cache': int, 'order': bool}
 
         Additional column attributes may be present.
         """
index bfa22c206406bff20343407c2d95f2e7532a9047..6768c062e5edd2a4add3e82de58e967c4300da99 100644 (file)
@@ -2483,6 +2483,10 @@ class DDLCompiler(Compiled):
             text += " NO MINVALUE"
         if create.element.nomaxvalue is not None:
             text += " NO MAXVALUE"
+        if create.element.cache is not None:
+            text += " CACHE %d" % create.element.cache
+        if create.element.order is True:
+            text += " ORDER"
         if create.element.cycle is not None:
             text += " CYCLE"
         return text
index 078487becfdf1b7146652b82a5d20bcf5af9d915..592dc390d310947dec8b1f55b5751b691e376a34 100644 (file)
@@ -2120,8 +2120,8 @@ class Sequence(DefaultGenerator):
 
     def __init__(self, name, start=None, increment=None, minvalue=None,
                  maxvalue=None, nominvalue=None, nomaxvalue=None, cycle=None,
-                 schema=None, optional=False, quote=None, metadata=None,
-                 quote_schema=None,
+                 schema=None, cache=None, order=None, optional=False,
+                 quote=None, metadata=None, quote_schema=None,
                  for_update=False):
         """Construct a :class:`.Sequence` object.
 
@@ -2188,6 +2188,19 @@ class Sequence(DefaultGenerator):
          schema name when a :class:`.MetaData` is also present are the same
          as that of :paramref:`.Table.schema`.
 
+        :param cache: optional integer value; number of future values in the
+         sequence which are calculated in advance.  Renders the CACHE keyword
+         understood by Oracle and PostgreSQL.
+
+         .. versionadded:: 1.1.12
+
+        :param order: optional boolean value; if true, renders the
+         ORDER keyword, understood by Oracle, indicating the sequence is
+         definitively ordered.   May be necessary to provide deterministic
+         ordering using Oracle RAC.
+
+         .. versionadded:: 1.1.12
+
         :param optional: boolean value, when ``True``, indicates that this
          :class:`.Sequence` object only needs to be explicitly generated
          on backends that don't provide another way to generate primary
@@ -2243,6 +2256,8 @@ class Sequence(DefaultGenerator):
         self.nominvalue = nominvalue
         self.nomaxvalue = nomaxvalue
         self.cycle = cycle
+        self.cache = cache
+        self.order = order
         self.optional = optional
         if schema is BLANK_SCHEMA:
             self.schema = schema = None
index dff423bf9fb0ea4e48b3411d59adfc85c67a87ba..0fe7658c70aead1ad838bc9f9e79e807c9340485 100644 (file)
@@ -949,6 +949,18 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
             "CREATE SEQUENCE foo_seq START WITH 1 MAXVALUE 10 CYCLE",
         )
 
+        self.assert_compile(
+            CreateSequence(Sequence(
+                            'foo_seq', cache=1000, order=True)),
+            "CREATE SEQUENCE foo_seq CACHE 1000 ORDER",
+        )
+
+        self.assert_compile(
+            CreateSequence(Sequence(
+                            'foo_seq', order=True)),
+            "CREATE SEQUENCE foo_seq ORDER",
+        )
+
         self.assert_compile(
             DropSequence(Sequence('foo_seq')),
             "DROP SEQUENCE foo_seq",