From 71c45937f9adbb64482fffcda75f8fe4d063e027 Mon Sep 17 00:00:00 2001 From: Mario Lassnig Date: Tue, 12 Nov 2013 23:08:51 +0100 Subject: add psql FOR UPDATE OF functionality --- lib/sqlalchemy/sql/compiler.py | 2 ++ lib/sqlalchemy/sql/selectable.py | 2 ++ 2 files changed, 4 insertions(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 4f3dbba36..51ec0d9eb 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1571,6 +1571,8 @@ class SQLCompiler(Compiled): def for_update_clause(self, select): if select.for_update: + if select.for_update_of is not None: + return " FOR UPDATE OF " + select.for_update_of return " FOR UPDATE" else: return "" diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 550e250f1..8ad238ca3 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1162,6 +1162,7 @@ class SelectBase(Executable, FromClause): def __init__(self, use_labels=False, for_update=False, + for_update_of=None, limit=None, offset=None, order_by=None, @@ -1170,6 +1171,7 @@ class SelectBase(Executable, FromClause): autocommit=None): self.use_labels = use_labels self.for_update = for_update + self.for_update_of = for_update_of if autocommit is not None: util.warn_deprecated('autocommit on select() is ' 'deprecated. Use .execution_options(a' -- cgit v1.2.1 From 741da873841012d893ec08bd77a5ecc9237eaab8 Mon Sep 17 00:00:00 2001 From: Mario Lassnig Date: Thu, 14 Nov 2013 20:18:52 +0100 Subject: added ORM support --- lib/sqlalchemy/sql/compiler.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 51ec0d9eb..4f3dbba36 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1571,8 +1571,6 @@ class SQLCompiler(Compiled): def for_update_clause(self, select): if select.for_update: - if select.for_update_of is not None: - return " FOR UPDATE OF " + select.for_update_of return " FOR UPDATE" else: return "" -- cgit v1.2.1 From e9aaf8eb66343f247b1ec2189707f820e20a0629 Mon Sep 17 00:00:00 2001 From: Mario Lassnig Date: Thu, 28 Nov 2013 14:50:41 +0100 Subject: added LockmodeArgs --- lib/sqlalchemy/sql/compiler.py | 7 ++++++- lib/sqlalchemy/sql/selectable.py | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 4f3dbba36..54eb1f9eb 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1570,7 +1570,12 @@ class SQLCompiler(Compiled): return "" def for_update_clause(self, select): - if select.for_update: + # backwards compatibility + if isinstance(select.for_update, bool): + return " FOR UPDATE" if select.for_update else "" + elif isinstance(select.for_update, str): + return " FOR UPDATE" + elif select.for_update.mode is not None: return " FOR UPDATE" else: return "" diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 8ad238ca3..dcf7689cf 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1162,7 +1162,6 @@ class SelectBase(Executable, FromClause): def __init__(self, use_labels=False, for_update=False, - for_update_of=None, limit=None, offset=None, order_by=None, @@ -1171,7 +1170,6 @@ class SelectBase(Executable, FromClause): autocommit=None): self.use_labels = use_labels self.for_update = for_update - self.for_update_of = for_update_of if autocommit is not None: util.warn_deprecated('autocommit on select() is ' 'deprecated. Use .execution_options(a' @@ -2787,4 +2785,3 @@ class AnnotatedFromClause(Annotated): Annotated.__init__(self, element, values) - -- cgit v1.2.1