forked from motaz/turbobird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbinfo.pas
153 lines (130 loc) · 3.29 KB
/
dbinfo.pas
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
unit dbInfo;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons, ExtCtrls, LCLType;
type
{ TfmDBInfo }
TfmDBInfo = class(TForm)
bbClose: TBitBtn;
bbRefresh: TBitBtn;
edCreationDate: TEdit;
edConnections: TEdit;
edServerTime: TEdit;
edPageSize: TEdit;
edDBSize: TEdit;
edName: TEdit;
edODSVer: TEdit;
edCharset: TEdit;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
meClients: TMemo;
procedure bbCloseClick(Sender: TObject);
procedure bbRefreshClick(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ private declarations }
FDBIndex: Integer;
public
procedure Init(dbIndex: Integer);
{ public declarations }
end;
var
fmDBInfo: TfmDBInfo;
implementation
{$R *.lfm}
{ TfmDBInfo }
uses SysTables;
procedure TfmDBInfo.bbCloseClick(Sender: TObject);
begin
Close;
Parent.Free;
end;
procedure TfmDBInfo.bbRefreshClick(Sender: TObject);
begin
Init(FDBIndex);
end;
procedure TfmDBInfo.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
CloseAction:= caFree;
end;
procedure TfmDBInfo.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and
((key=VK_F4) or (key=VK_W)) then
begin
// Close when pressing Ctrl-W or Ctrl-F4 (Cmd-W/Cmd-F4 on OSX)
Close;
Parent.Free;
end;
end;
procedure TfmDBInfo.Init(dbIndex: Integer);
var
dbName, CreationDate, ACharSet: string;
MajorVer, MinorVer, Pages, PageSize: Integer;
ProcessList: TStringList;
dbSize: Double;
AType: string;
ServerTime: string;
ErrorMsg: string;
begin
FDBIndex:= dbIndex;
ProcessList:= TStringList.Create;
try
// Read database info
if dmSysTables.GetDatabaseInfo(dbIndex, dbName, ACharSet, CreationDate, ServerTime,
MajorVer, MinorVer, Pages, PageSize, ProcessList, ErrorMsg) then
begin
edName.Text:= dbName;
edODSVer.Text:= IntToStr(MajorVer) + '.' + IntToStr(MinorVer);
edCharset.Text:= ACharSet;
edCreationDate.Text:= CreationDate;
edPageSize.Text:= IntToStr(PageSize);
edConnections.Text:= IntToStr(ProcessList.Count);
dbSize:= Pages * PageSize;
// Display database size in readable format
if dbSize > (1024*1024*1024) then
begin
dbSize:= ((dbSize / 1024) / 1024) / 1024;
AType:= 'Giga bytes';
end
else
if dbSize > (1024*1024) then
begin
dbSize:= ((dbSize / 1024) / 1024);
AType:= 'Mega bytes';
end
else
if dbSize > 1024 then
begin
dbSize:= (dbSize / 1024);
AType:= 'Kilo bytes';
end
else
begin
AType:= 'Bytes';
end;
edDBSize.Text:= Format('%3.1n %s', [dbSize, AType]);
fmDBInfo.edServerTime.Text:= ServerTime;
meClients.Lines.Text:= ProcessList.Text;
meClients.Lines.Insert(0, '');
Show;
end
else
ShowMessage('Unable to get database information' + LineEnding +
ErrorMsg);
finally
ProcessList.Free;
end;
end;
end.