On May 12, 2008, at 2:54 PM, Dr.T wrote:

>
> I saw the posts about SQLAlchemy updating an id when this is generated
> by SQLAlchemy by setting Sequence() on the table's primary key Column,
> but being an old Oracle hacker, I am generating the primary keys via
> pre-insert triggers on the tables.
>
> As SQLAlchemy is not selecting seq_name.nextval itself the id of the
> object is not being updated as is the case above.
>
> Is there nonetheless any SQLAlchemy magic to retrieve the value of the
> newly inserted record?

there is not in that case since cx_oracle nor OCI provides any way of  
getting at that value (i.e. cursor.lastrowid is not supported and im  
not familiar with a reliable "select last_inserted_id" technique for  
oracle).  With Oracle, SQLA needs to be given a SQL expression which  
it can execute in order to get at the new ID, *before* its inserted.   
Using triggers on your table is not entirely incompatible with this,  
as long as you give SQLA a "default" generator representing the  
expression which the trigger calls (using the "default" keyword  
argument on Column); SQLA then calls this expression directly and  
presents the new ID to the INSERT statement, thus bypassing the trigger.

If there is in fact some kind of "select last_inserted_id" function  
available that im not aware of, the oracle dialect could conceivably  
be enhanced to support this model as well.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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