]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Properly render ``cycle=False`` and ``order=False``
authorFederico Caselli <cfederico87@gmail.com>
Tue, 1 Dec 2020 22:47:13 +0000 (23:47 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Tue, 1 Dec 2020 22:49:17 +0000 (23:49 +0100)
These get rendered as ``NO CYCLE`` and ``NO ORDER`` in
:class:`_sql.Sequence` and :class:`_sql.Identity` objects.

Fixes: #5738
Change-Id: Ia9ccb5481a104cb32d3b517e99efd5e730c84946

doc/build/changelog/unreleased_14/5738.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/sql/compiler.py
test/dialect/oracle/test_compiler.py
test/sql/test_identity_column.py

diff --git a/doc/build/changelog/unreleased_14/5738.rst b/doc/build/changelog/unreleased_14/5738.rst
new file mode 100644 (file)
index 0000000..653a621
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, sql
+    :tickets: 5722
+    :versions: 1.4.0b2
+
+    Properly render ``cycle=False`` and ``order=False`` as ``NO CYCLE`` and
+    ``NO ORDER`` in :class:`_sql.Sequence` and :class:`_sql.Identity`
+    objects.
\ No newline at end of file
index c0f7aa5ce06adfb24ef2da55e7bded715bb541da..223c1db98d183de5bc4c28921490ad7f17a89da5 100644 (file)
@@ -1329,9 +1329,11 @@ class OracleDDLCompiler(compiler.DDLCompiler):
         text = super(OracleDDLCompiler, self).get_identity_options(
             identity_options
         )
-        return text.replace("NO MINVALUE", "NOMINVALUE").replace(
-            "NO MAXVALUE", "NOMAXVALUE"
-        )
+        text = text.replace("NO MINVALUE", "NOMINVALUE")
+        text = text.replace("NO MAXVALUE", "NOMAXVALUE")
+        text = text.replace("NO CYCLE", "NOCYCLE")
+        text = text.replace("NO ORDER", "NOORDER")
+        return text
 
     def visit_computed_column(self, generated):
         text = "GENERATED ALWAYS AS (%s)" % self.sql_compiler.process(
index 9b90bf86848661fed9a74c9558f885a89b1cdede..d53fe01c2ee234d0a74b32006a959b0c4bd6fd00 100644 (file)
@@ -4050,10 +4050,10 @@ class DDLCompiler(Compiled):
             text.append("NO MAXVALUE")
         if identity_options.cache is not None:
             text.append("CACHE %d" % identity_options.cache)
-        if identity_options.order is True:
-            text.append("ORDER")
+        if identity_options.order is not None:
+            text.append("ORDER" if identity_options.order else "NO ORDER")
         if identity_options.cycle is not None:
-            text.append("CYCLE")
+            text.append("CYCLE" if identity_options.cycle else "NO CYCLE")
         return " ".join(text)
 
     def visit_create_sequence(self, create, prefix=None, **kw):
index 20c579f64ec4798cd3e2814b2d3712f6ba9d43de..1b8b3fb89b76f929b5cdac4b2cc3d58ea25a81e4 100644 (file)
@@ -1286,13 +1286,16 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
                     increment=7,
                     nominvalue=True,
                     nomaxvalue=True,
+                    cycle=False,
+                    order=False,
                 ),
             ),
         )
         self.assert_compile(
             schema.CreateTable(t),
             "CREATE TABLE t (y INTEGER GENERATED ALWAYS AS IDENTITY "
-            "(INCREMENT BY 7 START WITH 4 NOMINVALUE NOMAXVALUE))",
+            "(INCREMENT BY 7 START WITH 4 NOMINVALUE NOMAXVALUE "
+            "NOORDER NOCYCLE))",
         )
 
     def test_column_identity_no_generated(self):
index f99054d629c95cc509a32d22f0931ac921b5c917..3ac97db92feeb141fefe900a799fef9e06875930 100644 (file)
@@ -55,16 +55,21 @@ class _IdentityDDLFixture(testing.AssertsCompiledSQL):
             dict(always=False, cache=1000, order=True),
             "BY DEFAULT AS IDENTITY (CACHE 1000 ORDER)",
         ),
-        (dict(order=True), "BY DEFAULT AS IDENTITY (ORDER)"),
+        (dict(order=True, cycle=True), "BY DEFAULT AS IDENTITY (ORDER CYCLE)"),
+        (
+            dict(order=False, cycle=False),
+            "BY DEFAULT AS IDENTITY (NO ORDER NO CYCLE)",
+        ),
     )
     def test_create_ddl(self, identity_args, text):
 
         if getattr(self, "__dialect__", None) != "default" and testing.against(
             "oracle"
         ):
-            text = text.replace("NO MINVALUE", "NOMINVALUE").replace(
-                "NO MAXVALUE", "NOMAXVALUE"
-            )
+            text = text.replace("NO MINVALUE", "NOMINVALUE")
+            text = text.replace("NO MAXVALUE", "NOMAXVALUE")
+            text = text.replace("NO CYCLE", "NOCYCLE")
+            text = text.replace("NO ORDER", "NOORDER")
 
         t = Table(
             "foo_table",