1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
| const cRDefault = 'SELECT'; cRUsage = 'SELECT, INSERT, UPDATE, DELETE'; cRMainUsage = 'USAGE'; cRAdmin = 'ALL PRIVILEGES';
function MakeRights(SecurityLevel: integer; var vRGrant: ShortStr): ShortStr; function DBChanges(Connection: TZConnection; SQLString: string): boolean;
implementation
function MakeRights(SecurityLevel: integer; var vRGrant: ShortStr): ShortStr; begin vRGrant := ' '; case SecurityLevel of 0: Result := cRUsage; 1: Result := cRMainUsage; 2: begin Result := cRAdmin; vRGrant := ' WITH GRANT OPTION'; end end; end;
function DBChanges(Connection: TZConnection; SQLString: string): boolean; var Query: TZQuery; begin Query := TZQuery.Create(Application);
Query.Connection := Connection; Query.SQL.Clear; Query.SQL.Add(SQLString);
try Query.ExecSQL; Result := TRUE; except Result := FALSE; end;
Query.Free; end;
procedure TfrmMain_frameAdmin.btnCreateUserClick(Sender: TObject); var SQLString: string; RGrant, Right: ShortStr; begin Right := MakeRights(rgRights.ItemIndex, RGrant);
if (edtUser.Text <> '')then begin if ((edtPwd1.Text <> '') and not(edtPwd1.Text <> edtPwd2.Text)) then begin SQLString := 'GRANT '+ Right + ' ON rma.* TO '''+edtUser.Text+'''@''%'' IDENTIFIED BY ''' + edtPwd1.Text +''''+ RGrant; end else if ((edtPwd1.Text = '') and (edtPwd2.Text = '')) then begin SQLString := 'GRANT '+ Right + ' ON rma.* TO '''+edtUser.Text+'''@''%' + RGrant; end else begin MessageDlg('Die Passwörter sind nicht identisch', mtError, [mbOk],0); Exit; end; end else begin MessageDlg('Sie haben keinen Benutzernamen eingegeben!', mtError, [mbOk],0); Exit; end;
if not DBChanges(SQLConnection, SQLString) then MessageDlg('Beim Anlegen des Benutzers "'+edtUser.Text+'" ist ein SQL-Fehler aufgetreten.', mtError, [mbOK], 0); |