From 490e822e73e92ffe63cf45df9c49f3b31af1954d Mon Sep 17 00:00:00 2001 From: RobotScribe Date: Wed, 29 Apr 2020 21:03:05 +0200 Subject: [PATCH] Do not use of and skip_locked with mariadb --- lib/sqlalchemy/dialects/mysql/base.py | 5 +++-- test/dialect/mysql/test_compiler.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index a814de1b6d..fa49135d54 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1499,7 +1499,7 @@ class MySQLCompiler(compiler.SQLCompiler): else: tmp = " FOR UPDATE" - if select._for_update_arg.of: + if select._for_update_arg.of and self.dialect._is_mysql: tables = util.OrderedSet() for c in select._for_update_arg.of: @@ -1512,7 +1512,8 @@ class MySQLCompiler(compiler.SQLCompiler): if select._for_update_arg.nowait: tmp += " NOWAIT" - if select._for_update_arg.skip_locked: + + if select._for_update_arg.skip_locked and self.dialect._is_mysql: tmp += " SKIP LOCKED" return tmp diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py index 636f9d5297..2a712e6817 100644 --- a/test/dialect/mysql/test_compiler.py +++ b/test/dialect/mysql/test_compiler.py @@ -353,6 +353,32 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): expr = literal("x", type_=String) + literal("y", type_=String) self.assert_compile(expr, "concat('x', 'y')", literal_binds=True) + def test_mariadb_for_update(self): + dialect = mysql.dialect() + dialect.server_version_info = (10, 1, 1, "MariaDB") + + table1 = table( + "mytable", column("myid"), column("name"), column("description") + ) + + self.assert_compile( + table1.select(table1.c.myid == 7).with_for_update(of=table1), + "SELECT mytable.myid, mytable.name, mytable.description " + "FROM mytable WHERE mytable.myid = %s " + "FOR UPDATE", + dialect=dialect, + ) + + self.assert_compile( + table1.select(table1.c.myid == 7).with_for_update( + skip_locked=True + ), + "SELECT mytable.myid, mytable.name, mytable.description " + "FROM mytable WHERE mytable.myid = %s " + "FOR UPDATE", + dialect=dialect, + ) + def test_for_update(self): table1 = table( "mytable", column("myid"), column("name"), column("description") -- 2.47.3