On Oct 6, 4:14 am, Joril <[EMAIL PROTECTED]> wrote:
> Hi everyone!
> I'm looking for a way to log queries at a higher level than SQL.. That
> is, given the class
>
> Base = declarative_base()
> class DataTest(Base):
>     id = Column(Integer, primary_key = True)
>     propb = Column(Boolean)
>     __tablename__ = "t"
>
> right now when I try to print a query restriction:
>
> restr=(DataTest.propb==False)
> print restr
>
> I get something like
>
> "t.propb = :propb_1"
>
> Is there a way to get
>
> "propb = False"
> ?
>
> I know I can fetch the operands via restr.left.name and
> restr.right.value, but what about the operator?
> Many thanks for your help!

You'd have to build a function which interpolates the values of bind
parameters into the SQL string, something like:

def print_clause(clause):
    t = str(clause)
    params = clause.compile().params
    def token(m):
        return repr(params[m.group(1)])
    return re.compile(r':(\w+)').sub(token, t)

Alternatively you could visit and compile the clause directly with
your own compiler, which subclasses compiler.DefaultCompiler and
overrides visit_bindparam() to return a string representation of the
data instead of a param name.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to