HD Mail wrote:

Actually, ignore my last post. I had a closer look and created this patch. Hopefully it can be of some use.

I added a for_update attribute to the Select class.

Then changed the ansisql.py:

def visit_select_postclauses

to add my for_update statement.

It seems to work for me.

Huy


Michael Bayer wrote:
I dont have "FOR UPDATE" in there as of yet. it can be added easily enough, although im short on time this week. feel free to add a ticket (or dig around sql.py and see if you can figure it out)

Thanks Michael. I did have a look. I could add it in SelectBaseMixin the same way you do order_by/group_by but because I not too familiar with SA internals, I'm a bit reluctant.

Huy

On Mar 29, 2006, at 8:00 AM, HD Mail wrote:

Hi,

I am building a select using

st = table.select()
st.append_whereclause(...)

Is it possible to append something like "FOR UPDATE" at the end of the generated select statement.

Before anyone shoots me down for using "for update", i'm writing a stock control system.

I love the query building features in SA so I really want to use it to write my sql rather then using straight sql.

Thanks

Huy



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Index: ansisql.py
===================================================================
--- ansisql.py  (revision 1144)
+++ ansisql.py  (working copy)
@@ -379,7 +379,9 @@
 
     def visit_select_postclauses(self, select):
         """ called when building a SELECT statement, position is after all 
other SELECT clauses. Most DB syntaxes put LIMIT/OFFSET here """
-        return (select.limit or select.offset) and self.limit_clause(select) 
or ""
+        limit_sql = (select.limit or select.offset) and 
self.limit_clause(select) or ""
+        for_update_sql = select.for_update and self.for_update_clause(select) 
or ""
+        return ' '.join([limit_sql, for_update_sql])
 
     def limit_clause(self, select):
         if select.limit is not None:
@@ -389,6 +391,12 @@
                 return " \n LIMIT -1"
             return " OFFSET " + str(select.offset)
 
+    def for_update_clause(self, select):
+        if select.for_update: 
+            return  " \n FOR UPDATE"
+        else:
+            return ""
+
     def visit_table(self, table):
         self.froms[table] = table.fullname
         self.strings[table] = ""
Index: sql.py
===================================================================
--- sql.py      (revision 1144)
+++ sql.py      (working copy)
@@ -1126,6 +1126,7 @@
         self._append_clause('order_by_clause', "ORDER BY", *clauses)
     def group_by(self, *clauses):
         self._append_clause('group_by_clause', "GROUP BY", *clauses)
+    
     def _append_clause(self, attribute, prefix, *clauses):
         if len(clauses) == 1 and clauses[0] is None:
             try:
@@ -1199,7 +1200,7 @@
 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, engine = None, limit=None, offset=None, scalar=False, 
correlate=True, for_update=False):
         self._froms = util.OrderedDict()
         self.use_labels = use_labels
         self.id = "Select(%d)" % id(self)
@@ -1210,6 +1211,7 @@
         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

Reply via email to