Page 1 of 1

Permissions and Messages from MyDac

Posted: Sun 27 Jan 2008 20:12
by gohjoe
With MySql, we can grant certain users certain permissions on a database or table or field. If a user tries to do something he is not supposed to do, how can we get the MyDac components to get these permission messages back to Delphi and our programs to present them to the users.
Can you give me coding examples?

Posted: Mon 28 Jan 2008 13:08
by Dimon
You can catch EMyError exceptions in try..except statements. Use EMyError.ErrorCode to know the error code.
For more information about the error code read the MySQL Reference Manual.
For example:

Code: Select all

  try
    MyTable.Post;
  except
    on E: EMyError do
      if E.ErrorCode = 1142 then  //ER_TABLEACCESS_DENIED_ERROR
        ShowMessage('Access to a server object denied.'#13#10 + 'Message: ' + E.Message)
      else
        raise;
  end;