]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes #12368
authorKingOfKaste <47917339+KingOfKaste@users.noreply.github.com>
Thu, 20 Feb 2025 19:03:52 +0000 (20:03 +0100)
committerKingOfKaste <47917339+KingOfKaste@users.noreply.github.com>
Thu, 20 Feb 2025 19:03:52 +0000 (20:03 +0100)
doc/build/changelog/unreleased_20/12368.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py

diff --git a/doc/build/changelog/unreleased_20/12368.rst b/doc/build/changelog/unreleased_20/12368.rst
new file mode 100644 (file)
index 0000000..c8a8bee
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, sqlite
+    :tickets: 12368
+
+    Fixed a bug that caused incorrect DDL when setting
+    :paramref:`.Table.sqlite_with_rowid` to ``False`` in combination with
+    :paramref:`.Table.sqlite_strict` to ``True``.
index e0c0f6e80986da5395837599a248170b9bc6c946..96b2414ccec4a20ca90ea732850054b608032067 100644 (file)
@@ -1758,12 +1758,18 @@ class SQLiteDDLCompiler(compiler.DDLCompiler):
         return text
 
     def post_create_table(self, table):
-        text = ""
-        if table.dialect_options["sqlite"]["with_rowid"] is False:
-            text += "\n WITHOUT ROWID"
-        if table.dialect_options["sqlite"]["strict"] is True:
-            text += "\n STRICT"
-        return text
+        table_options = []
+
+        if not table.dialect_options["sqlite"]["with_rowid"]:
+            table_options.append("WITHOUT ROWID")
+
+        if table.dialect_options["sqlite"]["strict"]:
+            table_options.append("STRICT")
+
+        if table_options:
+            return "\n " + ",\n ".join(table_options)
+        else:
+            return ""
 
 
 class SQLiteTypeCompiler(compiler.GenericTypeCompiler):
index 997ce893515a7f34eaf2a94bba9a7dd9e65367b5..730bce1a145218e89425eb51bce3db596ed5c0f4 100644 (file)
@@ -1153,6 +1153,14 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
             "CREATE TABLE atable (id INTEGER) STRICT",
         )
 
+    def test_create_table_without_rowid_strict(self):
+        m = MetaData()
+        table = Table("atable", m, Column("id", Integer), sqlite_with_rowid=False, sqlite_strict=True)
+        self.assert_compile(
+            schema.CreateTable(table),
+            "CREATE TABLE atable (id INTEGER) WITHOUT ROWID, STRICT",
+        )
+
 
 class OnConflictDDLTest(fixtures.TestBase, AssertsCompiledSQL):
     __dialect__ = sqlite.dialect()