I would like to lock a table like "LOCK TABLES table_name" in mysql
command. How can I do that with SqlAlchemy.
I have defined a class
|//|//|class Pointer(Entity):
using_options(tablename='Pointer',autosetup=True)
id=Field(MSInteger,primary_key=True)
|////|I need to lock table |////|'Pointer'.|//
You can lock the tables by executing the SQL directly. I'm not sure
what that looks like in Elixir, but in plain SA it'd be something like:
conn = engine.connect()
conn.execute("LOCK TABLES Pointer WRITE")
... do stuff with conn
conn.execute("UNLOCK TABLES")
> Thank you. This is what I am doing at the moment. I am hoping it can
> be
> done more pythonically.
locking tables is a coarse grained action that can lead to deadlocks.
Finer grained row locking is available using SELECT...FOR UPDATE which
the ORM supports directly using
query.with_lockmode(<"read"|"update">), and select() supports using
the "for_update" keyword argument: select([cols],
for_update=<True|"read">)