]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
support multivalues insert on strsqlcompiler
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2021 21:51:34 +0000 (17:51 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2021 21:52:23 +0000 (17:52 -0400)
Fixed the "stringify" compiler to support a basic stringification
of a "multirow" INSERT statement, i.e. one with multiple tuples
following the VALUES keyword.

Change-Id: I1fe38d204d9965275d3a72157d5a72a53bec4b11

doc/build/changelog/unreleased_14/mr_str.rst [new file with mode: 0644]
lib/sqlalchemy/engine/default.py
test/sql/test_compiler.py

diff --git a/doc/build/changelog/unreleased_14/mr_str.rst b/doc/build/changelog/unreleased_14/mr_str.rst
new file mode 100644 (file)
index 0000000..f8511dc
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, sql
+
+    Fixed the "stringify" compiler to support a basic stringification
+    of a "multirow" INSERT statement, i.e. one with multiple tuples
+    following the VALUES keyword.
+
index 5193a0273e8db6a70c19fcd7d8acc404a1dfc37d..0242d9812f68c585e048d3ad770dd42cf12ca8b4 100644 (file)
@@ -790,6 +790,7 @@ class StrCompileDialect(DefaultDialect):
 
     supports_native_boolean = True
 
+    supports_multivalues_insert = True
     supports_simple_order_by_label = True
 
     colspecs = {
index d7a74ee2eab4d1df6d04f3ddccbf343fc364daee..6cadda0bb84f54c6ef6ce3be44949dad003d01e1 100644 (file)
@@ -4415,6 +4415,17 @@ class StringifySpecialTest(fixtures.TestBase):
         stmt = Column(Integer) == 5
         eq_ignore_whitespace(str(stmt), '"<name unknown>" = :param_1')
 
+    def test_empty_insert(self):
+        stmt = table1.insert().values()
+        eq_ignore_whitespace(str(stmt), "INSERT INTO mytable () VALUES ()")
+
+    def test_multirow_insert(self):
+        stmt = table1.insert().values([{"myid": 1}, {"myid": 2}])
+        eq_ignore_whitespace(
+            str(stmt),
+            "INSERT INTO mytable (myid) VALUES (:myid_m0), (:myid_m1)",
+        )
+
     def test_cte(self):
         # stringify of these was supported anyway by defaultdialect.
         stmt = select(table1.c.myid).cte()