Hi,
This is my first posting to this list as I am new to SQLAlchemy , so let me
express
my gratitude to those who develop SQLAlchemy... It's absolutely fabulous... The
ORM in
particular is fantastic!
I am using version 0.2.8 with Python 2.4.3 and MySQL 4.1.21 on an up-to-date
Linux Gentoo box
Session Flush Problem
=================
I am having a problem with session.flush(). It seems that every time I issue a
session flush the
DB connection is closed. If I do something like this
eng = create_engine('mysql://test:[EMAIL
PROTECTED]/test',strategy='threadlocal')
conn=eng.connect()
session = create_session(bind_to=conn)
query=session.query(dbPeople) #This step needed for "compiling" the
class/mapper or something like that
query=query.select_by_Lastname
listofpeople=query("Doe")
oneguy=listofpeople[0]
oneguy.Country="Namibia"
session.flush()
listofpeople=query("Smith")
The flush works alright and the database is updated, but the last line result
in an error message:
sqlalchemy.exceptions.InvalidRequestError: This Connection is closed
Is that the normal behaviour? I would have expected the session to query the DB
and return a new list
of dbPeople adding them to its list of "persistent" object. Am I doing
something wrong? Misunderstanding
something?
Is this or something similar possible?
===========================
Given a dbPeople class, here is what I'd like to do
wherep=dbPeople()
wherep.Lastname="Smith"
wherep.Country="United Kingdom"
listofsmith=session.query(dbPeople).select_by(wherep)
listofsmithbosses=session.query(dbPeople).select_by(Manager=wherep)
Given the right table, classes and mapper definition (omitted here, in the
above example, Manager could be
defined as a "backref") the first query would produce an SQL "WHERE" clause like
"WHERE Lastname="Smith" AND Country="United Kingdom"
The list of dbPeople named "Smith" in the UK
Whilst the second would produce a query like
SELECT <list of field for table People> FROM People AS Employee, People
AS Manager, ManagerRel
WHERE Employee.id=ManagerRel.Employee AND
Manager.id=ManagerRel.Manager AND
Manager.Lastname="Smith" AND Manager.Country="United Kingdom"
The list of dbPeople whose manager is a "Smith" in the UK
Essentially, the (transient) object would keep track of which properties were
set (including set to None) and use
those to construct the WHERE clause. Probably easier said then done.... The
case of "Pending" instances should
be quite complex ( and in some case would not make any sense)
Best Regards,
François
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~----------~----~----~----~------~----~------~--~---