Board index » delphi » Newbie: Translating error messages (Key violations, etc)

Newbie: Translating error messages (Key violations, etc)

I set the primary key for my customer table, and when inserting a duplicate
record, I get a message like "violation of PRIMARY or UNIQUE KEY constraint
"INTEG_23" on table "CUST_MST"". How can I translate this or get the code to
handle the error and show some more meaningful message in my language?
 

Re:Newbie: Translating error messages (Key violations, etc)


The definition of a primary key is a column that contains a value that will
never (cannot) be duplicated. If you want to be able to insert duplicate
values for the column you have chosen as your primary key, you will need to
either remove the key, or choose a different column as your primary key.
This behavior is the same with a Unique constraint.

Byron Sturtevant
RIFOCS Corporation

Quote
"damian marquez" <dmarque...@hotmail.com> wrote in message

news:3a7441f8_1@dnews...
Quote
> I set the primary key for my customer table, and when inserting a
duplicate
> record, I get a message like "violation of PRIMARY or UNIQUE KEY
constraint
> "INTEG_23" on table "CUST_MST"". How can I translate this or get the code
to
> handle the error and show some more meaningful message in my language?

Re:Newbie: Translating error messages (Key violations, etc)


Hi!

I don't know if this is the best method, but what I did was something like this:

with Query do
 begin
    StartTransaction;
    try
       ApplyUpdates; {try to write the updates to the database};
       Commit; {on success, commit the changes};
    except
       on e: EDBEngineError do
       begin
          MiError(E);   {this is my procedure where I handle error messages}
          Rollback; {on failure, undo the changes};
          exit;
       end;
    end;
    CommitUpdates; {on success, clear the cache}
 end;

const
  {Declare constants you're interested in:}
  eKeyViol = 9729;
  eRequiredFieldMissing = 9732;
  eForeignKey = 9733;
  eDetailsExist = 9734;
  eLocked       = 10241;
  eUnlockedfailed = 10242;
  eFileLocked   = 10245;
  eAlreadyLocked = 10247;
  eReadOnly = 10763;
  eNoUpdate = 13062;

// and the MiError procedure looks like this:
procedure TError.MiError(E: EDataBaseError);
var
   iDBIError: Integer;
begin
  if (E is EDBEngineError) then
  begin
    iDBIError := (E as EDBEngineError).Errors[0].Errorcode;
    case iDBIError of
      eRequiredFieldMissing:
            begin
               MessageDlg('No deje campos vacos', mtError, [mbOK], 0);
            end;
      eKeyViol:
            begin
               MessageDlg('No duplique registros', mtError, [mbOK], 0);
            end;
      eDetailsExist:
            begin
               MessageDlg('Registro existente en otra tabla', mtError, [mbOK],
0);
            end;
      eForeignKey:
            begin
               MessageDlg('El registro existe en otra tabla o uno de sus valores
no es vlido', mtError, [mbOK], 0);
            end;
      eReadOnly:
            begin
               MessageDlg('Tabla de solo lectura', mtError, [mbOK], 0);
            end;
      eNoUpdate:
            begin
               MessageDlg('No se pueden actualizar los datos', mtError, [mbOK],
0);
            end;
    else
       begin
          ShowMessage('Mensaje: '+ (E as EDBEngineError).Errors[(E as
EDBEngineError).ErrorCount -1].Message +
             '  Codigo: '+ IntToStr((E as EDBEngineError).Errors[(E as
EDBEngineError).ErrorCount -1].ErrorCode));
       end;
    end;
  end;
end;

Hope that this example can help you

Best regards
RAH

Re:Newbie: Translating error messages (Key violations, etc)


obviously you have to make some changes mainly if you are using IBX, but this is
the idea

Re:Newbie: Translating error messages (Key violations, etc)


Quote
"Byron Sturtevant" <byron.sturtev...@rifocs.com> wrote:
>The definition of a primary key is a column that contains a value that will
>never (cannot) be duplicated. If you want to be able to insert duplicate
>values for the column you have chosen as your primary key, you will need to
>either remove the key, or choose a different column as your primary key.
>This behavior is the same with a Unique constraint.

I Understand, Byron, I DON'T WANT the user to be able to enter a duplicate value. But if he does, it's ok that the server traps the error. What I want to do is to catch that error and show a more meaningful message...

Re:Newbie: Translating error messages (Key violations, etc)


Quote
Rogelio Argueta <rogelio_argu...@yahoo.com> wrote:
>obviously you have to make some changes mainly if you are using IBX, but this is
>the idea

Hi, Rogelio, thanks a lot, in fact I did the same in BDE (WITH paradox), but I didnt know how to do it in IBX. Really I am wondering if there is a list of the error numbers IB can give you...

Re:Newbie: Translating error messages (Key violations, etc)


Yes to the list of codes - see the IB Language Reference appendix....

--
Brent Rose
br...@voyager.co.nz

Re:Newbie: Translating error messages (Key violations, etc)


Quote
"Brent Rose" <br...@voyager.co.nz> wrote:
>Yes to the list of codes - see the IB Language Reference appendix....

I think I have to download the docs....:) thank you.

Other Threads