[sqlalchemy] orm querying: where with a subquery on self

2009-05-12 Thread Max Ischenko
I'm trying to express the following SQL: SELECT * FROM attendances a WHERE grade = (SELECT MAX(grade) FROM attendances WHERE student_id=a.student_id) and school_id=112; A2 = aliased(A) # A is Attendance class q2 = s.query(max_grade).filter(A.student_id==A2.student_id).subquery() print q2 #

[sqlalchemy] Re: orm querying: where with a subquery on self

2009-05-12 Thread az
try label the column in q2, say q2.maxgrade, then use that as print s.query(A).filter( A.grade==q2.maxgrade)... On Tuesday 12 May 2009 10:17:11 Max Ischenko wrote: I'm trying to express the following SQL: SELECT * FROM attendances a WHERE grade = (SELECT MAX(grade) FROM attendances WHERE

[sqlalchemy] Re: orm querying: where with a subquery on self

2009-05-12 Thread Max Ischenko
On 12 май, 10:17, Max Ischenko ische...@gmail.com wrote: I'm trying to express the following SQL: SELECT  * FROM attendances a WHERE grade = (SELECT MAX(grade) FROM attendances WHERE student_id=a.student_id) and school_id=112; I've got it working using literal SQL but there must be a

[sqlalchemy] Re: SQLAlchemy and unit tests

2009-05-12 Thread Giovanni Marco Dall'Olio
On Tue, May 12, 2009 at 4:54 AM, James rent.lupin.r...@gmail.com wrote: So: - what is the recommended database initialisation / cleanup strategy for unit tests involving SA? - can anyone suggest how ORM state could be hanging around between unit tests (I'm using an in-memory DB)? - is there

[sqlalchemy] Re: orm querying: where with a subquery on self

2009-05-12 Thread Max Ischenko
On Tue, May 12, 2009 at 11:43, a...@svilendobrev.com wrote: try label the column in q2, say q2.maxgrade, then use that as print s.query(A).filter( A.grade==q2.maxgrade)... Doesn't work: q2 = s.query(max_grade.label('maxgrade')).filter(A.student_id==A2.student_id).subquery() print

[sqlalchemy] creating objects in after_flush hook

2009-05-12 Thread Alessandro Dentella
Hi, in a sessionExtension.after_flush hook I create objects (namely todo actions depending on what people have inserted/updated). At present I create these objects in the current session, but I do understand is not clean as the flush has already occurred. It almost works, objects are

[sqlalchemy] Re: creating objects in after_flush hook

2009-05-12 Thread sandro dentella
I correct myself On 12 Mag, 11:05, Alessandro Dentella san...@e-den.it wrote: Hi, in a sessionExtension.after_flush hook I create objects (namely todo actions depending on what people have inserted/updated). At present I create these objects in the current session, but I do

[sqlalchemy] why backref no have effect?

2009-05-12 Thread manman
mycode like: department_table=Table('department',medadata, Column('id',Integer,primary_key=True), Column('name',String (64),nullable=False,unique=True), ) class Department(object):pass doctor_table=Table('doctor',medadata,

[sqlalchemy] Re: why backref no have effect?

2009-05-12 Thread Michael Bayer
you'd need to map Doctor also. at that point, creating a new Doctor for the first time will compile all the mappers assembled and Doctor will get a department descriptor. On May 12, 2009, at 2:36 AM, manman wrote: mycode like: department_table=Table('department',medadata,

[sqlalchemy] Problems with pyodbc on RHEL 64

2009-05-12 Thread Yannick Gingras
Hi, I also reported this problem on the pyodbc mailing list but maybe one of you know a workaround. I'm trying to use pyodbc on RHEL 5.3 64 bit but all my strings are filled with garbage after position 1024. Here is an example: import pyodbc conn = pyodbc.connect('DRIVER={SQL

[sqlalchemy] Re: Problems with pyodbc on RHEL 64

2009-05-12 Thread Rick Morrison
AFAIK, there's nothing in SQLA that will address this -- the issue sounds new to me, and it seems to me that it's pretty clearly some kind of pyodbc/FreeTDS issue. Check your character encoding settings, there's quite a few reported issues with MSSQL + pyodbc + unicode statements. You may want to