Board index » delphi » How to know if the key violation is in primary or secondary indexes

How to know if the key violation is in primary or secondary indexes

Hi:

I'm using the folowing code in the OnPostError event of the Table to
handle primary key violation exception and shows a friendly message
(according the current module). But now I need to know if this
exception occurs in Primary Key or in a Secondary Key (unique flag is
true). The exception gernerated seems the same and the only thing I
saw different is exception message. Is there any way to know if how
index generated this exception ? Note: I'm using Paradox 7 Tables.

  if (E is EDBEngineError) And ((E as
EDBEngineError).Errors[0].Errorcode=dbErrKeyViol) Then
  Begin
    BoxAviso(sErrCadExamCodDupl);
    Abort;
  End;

Thanks in advance,

Marcelo Gomes da Costa
m...@cwb.matrix.com.br
unic...@cwb.matrix.com.br
http://www.cwb.matrix.com.br/unicode

 

Re:How to know if the key violation is in primary or secondary indexes


Quote
>> But now I need to know if this exception occurs in Primary Key or in a Secondary Key (unique flag is
>>true)

A solution { when cached updates are not being used } is to check for existing key values
before the record is posted...

From either the TDataset.OnBeforePost or TField.OnValidate event handler,  execute a TQuery that selects
existing records that have the key values that the user is attempting to post...

If the query result is not empty.. then the key aleady exists....

Otherwise, I believe we're stuck with parsing through the message text to find name
of the offending field.

===
Bill

Re:How to know if the key violation is in primary or secondary indexes


Thanks,

--
Marcelo Gomes da Costa
m...@cwb.matrix.com.br
unic...@cwb.matrix.com.br
http://www.cwb.matrix.com.br/unicode

Other Threads