]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix sqlite localtimestamp function
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 1 May 2025 13:43:29 +0000 (09:43 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 1 May 2025 13:44:08 +0000 (09:44 -0400)
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
(cherry picked from commit d689e465edf11308b0efba018aa84c3d79ccbaab)

doc/build/changelog/unreleased_20/12566.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/12566.rst b/doc/build/changelog/unreleased_20/12566.rst
new file mode 100644 (file)
index 0000000..194936f
--- /dev/null
@@ -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.
index bf632f1fa4f78905bce0179a01c21f99e7660f7e..719c0860b4fce6e310732ba9ffc729e7bc9a2de8 100644 (file)
@@ -1367,7 +1367,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"
index c2c63e9ef06fdb0a7dc51d23ca1892c4c7d8c19e..0d8c671402d9953d5c6c3cab4218f8ace88040da 100644 (file)
@@ -785,6 +785,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"
@@ -969,7 +979,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):