check for duplicate before post

The alpha/beta tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.

This is a forum that will be removed once the 7.X version goes into stable!!

Moderators: gto, EgonHugeist, olehs

Locked
btray77
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 30.04.2010, 19:44

check for duplicate before post

Post 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
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post 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
btray77
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 30.04.2010, 19:44

Post 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
trupka
Expert Boarder
Expert Boarder
Posts: 140
Joined: 26.08.2007, 22:10

Post 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.
You do not have the required permissions to view the files attached to this post.
btray77
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 30.04.2010, 19:44

Post by btray77 »

Thank you for taking the time to do this demo.

-Brad
btray77
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 30.04.2010, 19:44

Post 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
trupka
Expert Boarder
Expert Boarder
Posts: 140
Joined: 26.08.2007, 22:10

Post 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;
btray77
Fresh Boarder
Fresh Boarder
Posts: 12
Joined: 30.04.2010, 19:44

Post by btray77 »

Thanks for the info

-Brad
Locked