diff options
| author | RobotScribe <quentinso@theodo.fr> | 2020-04-29 15:22:59 -0400 |
|---|---|---|
| committer | Gord Thompson <gord@gordthompson.com> | 2020-05-15 15:50:32 -0600 |
| commit | 103260ddb476c5354b3201f92636c474f2a83c35 (patch) | |
| tree | fbec060d33e0a6c3770c9d5ce7818432497ad6ef /lib/sqlalchemy | |
| parent | 9821bddfcb3c94cea13b7f19bcb27845b0dc1ed8 (diff) | |
| download | sqlalchemy-103260ddb476c5354b3201f92636c474f2a83c35.tar.gz | |
Add with_for_update mysql new functionalities
Fixes: #4860
# Description
Add nowait, skip_lock, of arguments to for_update_clause for mysql
### Checklist
This pull request is:
- [ ] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [ ] A short code fix
- please include the issue number, and create an issue if none exists, which
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests. one line code fixes without tests will not be accepted.
- [x] A new feature implementation
- please include the issue number, and create an issue if none exists, which must
include a complete example of how the feature would look.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.
**Have a nice day!**
Closes: #5290
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5290
Pull-request-sha: 490e822e73e92ffe63cf45df9c49f3b31af1954d
Change-Id: Ibd2acc47b538c601c69c8fb954776035ecab4c6c
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 31 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 3 |
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index dca7b9a00..d009d656e 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -808,6 +808,7 @@ from ...sql import coercions from ...sql import compiler from ...sql import elements from ...sql import roles +from ...sql import util as sql_util from ...types import BINARY from ...types import BLOB from ...types import BOOLEAN @@ -1494,9 +1495,28 @@ class MySQLCompiler(compiler.SQLCompiler): def for_update_clause(self, select, **kw): if select._for_update_arg.read: - return " LOCK IN SHARE MODE" + tmp = " LOCK IN SHARE MODE" else: - return " FOR UPDATE" + tmp = " FOR UPDATE" + + if select._for_update_arg.of and self.dialect.supports_for_update_of: + + tables = util.OrderedSet() + for c in select._for_update_arg.of: + tables.update(sql_util.surface_selectables_only(c)) + + tmp += " OF " + ", ".join( + self.process(table, ashint=True, use_schema=False, **kw) + for table in tables + ) + + if select._for_update_arg.nowait: + tmp += " NOWAIT" + + if select._for_update_arg.skip_locked and self.dialect._is_mysql: + tmp += " SKIP LOCKED" + + return tmp def limit_clause(self, select, **kw): # MySQL supports: @@ -2211,6 +2231,9 @@ class MySQLDialect(default.DefaultDialect): sequences_optional = True + supports_for_update_of = False # default for MySQL ... + # ... may be updated to True for MySQL 8+ in initialize() + supports_sane_rowcount = True supports_sane_multi_rowcount = False supports_multivalues_insert = True @@ -2526,6 +2549,10 @@ class MySQLDialect(default.DefaultDialect): self._is_mariadb and self.server_version_info >= (10, 3) ) + self.supports_for_update_of = ( + self._is_mysql and self.server_version_info >= (8,) + ) + self._needs_correct_for_88718_96365 = ( not self._is_mariadb and self.server_version_info >= (8,) ) diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 20f731116..b17549668 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -128,6 +128,9 @@ class DefaultDialect(interfaces.Dialect): supports_server_side_cursors = False + # extra record-level locking features (#4860) + supports_for_update_of = False + server_version_info = None default_schema_name = None |
