From d689e465edf11308b0efba018aa84c3d79ccbaab Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 1 May 2025 09:43:29 -0400 Subject: [PATCH] fix sqlite localtimestamp function Fixed and added test support for a few SQLite SQL functions hardcoded into the compiler most notably the "localtimestamp" function which rendered with incorrect internal quoting. Fixes: #12566 Change-Id: Id5bd8dc7841f0afab7df031ba5c0854dab845a1d --- doc/build/changelog/unreleased_20/12566.rst | 7 +++++++ lib/sqlalchemy/dialects/sqlite/base.py | 2 +- test/dialect/test_sqlite.py | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 doc/build/changelog/unreleased_20/12566.rst diff --git a/doc/build/changelog/unreleased_20/12566.rst b/doc/build/changelog/unreleased_20/12566.rst new file mode 100644 index 0000000000..194936f967 --- /dev/null +++ b/doc/build/changelog/unreleased_20/12566.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, sqlite + :tickets: 12566 + + Fixed and added test support for a few SQLite SQL functions hardcoded into + the compiler most notably the "localtimestamp" function which rendered with + incorrect internal quoting. diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 99283ac356..1501e594f3 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -1360,7 +1360,7 @@ class SQLiteCompiler(compiler.SQLCompiler): return "CURRENT_TIMESTAMP" def visit_localtimestamp_func(self, func, **kw): - return 'DATETIME(CURRENT_TIMESTAMP, "localtime")' + return "DATETIME(CURRENT_TIMESTAMP, 'localtime')" def visit_true(self, expr, **kw): return "1" diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 2ae7298dc5..17c0eb8d71 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -780,6 +780,16 @@ class DialectTest( " y INTEGER GENERATED ALWAYS AS (x + 2)%s)" % text, ) + @testing.combinations( + (func.localtimestamp(),), + (func.now(),), + (func.char_length("test"),), + (func.aggregate_strings("abc", ","),), + argnames="fn", + ) + def test_builtin_functions_roundtrip(self, fn, connection): + connection.execute(select(fn)) + class AttachedDBTest(fixtures.TablesTest): __only_on__ = "sqlite" @@ -964,7 +974,7 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL): def test_localtime(self): self.assert_compile( - func.localtimestamp(), 'DATETIME(CURRENT_TIMESTAMP, "localtime")' + func.localtimestamp(), "DATETIME(CURRENT_TIMESTAMP, 'localtime')" ) def test_constraints_with_schemas(self): -- 2.47.2