On 6 Ott, 15:26, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Oct 6, 4:14 am,Joril<[EMAIL PROTECTED]> wrote:
>
> > I'm looking for a way to log queries at a higher level than SQL.. That
[cut]
>
> 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.


Hi everyone,
I have a further question on this topic (=logging queries at class
level instead of table level).. Is there a way to represent "has"
restriction instances with something closer to what created them? For
example, with the following program:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relation

Base = declarative_base()

class Address(Base):
    __tablename__ = 'addresses'

    id = Column('id', Integer, primary_key=True)
    email = Column('email', String(50))

class User(Base):
    __tablename__ = 'users'

    id = Column('id', Integer, primary_key=True)
    name = Column('name', String(50))
    home_id = Column(Integer, ForeignKey('addresses.id'))
    work_id = Column(Integer, ForeignKey('addresses.id'))
    home_address = relation("Address",
primaryjoin="Address.id==User.home_id")
    work_address = relation("Address",
primaryjoin="Address.id==User.work_id")

res = User.home_address.has(email="test")
print res


I get
> EXISTS (SELECT 1 FROM addresses WHERE addresses.id = users.home_id AND 
> addresses.email = :email_1)

Is there a way to have something like
> home_address HAS email='test'
?

I tried digging into "res" with a debugger, but couldn't find any
reference to home_address..
Many thanks for your time!
--~--~---------~--~----~------------~-------~--~----~
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