oh OK this is a little simpler than what I had in mind, you just have to add 
the mixin expression.Executable to your ForUpdateOf class.


On Feb 3, 2011, at 9:05 PM, Kent wrote:

> Here is a crude outline (need to properly escape table name, etc.), of
> what I think might work, and it seems to render properly, but crashes
> with:
> 
>  File "/home/rarch/tg2env/lib/python2.6/site-packages/
> SQLAlchemy-0.6.4.2kbdev-py2.6-linux-x86_64.egg/sqlalchemy/engine/
> default.py", line 353, in __init__
>    raise exc.ArgumentError("Not an executable clause: %s" % compiled)
> ArgumentError: Not an executable clause:
> ...
> 
> class MyQuery(Query):
>    _for_update_of = None
> 
>    @_generative()
>    def for_update_of(self, arg):
>        """Keep track that we want to for update of this"""
>        self._for_update_of = class_mapper(arg).mapped_table.name
> 
>    def _compile_context(self, labels=True):
>        context = super(MyQuery, self)._compile_context(labels)
>        if self._for_update_of:
>            context.statement = ForUpdateOf(context.statement,
> self._for_update_of)
>        return context
> 
> class ForUpdateOf(ClauseElement):
>    def __init__(self, statement, for_update_of):
>        self.statement = statement
>        self.for_update_of = for_update_of
> 
> @compiles(ForUpdateOf)
> def compile_forupdateof(element, compiler, **kw):
>    return "%s FOR UPDATE OF %s" %
> (compiler.process(element.statement), element.for_update_of)
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to