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()


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:

So since I don't know which objects might be updated, I clear them all?

Quoting Michael Bayer <[EMAIL PROTECTED]>:

Florian Boesch wrote:

Now why would I get so incredibly pissed at this caching issue. Well, it's
because Michael to my understanding basically told me in one go that I'm a
stupid fuckwitt and that I have no business "sneaking" database updates
past
his mapping code. That ah, did me in for.

wow i never said that at all.  i have learned that in these online forum
kind of worlds, you *really* have to read carefully what you are
responding to...especially if youre starting to get emotional.  I am a
veteran loser-of-cool in online communities, even quite recently to those
who saw it happen (not in this forum)....i know all about the "reaction"
phase.

I didnt say you shouldnt use raw SQL; you can totally use raw SQL, but you
should also tell the ORM to expire the apporpriate objects if youre doing
so, so that it knows those have been changed behind its back.  if you are
issuing SQL, you should not expect the ORM to automatically detect
that...and also shouldnt expect the ORM to work in such a way that assumes
this technique is being used, since thats not the "default" use case for
it.





-------------------------------------------------------
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!
_______________________________________________
Sqlalchemy-users mailing list






-------------------------------------------------------
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!
_______________________________________________
Sqlalchemy-users mailing list

Aaron Bickell
Research & Development
Optio Software, Inc


Reply via email to