jo wrote:
Hi all,

I need to insert a new row and get back the last inserted id,
I have some difficulty using the flush(), then I'm trying with commit() but
I can't understand how commit() works in 0.6.
In the following script I try to update a row and it works properly
but when I try to insert a new one, it doesn't work,
there's no messages but the row is not inserted into the table.
Is this the right way ?


from sqlalchemy.orm import sessionmaker
Session = sessionmaker(autoflush=True)
session = Session()

#update an existing row... it works
old = Specie.get('D')
old.specie_descrizione='dog'

#insert a new row... it doesn't work
new=Specie(
   specie_codice='C',
   specie_descrizione='cat'
)

session.commit()

thanks for any help

j

in my disperation, I tried also the following, but without success: :-(
from sqlalchemy.orm.session import Session
session=Session(autoflush=True,autocommit=True)

class Gruppo:
   pass

mapper(Gruppo,
      tbl['gruppo'],
      column_prefix = 'gruppo_',
   )



session.begin()
> <sqlalchemy.orm.session.SessionTransaction object at 0x28a9710>

new=Gruppo( gruppo_id = 1, gruppo_descrizione='cat')
session.commit()
print Gruppo.get(1)

>SELECT gruppo.id AS gruppo_id, gruppo.descrizione AS gruppo_descrizione
>FROM gruppo
>WHERE gruppo.id = %(param_1)s

>Col ('gruppo_id', 'gruppo_descrizione')
>None

I don't understand what's wrong. I can't INSERT a new record into a table.
Could someone, give me some help?

j




--
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?hl=en.

Reply via email to