Skip to Content.
Sympa Menu

freetds - Re: [freetds] SELECT @@IDENTITY AS InsertID

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] SELECT @@IDENTITY AS InsertID
  • Date: Wed, 16 Nov 2005 15:58:31 +0100

>
> > From: Shaun Craig
> > Sent: Wednesday, November 16, 2005 6:01 AM
> >
> > At present i've taken out my select @@identity and replaced it with
> > a select top 1 ... order by ...desc, this also gets me my identity,
> > its safe for each 'Event' as another 'Event' from the same device
> > cant be processed till this 'Event' would be finished.
> >
> > I dont use any stored procedures as code will have to be converted
> > to connect to mysql eventually.
>
> Your code will be standards-conformant and faster if you use 'select
> max(ID)' instead of "top 1 ... order by". It's much less work for the
> server, especially if (as should be the case) the ID is the first
> element of a unique index.
>

Yes, however if another connection insert a row just after my insert
max(id) returns wrong id... I think that the best option is to fix our
pool server to not reuse connection for every query. It would be perfect
if it could also "rollback" to a safe state (rollback all transactions,
close cursors, drop temporary objects and so on)

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page