diff options
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/base.py | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 18 |
5 files changed, 25 insertions, 17 deletions
diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index a3c31b7cc..ba69c3d1f 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -666,15 +666,15 @@ class OracleCompiler(compiler.SQLCompiler): tmp = ' FOR UPDATE' - if select._for_update_arg.nowait: - tmp += " NOWAIT" - if select._for_update_arg.of: tmp += ' OF ' + ', '.join( - self._process(elem) for elem in + self.process(elem) for elem in select._for_update_arg.of ) + if select._for_update_arg.nowait: + tmp += " NOWAIT" + return tmp diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 091fdeda2..69b0fb040 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1020,17 +1020,17 @@ class PGCompiler(compiler.SQLCompiler): else: tmp = " FOR UPDATE" - if select._for_update_arg.nowait: - tmp += " NOWAIT" - if select._for_update_arg.of: # TODO: assuming simplistic c.table here tables = set(c.table for c in select._for_update_arg.of) tmp += " OF " + ", ".join( - self.process(table, asfrom=True) + self.process(table, ashint=True) for table in tables ) + if select._for_update_arg.nowait: + tmp += " NOWAIT" + return tmp def returning_clause(self, stmt, returning_cols): diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index f0d9a47d6..173ad038e 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1124,10 +1124,10 @@ class Query(object): self._execution_options = self._execution_options.union(kwargs) @_generative() - def with_lockmode(self, mode, of=None): + def with_lockmode(self, mode): """Return a new Query object with the specified locking mode. - .. deprecated:: 0.9.0b2 superseded by :meth:`.Query.for_update`. + .. deprecated:: 0.9.0b2 superseded by :meth:`.Query.with_for_update`. :param mode: a string representing the desired locking mode. A corresponding :meth:`~sqlalchemy.orm.query.LockmodeArgs` object diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 0fc99897e..3ba3957d6 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1513,9 +1513,11 @@ class SQLCompiler(Compiled): text += self.order_by_clause(select, order_by_select=order_by_select, **kwargs) + if select._limit is not None or select._offset is not None: text += self.limit_clause(select) - if select._for_update_arg: + + if select._for_update_arg is not None: text += self.for_update_clause(select) if self.ctes and \ diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index e49c10001..01c803f3b 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1151,7 +1151,7 @@ class TableClause(Immutable, FromClause): return [self] -class ForUpdateArg(object): +class ForUpdateArg(ClauseElement): @classmethod def parse_legacy_select(self, arg): @@ -1185,6 +1185,8 @@ class ForUpdateArg(object): read = True elif arg == 'read_nowait': read = nowait = True + elif arg is not True: + raise exc.ArgumentError("Unknown for_update argument: %r" % arg) return ForUpdateArg(read=read, nowait=nowait) @@ -1195,9 +1197,13 @@ class ForUpdateArg(object): elif self.read and self.nowait: return "read_nowait" elif self.nowait: - return "update_nowait" + return "nowait" else: - return "update" + return True + + def _copy_internals(self, clone=_clone, **kw): + if self.of is not None: + self.of = [clone(col, **kw) for col in self.of] def __init__(self, nowait=False, read=False, of=None): """Represents arguments specified to :meth:`.Select.for_update`. @@ -1208,7 +1214,7 @@ class ForUpdateArg(object): self.nowait = nowait self.read = read if of is not None: - self.of = [_only_column_elements(of, "of") + self.of = [_only_column_elements(elem, "of") for elem in util.to_list(of)] else: self.of = None @@ -1770,7 +1776,7 @@ class CompoundSelect(SelectBase): self.selects = [clone(s, **kw) for s in self.selects] if hasattr(self, '_col_map'): del self._col_map - for attr in ('_order_by_clause', '_group_by_clause'): + for attr in ('_order_by_clause', '_group_by_clause', '_for_update_arg'): if getattr(self, attr) is not None: setattr(self, attr, clone(getattr(self, attr), **kw)) @@ -2255,7 +2261,7 @@ class Select(HasPrefixes, SelectBase): # present here. self._raw_columns = [clone(c, **kw) for c in self._raw_columns] for attr in '_whereclause', '_having', '_order_by_clause', \ - '_group_by_clause': + '_group_by_clause', '_for_update_arg': if getattr(self, attr) is not None: setattr(self, attr, clone(getattr(self, attr), **kw)) |
