childwin.pas
来自「MysqlFront的源码」· PAS 代码 · 共 2,085 行 · 第 1/5 页
PAS
2,085 行
tn := tndb.getFirstChild;
for i:=0 to tndb.Count -1 do begin
if Tabellenliste.Selected.Caption = tn.Text then
begin
DBTree.Selected := tn;
PageControl1.ActivePage := SheetData;
viewdata(self);
break;
end;
tn := tndb.GetNextChild(tn);
end;
end;
procedure TMDIChild.TabelleLeeren(Sender: TObject);
var
t : TStringList;
i : Integer;
begin
// Empty Table(s)
if Tabellenliste.SelCount = 0 then
exit;
t := TStringlist.Create;
with Tabellenliste do
for i:=0 to Items.count-1 do
if Items[i].Selected then
t.add(Items[i].Caption);
if MessageDlg('Empty ' + inttostr(t.count) + ' Table(s) ?' + crlf + '(' + implodestr(', ', t) + ')', mtConfirmation, [mbok,mbcancel], 0) <> mrok then
exit;
Screen.Cursor := crSQLWait;
for i:=0 to t.count-1 do
ExecQuery( 'DELETE FROM ' + mainform.mask(t[i]) );
ShowDBProperties(self);
Screen.Cursor := crDefault;
end;
procedure TMDIChild.TabelleLoeschen(Sender: TObject);
var
i,j : Integer;
tn, tndb : TTreeNode;
t : TStringList;
begin
// Drop Table(s)
t := TStringlist.Create;
if (Sender as TComponent).Name = 'PopupMenuDropTable' then begin
// delete-command was sended by dbtree-popupmenu:
t.add(mainform.mask(ItemToDrop.Parent.text) + '.' + mainform.mask(ItemToDrop.text));
end
else with Tabellenliste do begin
// delete-command was sended by tabellenliste-popupmenu:
for i:=0 to Items.count-1 do
if Items[i].Selected then
t.add(mainform.mask(Items[i].Caption));
if t.count = 0 then
exit;
end;
if MessageDlg('Drop ' + inttostr(t.count) + ' Table(s) ?' + crlf + '(' + implodestr(', ', t) + ')', mtConfirmation, [mbok,mbcancel], 0) <> mrok then
exit;
Screen.Cursor := crSQLWait;
ExecQuery( 'DROP TABLE ' + implodestr(', ', t) );
if DBTree.Selected.Level = 1 then tndb := DBTree.Selected
else if DBTree.Selected.Level = 2 then tndb := DBTree.Selected.Parent
else exit;
for i:=0 to t.count-1 do begin
// delete it in dbtree too...
tn := tndb.getFirstChild;
for j:=0 to tndb.Count -1 do begin
if t[i] = tn.Text then begin
tn.Delete;
break;
end;
tn := tndb.GetNextChild(tn);
end;
end;
ShowDBProperties(self);
Screen.Cursor := crDefault;
end;
procedure TMDIChild.DBLoeschen(Sender: TObject);
var
tndb_ : TTreeNode;
begin
// Drop DB?
if (Sender as TComponent).Name = 'PopupmenuDropDatabase' then // drop cmd from popupmenu
tndb_ := itemtodrop
else case DBTree.Selected.Level of // drop cmd from toolbar
1 : tndb_ := DBTree.Selected;
2 : tndb_ := DBTree.Selected.Parent;
3 : tndb_ := DBTree.Selected.Parent.Parent;
end;
if MessageDlg('Drop Database '+tndb_.Text+'?' + crlf + crlf + 'WARNING: You will lose all tables in database '+tndb_.Text+'!', mtConfirmation, [mbok,mbcancel], 0) <> mrok then
abort;
Screen.Cursor := crSQLWait;
try
ExecQuery( 'DROP DATABASE ' + tndb_.Text );
tndb_.Delete;
except
MessageDLG('Dropping failed.'+crlf+'Maybe '''+tndb_.Text+''' is not a valid database-name.', mtError, [mbOK], 0)
end;
Screen.Cursor := crDefault;
end;
procedure TMDIChild.ShowVariablesAndProcesses(Sender: TObject);
var
v : String[10];
i : Integer;
n : TListItem;
versions : TStringList;
begin
// Variables und Process-List aktualisieren
Screen.Cursor := crSQLWait;
Variabelliste.Items.BeginUpdate;
Variabelliste.Items.Clear;
// VERSION
v := GetVar( 'SELECT VERSION()' );
versions := explode( '.', v );
mysql_version := MakeInt(versions[0]) * 10000 + MakeInt(versions[1]) * 100 + MakeInt(versions[2]);
strHostRunning := ZConn.HostName + ' running MySQL-Version ' + v + ' / Uptime: ';
// VARIABLES
ZQuery3.Close;
ZQuery3.SQL.Clear;
ZQuery3.SQL.Add( 'SHOW VARIABLES' );
ZQuery3.Open;
ZQuery3.First;
for i:=1 to ZQuery3.RecordCount do
begin
n := VariabelListe.Items.Add;
n.Caption := ZQuery3.Fields[0].AsString;
n.Subitems.Add( ZQuery3.Fields[1].AsString );
ZQuery3.Next;
end;
uptime := 0;
// STATUS
ZQuery3.Close;
ZQuery3.SQL.Clear;
ZQuery3.SQL.Add( 'SHOW STATUS' );
ZQuery3.Open;
ZQuery3.First;
for i:=1 to ZQuery3.RecordCount do
begin
n := VariabelListe.Items.Add;
n.Caption := ZQuery3.Fields[0].AsString;
n.Subitems.Add( ZQuery3.Fields[1].AsString );
if lowercase( ZQuery3.Fields[0].AsString ) = 'uptime' then
uptime := strToIntDef(ZQuery3.Fields[1].AsString, 0);
ZQuery3.Next;
end;
Timer1Timer(self);
Timer1.OnTimer := Timer1Timer;
VariabelListe.Items.EndUpdate;
TabSheet6.Caption := 'Variables (' + inttostr(VariabelListe.Items.Count) + ')';
Screen.Cursor := crDefault;
ShowProcesslist(self); // look at next procedure
end;
procedure TMDIChild.ShowProcessList(sender: TObject);
var
i,j : Integer;
n : TListItem;
begin
// PROCESSLIST
Screen.Cursor := crSQLWait;
try
ProcessListe.Items.BeginUpdate;
ProcessListe.Items.Clear;
ZQuery3.Close;
ZQuery3.SQL.Clear;
ZQuery3.SQL.Add( 'SHOW PROCESSLIST' );
ZQuery3.Open;
ZQuery3.First;
for i:=1 to ZQuery3.RecordCount do
begin
n := ProcessListe.Items.Add;
n.Caption := ZQuery3.Fields[0].AsString;
if CompareText( ZQuery3.Fields[4].AsString, 'Killed') = 0 then
n.ImageIndex := 1 // killed
else
n.ImageIndex := 0; // running
for j := 1 to 7 do
n.Subitems.Add(ZQuery3.Fields[j].AsString);
ZQuery3.Next;
end;
ZQuery3.Close;
ProcessListe.Items.EndUpdate;
TabSheet7.Caption := 'Process-List (' + inttostr(ProcessListe.Items.Count) + ')';
except
LogSQL('# Error on loading process-list!');
end;
ProcessListe.Items.EndUpdate;
Screen.Cursor := crDefault;
end;
procedure TMDIChild.ProcessListeChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
Kill1.Enabled := (ProcessListe.Selected <> nil) and (PageControl2.ActivePage = TabSheet7);
end;
procedure TMDIChild.KillProcess(Sender: TObject);
var t : boolean;
begin
if ProcessListe.Selected.Caption = GetVar( 'SELECT CONNECTION_ID()' ) then
MessageDlg('Fatal: Better not kill my own Process...', mtError, [mbok], 0)
else begin
t := TimerProcessList.Enabled;
TimerProcessList.Enabled := false; // prevent av (processliste.selected...)
if MessageDlg('Kill Process '+ProcessListe.Selected.Caption+'?', mtConfirmation, [mbok,mbcancel], 0) = mrok then
begin
ExecQuery( 'KILL '+ProcessListe.Selected.Caption );
ShowVariablesAndProcesses(self);
end;
TimerProcessList.Enabled := t; // re-enable autorefresh timer
end;
end;
procedure TMDIChild.PageControl2Change(Sender: TObject);
begin
ProcessListeChange(self, nil, TItemChange(self));
end;
procedure TMDIChild.ExecSQLClick(Sender: TObject; Selection: Boolean=false; CurrentLine: Boolean=false);
var
SQL : TStringList;
i, rowsaffected : Integer;
SQLstart, SQLend, SQLscriptstart,
SQLscriptend : Integer;
SQLTime : Real;
fieldcount, recordcount : Integer;
begin
// Execute user-defined SQL
// if SynMemo3.Focused then
// exit;
if length(trim(SynMemo1.Text)) = 0 then
exit;
TRY
showstatus('Initializing SQL...', 2, 51);
Mainform.ExecuteQuery.Enabled := false;
Mainform.ExecuteSelection.Enabled := false;
if ActualDatabase <> '' then
zconn.Database := ActualDatabase;
ZQuery1.Active := false;
ZQuery1.DisableControls;
if CurrentLine then
SQL := parseSQL(SynMemo1.LineText) // Run current line
else begin
if Selection then
SQL := parsesql(SynMemo1.SelText) else // Run selection
SQL := parsesql(SynMemo1.Text); // Run all
end;
if SQL.Count > 1 then
SQLscriptstart := GetTickCount;
rowsaffected := 0;
ProgressBarQuery.Max := SQL.Count;
ProgressBarQuery.Position := 0;
ProgressBarQuery.show;
showstatus('Executing SQL...', 2, 51);
for i:=0 to SQL.Count-1 do begin
ProgressBarQuery.Stepit;
Application.ProcessMessages;
if sql[i] = '' then
continue;
// open last query with data-aware:
Label4.Caption := '';
ZQuery1.Close;
ZQuery1.SQL.Clear;
ZQuery1.SQL.Add(SQL[i]);
// set db-aware-component's properties..
DBMemo1.DataField := '';
DBMemo1.DataSource := DataSource2;
ZDBImage1.DataField := '';
ZDBImage1.DataSource := DataSource2;
// ok, let's rock
SQLstart := GetTickCount;
try
if (StrCmpBegin('select', lowercase(SQL[i])) or
StrCmpBegin('show', lowercase(SQL[i])) or
StrCmpBegin('desc', lowercase(SQL[i])) or
StrCmpBegin('explain', lowercase(SQL[i])) or
StrCmpBegin('describe', lowercase(SQL[i]))) then
begin
ZQuery1.Open;
fieldcount := ZQuery1.Fieldcount;
recordcount := ZQuery1.Recordcount;
end
else
begin
LogSQL(ZQuery1.SQL.GetText);
ZQuery1.ExecSql;
fieldcount := 0;
recordcount := 0;
end;
except
on E:Exception do
begin
if ToolButtonStopOnErrors.Down or (i=SQL.Count-1) then begin
Screen.Cursor := crdefault;
MessageDLG(E.Message, mtError, [mbOK], 0);
ProgressBarQuery.hide;
Mainform.ExecuteQuery.Enabled := true;
Mainform.ExecuteSelection.Enabled := true;
break;
end;
end;
end;
rowsaffected := rowsaffected + ZQuery1.RowsAffected;
SQLend := GetTickCount;
SQLTime := (SQLend - SQLstart) / 1000;
Label4.Caption :=
IntToStr(rowsaffected) + ' row(s) affected. ' +
inttostr(fieldcount) + ' field(s), ' +
inttostr(recordcount) + ' record(s) in last resultset. ' +
'Time: '+floattostrf(SQLTime, ffFixed, 18, 2)+' sec.';
end;
ProgressBarQuery.hide;
Mainform.ExecuteQuery.Enabled := true;
Mainform.ExecuteSelection.Enabled := true;
// count chars:
SynMemo1.OnChange(self);
if SQL.Count > 1 then begin
SQLscriptend := GetTickCount;
SQLTime := (SQLscriptend - SQLscriptstart) / 1000;
Label4.Caption := Label4.Caption + ' Script-Time: ' + floattostrf(SQLTime, ffFixed, 18, 2)+' sec.';
end;
FINALLY
ZQuery1.EnableControls;
// resize all columns, if they are more wide than Mainform.DefaultColWidth
if Mainform.DefaultColWidth <> 0 then
for i:=0 to DBGrid2.Columns.count-1 do
if DBGrid2.Columns[i].Width > Mainform.DefaultColWidth then
DBGrid2.Columns[i].Width := Mainform.DefaultColWidth;
DBGridColenter(dbgrid2);
Screen.Cursor := crdefault;
showstatus('Ready', 2);
END;
end;
procedure TMDIChild.FeldListeChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
// Feldeigenschaften anzeigen
if FeldListe.Selected <> nil then
with Feldliste.Selected do begin
Toolbutton9.Enabled := True;
DropField1.Enabled := True; //drop field
MenuEditField.Enabled := true;
ButtonEditField.enabled := true;
end else begin
Toolbutton9.Enabled := False;
DropField1.Enabled := false; //drop field
MenuEditField.Enabled := false;
ButtonEditField.enabled := false;
end;
end;
procedure TMDIChild.DropField(Sender: TObject);
var
tn : TTreeNode;
begin
// Feld l鰏chen
if Feldliste.Items.Count = 1 then
begin
if MessageDlg('Can''t drop the last Field - drop Table '+ActualTable+'?', mtConfirmation, [mbok,mbcancel], 0) = mrok then
begin
Screen.Cursor := crSQLWait;
ExecQuery( 'DROP TABLE '+mainform.mask(ActualTable) );
tn := DBTree.Selected;
DBTree.Selected := DBTree.Selected.Parent;
tn.Destroy;
ShowDBProperties(self);
Screen.Cursor := crDefault;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?