]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added for_update flag to Select/CompoundSelect
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 31 Mar 2006 22:28:17 +0000 (22:28 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 31 Mar 2006 22:28:17 +0000 (22:28 +0000)
lib/sqlalchemy/ansisql.py
lib/sqlalchemy/sql.py
test/select.py

index f13a7b84fcda62512f5d03e474e1e0938c0f889c..adfa36918bdbca780653e0758bca86226a5b9b01 100644 (file)
@@ -373,6 +373,9 @@ class ANSICompiler(sql.Compiled):
                 
         text += self.visit_select_postclauses(select)
  
+        if select.for_update:
+            text += " FOR UPDATE"
+            
         if getattr(select, 'parens', False):
             self.strings[select] = "(" + text + ")"
         else:
index 86c538f27780774c38ede458aa30c86360a4cfed..b86c965c009b437533555737e8290b2ea1c7e627 100644 (file)
@@ -1176,6 +1176,7 @@ class CompoundSelect(SelectBaseMixin, FromClause):
         self.use_labels = kwargs.pop('use_labels', False)
         self.parens = kwargs.pop('parens', False)
         self.correlate = kwargs.pop('correlate', False)
+        self.for_update = kwargs.pop('for_update', False)
         self.oid_column = selects[0].oid_column
         for s in self.selects:
             s.group_by(None)
@@ -1211,7 +1212,7 @@ class CompoundSelect(SelectBaseMixin, FromClause):
 class Select(SelectBaseMixin, FromClause):
     """represents a SELECT statement, with appendable clauses, as well as 
     the ability to execute itself and return a result set."""
-    def __init__(self, columns=None, whereclause = None, from_obj = [], order_by = None, group_by=None, having=None, use_labels = False, distinct=False, engine = None, limit=None, offset=None, scalar=False, correlate=True):
+    def __init__(self, columns=None, whereclause = None, from_obj = [], order_by = None, group_by=None, having=None, use_labels = False, distinct=False, for_update=False, engine=None, limit=None, offset=None, scalar=False, correlate=True):
         self._froms = util.OrderedDict()
         self.use_labels = use_labels
         self.name = None
@@ -1221,6 +1222,7 @@ class Select(SelectBaseMixin, FromClause):
         self.oid_column = None
         self.limit = limit
         self.offset = offset
+        self.for_update = for_update
 
         # indicates that this select statement should not expand its columns
         # into the column clause of an enclosing select, and should instead
index cac641fc09540299749343442a43bc38d00791dc..c11cff5ea52180821513e80f413b8166355937cf 100644 (file)
@@ -240,6 +240,11 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
             select([table2.c.othername, func.count(table2.c.otherid)], group_by = [table2.c.othername], order_by = [table2.c.othername]),
             "SELECT myothertable.othername, count(myothertable.otherid) FROM myothertable GROUP BY myothertable.othername ORDER BY myothertable.othername"
         )
+    
+    def testforupdate(self):
+        self.runtest(
+            table1.select(table1.c.myid==7, for_update=True), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = :mytable_myid FOR UPDATE"
+        )
     def testalias(self):
         # test the alias for a table1.  column names stay the same, table name "changes" to "foo".
         self.runtest(