If all you're looking for is an implicit generation of an IDENTITY column,
you can use the autoincrement=True keyword to the Column constructor.

But be careful with the assumption of autoincrementing PKs. It's perfectly
valid to have a PK that is not autoincrementing. That's why the
pseudo-Sequence() mechanism is there in the first place, to distinguish
between the two (and to allow the specification of the IDENTITY seed value).


Issuing a spurious "SELECT @@IDENTITY" could be construed as a bit risky as
well -- that will simply return the last inserted IDENTITY value on that DB
connection -- which could be from a completely different query. Given that
SA pools connection, it seems to me that this is bad-tasting recipe.

I'm not sure I understand the motivation to check each query anew for
identity keys. What's wrong with checking for them only at table definition
time?

Rick


On 1/9/07, Paul Johnston <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
>
> Using MSSQL, session.flush() doesn't always fetch primary keys back from
> the database. It works if you explicity specify a sequence, but if the
> sequence is implicitly created it doesn't fetch. I have raised ticket
> #415 for this issue.
>
> In MSSQLExecutionContext, it looks to see if any column has a sequence,
> and if so issues "select @@identity" afterwards. A couple of simple
> solutions to this:
> 1) Always issue "select @@identity" (quick tests show this should be safe)
> 2) Copy the code from MSSQLSchemaGenerator that determines whether to
> create an implicit sequence, and run it for each query.
> Thing is, I'm a bit worried about the performance of both those options.
>
> I'm wondering why the decision to give a column an implicit sequence is
> in the database engine code. The fix that seems logical to me is to put
> the code to create an implicit sequence in Column.__init__. It's down to
> the individual engines how they implement this sequence, but its
> existence or not is engine independent.
>
> Let me know what you think,
>
> Paul
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
 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