Duplicate key / PostError
Posted: Thu 11 Jun 2009 22:06
hi,
My MYSQL INNODB table contains 2 fields called :
- city_id (int / autoinc)
- city_name (var)
There's a unique index on city_name. Because i would like to prevent
duplicate city names i have a OnPostError event for this query with the code below. Within my datamodule i defined const. like this:
const
{Declare constants we're interested in}
ER_DUP_KEY = 1062;
The OnPostError event has this code:
For some reason the message above is not showed and the applications
terminates after entering a duplicate name.
How to prevent this and is there some other code to prevent duplicates
or make the above code working.
Regards Peter
My MYSQL INNODB table contains 2 fields called :
- city_id (int / autoinc)
- city_name (var)
There's a unique index on city_name. Because i would like to prevent
duplicate city names i have a OnPostError event for this query with the code below. Within my datamodule i defined const. like this:
const
{Declare constants we're interested in}
ER_DUP_KEY = 1062;
The OnPostError event has this code:
Code: Select all
procedure TdmTables.qry_cityPostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
if (E is EMyError) then begin
if (EMyError(E).ErrorCode=ER_DUP_KEY) then begin
Application.MessageBox('It's not allowed to enter duplicate names!.', 'Warning', MB_OK+MB_ICONEXCLAMATION+MB_DEFBUTTON1+MB_APPLMODAL);
dmTables.qry_city.cancel;
Abort;
end;
end;
end;terminates after entering a duplicate name.
How to prevent this and is there some other code to prevent duplicates
or make the above code working.
Regards Peter