Aaron Bickell wrote:

I have run into issues with keeping the objects I have 'sync'ed with the database so I can issue plain sql statements within the same transaction. This is how I have been dealing with it...


from sqlalchemy import *
from sqlalchemy.schema import default_engine as engine

global_connect("postgres://database=crazy_db")

users = Table('users',
    Column('user_id', Integer, primary_key = True),
    Column('user_name', String(16), nullable = False),
    Column('email_address', String(60), key='email'),
    Column('password', String(20), nullable = False)
    )

class User(object):pass

User.mapper = mapper(User, users)

try:users.drop()
except:pass

users.create()

engine.begin()
u = User()
u.user_name = 'barry'
u.user_id = 12
u.password = 'hooha'

objectstore.commit(u)

#issues select directly on the database
c = engine.execute("select * from users where user_name='barry'")
print c.fetchall()
engine.commit()


Why don't you use
objectstore.get_session.refresh(u) - for reloading individual records,
or
objectstore.clear()

Huy

I know that there are some ramifications to committing/deleting objects individually, but I've been using this a bit, without any issues. Because the engine had explicitly started a transaction, all statements in this scope act in this transaction, and 'objectstore.commit(u)' simply causes the insert/update/delete statements for that object to be issued. I hope this helps.

Aaron

On Mar 29, 2006, at 2:44 AM, Florian Boesch wrote:

[snip]


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to