]> 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:43:29 +0000 (09:43 -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

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 99283ac356faf91441c761de6f91512621593343..1501e594f354878453a37be6337de303010f9d29 100644 (file)
@@ -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"
index 2ae7298dc5dd1cfa6db4d4c644c9b80404bdc734..17c0eb8d71591a46ee452eae90bd01b589418486 100644 (file)
@@ -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):