MS SQL Azure, last autoinc value with TUniTable/TUniQuery

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
StefanDWC
Posts: 24
Joined: Mon 22 May 2017 08:42

MS SQL Azure, last autoinc value with TUniTable/TUniQuery

Post by StefanDWC » Wed 24 May 2017 10:19

Hello, how can i retrive the last autoinc value which is generated by inserting of my latest record in a TUniTable or TUniQuery?
if i post a insert script manually then can i use the MS SQL script variable @@IDENTITY.
However, if i use e.g., TUniTable.Insert + TUniTable.Post, how can i get the value then?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: MS SQL Azure, last autoinc value with TUniTable/TUniQuery

Post by azyk » Fri 26 May 2017 13:50

After inserting record in the TUniTable dataset you can get auto-increment field value from the TUniQuery.LastInsertId:
Https://www.devart.com/unidac/docs/inde ... sertid.htm

StefanDWC
Posts: 24
Joined: Mon 22 May 2017 08:42

Re: MS SQL Azure, last autoinc value with TUniTable/TUniQuery

Post by StefanDWC » Sun 28 May 2017 10:06

Thanks for reply.
From your link:
Can be used with MySQL and PostgreSQL servers to get the value of the ID field after executing INSERT statement.
But, i use SQL Server and Azure, where the property is always zero.
As long i use TUniQuery like TUniTable, only with additional SQL filters, have i a solution (over the DoAfterPost methode) which work with most of my tables where i have a default identity field which have always the same name.

However, i would appreciate a native solution from your side.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: MS SQL Azure, last autoinc value with TUniTable/TUniQuery

Post by azyk » Fri 16 Jun 2017 10:13

Your solution is correct and we cannot propose anything better.

Post Reply