From: KingOfKaste <47917339+KingOfKaste@users.noreply.github.com> Date: Thu, 20 Feb 2025 19:31:42 +0000 (-0500) Subject: Fix SQLite error for table with "WITHOUT ROWID" & "STRICT" X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=48ad8c81115bd01d733fe1a4f78c8c30d7c2abbb;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix SQLite error for table with "WITHOUT ROWID" & "STRICT" 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 --- diff --git a/doc/build/changelog/unreleased_20/12368.rst b/doc/build/changelog/unreleased_20/12368.rst new file mode 100644 index 0000000000..b02f0fb0a9 --- /dev/null +++ b/doc/build/changelog/unreleased_20/12368.rst @@ -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. diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index e0c0f6e809..96b2414cce 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -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): diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 997ce89351..ecb9510c93 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -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()