From: Mike Bayer Date: Wed, 7 Apr 2021 21:51:34 +0000 (-0400) Subject: support multivalues insert on strsqlcompiler X-Git-Tag: rel_1_4_7~14^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26f1efcb055b70fe86a643338b65c849f9e2fa4e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git support multivalues insert on strsqlcompiler 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 --- diff --git a/doc/build/changelog/unreleased_14/mr_str.rst b/doc/build/changelog/unreleased_14/mr_str.rst new file mode 100644 index 0000000000..f8511dc874 --- /dev/null +++ b/doc/build/changelog/unreleased_14/mr_str.rst @@ -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. + diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 5193a0273e..0242d9812f 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -790,6 +790,7 @@ class StrCompileDialect(DefaultDialect): supports_native_boolean = True + supports_multivalues_insert = True supports_simple_order_by_label = True colspecs = { diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index d7a74ee2ea..6cadda0bb8 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -4415,6 +4415,17 @@ class StringifySpecialTest(fixtures.TestBase): stmt = Column(Integer) == 5 eq_ignore_whitespace(str(stmt), '"" = :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()