Ver Mensaje Individual
  #3  
Antiguo 08-12-2012
Avatar de mRoman
mRoman mRoman is offline
Miembro
 
Registrado: nov 2003
Posts: 646
Reputación: 23
mRoman Va por buen camino
Gracias..

Cita:
Empezado por ecfisa Ver Mensaje
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.
Ok....gracias ecfisa, fijate que hice algo parecido, pero no me funciono....lo que veo de diferente es el componente IBTransaction1.CommitRetaining.....NO LO PUSE !!!!....será esta la causa?, probaré y les comento.

Con respecto a la version de Firebird...cual estas usando?
__________________
Miguel Román

Afectuoso saludo desde tierras mexicanas....un aguachile?, con unas "cetaseas" bien "muertas"?, VENTE PUES !!
Responder Con Cita