Page 1 of 1

check for duplicate before post

Posted: 10.05.2010, 09:30
by btray77
How would I check for duplicates before posting data?

I've been given this via stackoverflow but not sure how to implement it.

update or insert into KEYWORDLIST (KEYWORD) values(:KEYWORD) matching(KEYWORD)

I was guessing I would do this onNewRecord or BeforePost...

Thank you

-Brad

Using: D2K9, Zeos 7, Firebird 2.1

Posted: 10.05.2010, 10:11
by seawolf
In my opinion you can:

1. write a stored procedure where you call a select which verify is this record already exists. If exists you don't need to do the update/insert
2. write that select in your Delphi code
3. insert the sql code above in a try/except .. if you receive an error obviously record already existed

Posted: 12.05.2010, 01:09
by btray77
Any chance on some demo code on how I would do that, or a tutorial suggestion? I've got very little experience on how to do this.

Thanks

-Brad

Posted: 12.05.2010, 09:54
by trupka
btray77,
FB2.1 supports UPDATE OR INSERT statement so this is quite easy to solve (see attached example).
Take a closer look at ZUpdateSQL1.InsertSQL|ModifySQL props.

Posted: 13.05.2010, 02:20
by btray77
Thank you for taking the time to do this demo.

-Brad

Posted: 13.05.2010, 03:02
by btray77
After looking at the demo.

1. I need to have a ZUpdateSQL component
2. I need to setup the params. (Not 100% sure on how these params work, but I think i've got it.)
3. Setup the SQL for the insert/update/delete/refresh using the params

The one thing the demo doesn't do is update the dataset after the edit is completed. How would I go about doing that? the best way? I'm guessing the ZQuery1AfterPost procedure and then call ZQuery1.Refresh;

Thanks

-Brad

Posted: 13.05.2010, 11:41
by trupka
btray77 wrote:After looking at the demo.
? I'm guessing the ZQuery1AfterPost procedure and then call ZQuery1.Refresh;
Yes, something like

Code: Select all

procedure TForm1.ZQuery1AfterPost(DataSet: TDataSet);
begin
	DataSet.DisableControls;
    try
    	DataSet.Refresh;
    finally
	    DataSet.EnableControls;
    end;
end;

Posted: 13.05.2010, 12:54
by btray77
Thanks for the info

-Brad