Ver Mensaje Individual
  #2  
Antiguo 08-12-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola mRoman.

Te pongo un ejemplo simple para que pruebes:
Código Delphi [-]
// Crea rol, usuario y lo agrega al rol
procedure TForm1.btCrearClick(Sender: TObject);
begin
  // Crear rol
  IBSQL1.Close;
  IBSQL1.SQL.Text:= 'CREATE ROLE ABCXYZ';
  try
    IBSQL1.ExecQuery;
    IBTransaction1.CommitRetaining;
  except
    raise Exception.Create('Rol existente');
  end;
  // Crear usuario
  IBSQL1.Close;
  IBSQL1.SQL.Clear;
  IBSQL1.SQL.Add('CREATE USER PEPITO PASSWORD ''1234''');
  IBSQL1.SQL.Add('FIRSTNAME ''JOSE'' MIDDLENAME ''APOLONIO'' LASTNAME ''PEREZ''');
  try
    IBSQL1.ExecQuery;
    IBTransaction1.CommitRetaining;
  except
    raise Exception.Create('Usuario existente');
  end;
  // Asignar rol al usuario
  IBSQL1.Close;
  IBSQL1.SQL.Text:= 'GRANT ABCXYZ TO PEPITO';
  IBSQL1.ExecQuery;
  IBTransaction1.CommitRetaining;
end;

// Mostrar los usuarios del rol ABCXYZ
procedure TForm1.btMostrarClick(Sender: TObject);
begin
  with IBQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT RDB$USER AS USUARIO,RDB$RELATION_NAME AS ROL');
    SQL.ADD('FROM RDB$USER_PRIVILEGES');
    SQL.Add('WHERE RDB$RELATION_NAME = ''ABCXYZ''');
    SQL.Add('ORDER BY RDB$USER');
    Open;
  end;
end;

//  Borra rol y usuario
procedure TForm1.btBorrarClick(Sender: TObject);
begin
 IBSQL1.Close;
  IBSQL1.SQL.Text:= 'DROP ROLE ABCXYZ';
  try
    IBSQL1.ExecQuery;
    IBTransaction1.CommitRetaining;
  except
    raise Exception.Create('Rol inexistente');
  end;
  
  IBSQL1.Close;
  IBSQL1.SQL.Text:= 'DROP USER PEPITO';
  try
    IBSQL1.ExecQuery;
    IBTransaction1.CommitRetaining;
  except
    raise Exception.Create('Usuario inexistente');
  end;
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 08-12-2012 a las 11:19:52.
Responder Con Cita