Board index » delphi » Need KeyViol Exception Handler Tips- 1.0 & Pdox

Need KeyViol Exception Handler Tips- 1.0 & Pdox

Does anyone have a clean beforepost or other code snippet which detects
Paradox table key violations before the BDE default one? Would appreciate
tips, or is there an example in the demos?
Thanks- Larry Ward, MD
llw...@primenet.com

 

Re:Need KeyViol Exception Handler Tips- 1.0 & Pdox


Quote
llw...@primenet.com (larry ward) wrote:
>Does anyone have a clean beforepost or other code snippet which detects
>Paradox table key violations before the BDE default one? Would appreciate
>tips, or is there an example in the demos?
>Thanks- Larry Ward, MD
>llw...@primenet.com

Simple work around I've used :

Place a TQuery on the form, have a string resource :
SELECT TABLE.FIELD FROM TABLE WHERE TABLE.%s = %s
 I use this to check duplication of two fields, and format the string
with the necessary field and parameters.
After opening the query, with unidirectional set to true, if the
RecordCount > 0, then the item already exists, and then I raise
an exception - this stops the table from attempting to post the
duplicate key before the BDE gets upset

Re:Need KeyViol Exception Handler Tips- 1.0 & Pdox


Quote
llw...@primenet.com (larry ward) wrote:
>Does anyone have a clean beforepost or other code snippet which detects
>Paradox table key violations before the BDE default one? Would appreciate
>tips, or is there an example in the demos?
>Thanks- Larry Ward, MD
>llw...@primenet.com

You may catch key violation from any databases like that :

uses BDE;

function ExecSQLKeyViol(Q : tQuery) : boolean;
begin
  try
    Q.ExecSQL;
    result := false;
  except
    on e : EDBEngineError do begin
      if e.Errors[0].ErrorCode<>DBIERR_KEYVIOL then
        raise;
      Result := true;
    end;
  end;
end;

Dmitriy Anisimkov ,Russia, Omsk,  e-mail  t...@quadrat.omsk.su

Other Threads