Jump to content
Nathan Wild

Refresh Current Record To Access Value Of Newly Inserted AutoInc Field

Recommended Posts

I am trying to append records to a pair of tables in a master/detail relationship.  The master dataset is a writable FDQuery with an AutoInc key field.  When I post to this dataset the autoinc field has a value of -1.  I want to go on and write out detail records, but nothing I've tried will give me the actual value for autoinc field in the newly posted master dataset.

 

I am not able to call FDQuery.Refesh() as it gives me a "SQLBind Parameter has not been called for parameter" error (I've posted about this before and apparently it is a known bug).

 

FDQuery.RefreshRecord() gives me an error "[FireDAC][DApt]-400. Fetch command fetched [0] instead of [1] record. Possible reasons: update table does not have PK or row identifier, record has been changed/deleted by another user"

 

As my master dataset is sorted by the autoinc key field, I was able to solve the issue by calling FDQuery.First() and FDQuery.Last(), but this feels wrong, so I thought I would check in and see if anyone had a suggestion for how this *SHOULD* be done?

 

Thanks in advance...

Share this post


Link to post

Usualy I use "returning" to get the value of new autoincremented field (Firebird).

Share this post


Link to post
1 hour ago, Ruslan said:

Usualy I use "returning" to get the value of new autoincremented field (Firebird).

What do you mean by "returning"?

Share this post


Link to post

"returning" mentioned here is part of sql command, it >returns values of auto id and other expressions.

 

Maybe this is not available in Pervasive. Here is firebird documentation explaining it:

http://www.firebirdsql.org/refdocs/langrefupd21-insert.html

 

This is of course a solution coming from the database side. Firedac offers client side solutions.

Share this post


Link to post
On 4/12/2019 at 1:20 PM, Nathan Wild said:

I am using Pervasive.

AFAIK, Pervasive is not a directly supported database in FireDAC (only via ODBC). Therefore it may be necessary to handle those AutoInc fields manually as described in the documentation.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×