]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix SQLite error for table with "WITHOUT ROWID" & "STRICT"
authorKingOfKaste <47917339+KingOfKaste@users.noreply.github.com>
Thu, 20 Feb 2025 19:31:42 +0000 (14:31 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Feb 2025 20:26:16 +0000 (15:26 -0500)
Fixed issue that omitted the comma between multiple SQLite table extension
clauses, currently ``WITHOUT ROWID`` and ``STRICT``, when both options
:paramref:`.Table.sqlite_with_rowid` and  :paramref:`.Table.sqlite_strict`
were configured at their non-default settings at the same time.  Pull
request courtesy david-fed.

Fixes: #12368
Closes: #12369
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12369
Pull-request-sha: 3c9ceffe8279f5d961a44e6d468f21881bcbc75c

Change-Id: I1a44fd2d655d0e6eaad8213a360879daca9e4f11
(cherry picked from commit 48ad8c81115bd01d733fe1a4f78c8c30d7c2abbb)

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..b02f0fb
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, sqlite
+    :tickets: 12368
+
+    Fixed issue that omitted the comma between multiple SQLite table extension
+    clauses, currently ``WITH ROWID`` and ``STRICT``, when both options
+    :paramref:`.Table.sqlite_with_rowid` and  :paramref:`.Table.sqlite_strict`
+    were configured at their non-default settings at the same time.  Pull
+    request courtesy david-fed.
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 f73ba4025a1c23c4c04b5542e92c0e220c26517c..819bf8aa06b75dd02d2ff48dfdd8ce2564782850 100644 (file)
@@ -1153,6 +1153,20 @@ 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()