MySQL Forums
Forum List  »  Delphi

Duplicate key
Posted by: Peter van Mierlo
Date: June 13, 2009 11:53AM

hi,

I use Delphi 6 / MySQL 5.x / DevArt MyDAC components. The tables is a type InnoDB and i would like to prevent duplicate values on a table. There's a unique index on a fieldname item_name. To prevent dupicates values i used a OnPostError with the following code below. In the datamodule i created a const. like this:

const
{Declare constants we're interested in}
ER_DUP_KEY = 1062;

The code below is the OnPostError

if (E is EMyError) then begin
if (EMyError(E).ErrorCode=ER_DUP_KEY) then begin
Application.MessageBox('De door u ingevoerde waarde bestaat reeds'+#10+'en mag niet dubbel worden geregistreerd!.', 'Mededeling', MB_OK+MB_ICONEXCLAMATION+MB_DEFBUTTON1+MB_APPLMODAL);
dmTables.qry_item.cancel;
Action := daAbort;
end;
end;

For some reasons when entering a duplicate item_name in this example the application terminates and i can't figure out why or where. Is this procedure correct, is the const. value correct or are there other methods to prevent dupplicates.

Regards Peter

Options: ReplyQuote


Subject
Written By
Posted
Duplicate key
June 13, 2009 11:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.