in reply to Getting identity after autoincr in FreeTDS/MSSQL/DBI

I would bet that this is happening because you're trying to do both in one statement. try doing the insert, then grab the identity with a second call.. cooincidentally, my first post here spoke to this issue, albeit from Win32. Identity nabber for MSSQL
  • Comment on Re: Getting identity after autoincr in FreeTDS/MSSQL/DBI

Replies are listed 'Best First'.
Re: Re: Getting identity after autoincr in FreeTDS/MSSQL/DBI
by wardk (Deacon) on Nov 09, 2001 at 22:47 UTC
    hmmm, I guess I should login before posting, if I was wrong about the above blame anonymous monk...
      wardk,

      I think it is different when running over freeTDS on linux, because when I tried to do it as two seperate commands, @@IDENTITY was empty. I think it has something to do with the concept of "current session", but I don't really know.

      Nice work in Identity nabber for MSSQL, by the way.

      Thanks,
      Scott

        If the value for @@identity is empty when doing this as two requests it means that the select @@identity is done on a different physical connection from the insert. This usually happens when you don't completely flush all the results after the initial insert.

        I'm thinking of adding an attribute to DBD::Sybase that would inhibit the automatic secondary connections to handle multiple concurrent $sth on a single database handle as that causes quite a lot of confusion for people...

        Michael