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,
- )
+ with testing.expect_warnings("SKIP LOCKED ignored on non-supporting"):
+ 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_delete_extra_froms(self):
t1 = table("t1", column("c1"))
from sqlalchemy import exc
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
+from sqlalchemy import Table
from sqlalchemy import testing
from sqlalchemy import update
from sqlalchemy.dialects.mysql import base as mysql
+from sqlalchemy.exc import ProgrammingError
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
from sqlalchemy.sql import column
from sqlalchemy.sql import table
+from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
+from sqlalchemy.testing import expect_warnings
from sqlalchemy.testing import fixtures
"LOCK IN SHARE MODE OF mytable",
dialect=self.for_update_of_dialect,
)
+
+
+class SkipLockedTest(fixtures.TablesTest):
+ __only_on__ = ("mysql",)
+ __backend__ = True
+
+ @classmethod
+ def define_tables(cls, metadata):
+
+ Table(
+ "stuff",
+ metadata,
+ Column("id", Integer, primary_key=True),
+ Column("value", Integer),
+ )
+
+ @testing.only_on("mysql>=8")
+ @testing.skip_if(lambda config: testing.db.dialect._is_mariadb)
+ def test_skip_locked(self, connection):
+
+ stuff = self.tables.stuff
+
+ stmt = stuff.select().with_for_update(skip_locked=True)
+
+ connection.execute(stmt).fetchall()
+
+ @testing.only_on(lambda config: testing.db.dialect._is_mariadb)
+ def test_warning_skip_locked(self, connection):
+
+ stuff = self.tables.stuff
+
+ stmt = stuff.select().with_for_update(skip_locked=True)
+
+ with expect_warnings(
+ "SKIP LOCKED ignored on non-supporting MariaDB backend. "
+ "This will raise an error in SQLAlchemy 1.4."
+ ):
+
+ connection.execute(stmt).fetchall()
+
+ @testing.only_on("mysql<8")
+ def test_unsupported_skip_locked(self, connection):
+
+ stuff = self.tables.stuff
+
+ stmt = stuff.select().with_for_update(skip_locked=True)
+
+ assert_raises_message(
+ ProgrammingError,
+ "You have an error in your SQL syntax",
+ connection.execute,
+ stmt,
+ )