Check for duplicates before post

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
vanmeir
Posts: 13
Joined: Thu 19 May 2011 09:34
Location: The Netherlands
Contact:

Check for duplicates before post

Post by vanmeir » Sat 06 Jul 2013 12:30

Hello,

I would like to know if there is a strategy for checking (preventing) duplicate records (or specific fields within records) before the current record will be posted?
The purpose of this is to be able to notify the user for incorrect values and keep the option for the user to cancel the edit.
Important to say is that i'm using cachedupdates mode!

Regards,

Frans

AndreyZ

Re: Check for duplicates before post

Post by AndreyZ » Mon 08 Jul 2013 09:33

Hello,

There is no built-in mechanism that allows checking of duplicate records in the CachedUpdates mode. You can use the BeforePost event to check it yourself and abort the posting in case of existence of duplicate records. Please note that the only way to cancel posting in the BeforePost event is to call the Abort method. This functionality is inherited from the TDataSet standard class. For more information, please read the BeforePost event description in the Delphi help.

vanmeir
Posts: 13
Joined: Thu 19 May 2011 09:34
Location: The Netherlands
Contact:

Re: Check for duplicates before post

Post by vanmeir » Mon 08 Jul 2013 11:17

Hello Andrey,

the problem in this case is that calls like Locate and FindKey can lead to a jump to another record.
Maybe it's better to rephrase the question: is there a method availlable to search or check for values within a dataset without changing/disturbing (the state of) the current record?

AndreyZ

Re: Check for duplicates before post

Post by AndreyZ » Tue 09 Jul 2013 08:01

To avoid changing of the current record, you should use bookmarks. Here is a code example:

Code: Select all

var
  bm: TBookmark;
begin
  bm := MSQuery.Bookmark; // save the current position
  MSQuery.Locate(KeyFields, KeyValues, Options);
  MSQuery.GotoBookmark(bm); // return to the saved position
end;

AntonPlotnikov2018
Posts: 4
Joined: Thu 01 Nov 2018 15:14

Re: Check for duplicates before post

Post by AntonPlotnikov2018 » Wed 05 Aug 2020 07:00

I have the same issue. Locate is not accepted because I should check duplicates before posting. Is this a way to scan underlying in-memory storage without changing the current record and its state?

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Check for duplicates before post

Post by Stellar » Tue 06 Oct 2020 13:51

Unfortunately, we couldn't reproduce the issue. To investigate this behavior of SDAC, please compose a small sample demonstrating the issue and send it to us, including database objects creating scripts.
You can send the sample using the contact form at our site: devart.com/company/contactform.html

Post Reply