ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/examples/dbInfo/Unit1.pas
Revision: 263
Committed: Thu Dec 6 15:55:01 2018 UTC (5 years, 4 months ago) by tony
Content type: text/x-pascal
File size: 5919 byte(s)
Log Message:
Release 2.3.2 committed

File Contents

# Content
1 (*
2 * IBX For Lazarus (Firebird Express)
3 *
4 * The contents of this file are subject to the Initial Developer's
5 * Public License Version 1.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy
7 * of the License here:
8 *
9 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 *
11 * Software distributed under the License is distributed on an "AS
12 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 * implied. See the License for the specific language governing rights
14 * and limitations under the License.
15 *
16 * The Initial Developer of the Original Code is Tony Whyman.
17 *
18 * The Original Code is (C) 2015 Tony Whyman, MWA Software
19 * (http://www.mwasoftware.co.uk).
20 *
21 * All Rights Reserved.
22 *
23 * Contributor(s): ______________________________________.
24 *
25 *)
26
27 unit Unit1;
28
29 {$mode objfpc}{$H+}
30
31 interface
32
33 uses
34 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
35 IB, IBDatabase, IBDatabaseInfo, IBQuery, IBExternals;
36
37 type
38
39 { TForm1 }
40
41 TForm1 = class(TForm)
42 IBDatabase1: TIBDatabase;
43 IBDatabaseInfo1: TIBDatabaseInfo;
44 IBTransaction1: TIBTransaction;
45 Memo1: TMemo;
46 TableNameLookup: TIBQuery;
47 procedure FormShow(Sender: TObject);
48 procedure IBDatabase1AfterConnect(Sender: TObject);
49 private
50 procedure AddPerfStats(Heading: string; stats: TStrings);
51 { private declarations }
52 procedure ShowBoolValue(aValue: Long; WhenTrue, WhenFalse: string);
53 procedure ShowStrings(aCaption: string; List: TStrings);
54 function HexString(s: AnsiString): string;
55 public
56 { public declarations }
57 end;
58
59 var
60 Form1: TForm1;
61
62 implementation
63
64 {$R *.lfm}
65
66 { TForm1 }
67
68 procedure TForm1.FormShow(Sender: TObject);
69 begin
70 Memo1.Lines.Clear;
71 repeat
72 try
73 IBDatabase1.Connected := true;
74 except
75 on E:EIBClientError do
76 begin
77 Close;
78 Exit
79 end;
80 On E:Exception do
81 MessageDlg(E.Message,mtError,[mbOK],0);
82 end;
83 until IBDatabase1.Connected;
84 end;
85
86 procedure TForm1.IBDatabase1AfterConnect(Sender: TObject);
87 begin
88 IBTransaction1.Active := true;
89 TableNameLookup.Active := true;
90 Memo1.Lines.Add('Authentication Method = '+ IBDatabase1.AuthenticationMethod);
91 Memo1.Lines.Add('Remote Protocol = ' + IBDatabase1.RemoteProtocol);
92 Memo1.Lines.Add('Attachment SQLDialect = ' + IntToStr(IBDatabase1.DBSQLDialect));
93 with IBDatabaseInfo1 do
94 begin
95 Memo1.Lines.Add('Firebird Library Pathname = ' + IBDatabase1.FirebirdAPI.GetFBLibrary.GetLibraryFilePath);
96 Memo1.Lines.Add('DB SQLDialect = ' + IntToStr(DBSQLDialect));
97 Memo1.Lines.Add('Allocation = ' + IntToStr(Allocation));
98 Memo1.Lines.Add('Base Level = ' + IntToStr(BaseLevel));
99 Memo1.Lines.Add('DB File Name = ' + DBFileName);
100 Memo1.Lines.Add('DB Site Name = ' + DBSiteName);
101 Memo1.Lines.Add('DB Implementation No = ' + IntToStr(DBImplementationNo));
102 Memo1.Lines.Add('Database Created: ' + DateTimeToStr(DateDBCreated));
103 Memo1.Lines.Add('DB Implementation Class = ' + IntToStr(DBImplementationClass));
104 ShowBoolValue(NoReserve, 'No Space Reserved','Space is Reserved');
105 Memo1.Lines.Add('ODS Minor Version = ' + IntToStr(ODSMinorVersion));
106 Memo1.Lines.Add('ODS Major Version = ' + IntToStr(ODSMajorVersion));
107 Memo1.Lines.Add('Page Size = ' + IntToStr(PageSize));
108 Memo1.Lines.Add('Version = ' + Version);
109 Memo1.Lines.Add('Current Memory = ' + IntToStr(CurrentMemory));
110 ShowBoolValue(ForcedWrites,'Forced Writes Enabled','Forced Writes Disabled');
111 Memo1.Lines.Add('Max Memory = ' + IntToStr(MaxMemory));
112 Memo1.Lines.Add('Number of Buffers = ' + IntToStr(NumBuffers));
113 Memo1.Lines.Add('Sweep Interval = ' + IntToStr(SweepInterval));
114 ShowStrings('User Names',UserNames);
115 Memo1.Lines.Add('Fetches = ' + IntToStr(Fetches));
116 Memo1.Lines.Add('Marks = ' + IntToStr(Marks));
117 Memo1.Lines.Add('Reads = ' + IntToStr(Reads));
118 Memo1.Lines.Add('Writes = ' + IntToStr(Writes));
119 if ODSMajorVersion >= 12 then
120 begin
121 Memo1.Lines.Add('Pages Free = ' + IntToStr(PagesFree));
122 Memo1.Lines.Add('Pages Used = ' + IntToStr(PagesUsed));
123 end;
124 Memo1.Lines.Add('Transaction Count = ' + IntToStr(TransactionCount));
125 AddPerfStats('Backout Count',BackoutCount);
126 AddPerfStats('Delete Count',DeleteCount);
127 AddPerfStats('Expunge Count',ExpungeCount);
128 AddPerfStats('Insert Count',InsertCount);
129 AddPerfStats('Purge Count',PurgeCount);
130 AddPerfStats('Read Idx Count',ReadIdxCount);
131 AddPerfStats('Read Seq Count',ReadSeqCount);
132 AddPerfStats('Update Count',UpdateCount);
133 Memo1.Lines.Add('');
134 ShowBoolValue(ReadOnly,'Database is Read Only','Database is Read/Write');
135 Memo1.Lines.Add('Hex Dump of Database Page 100:');
136 Memo1.Lines.Add(HexString(GetDatabasePage(100)));
137 end;
138 end;
139
140 procedure TForm1.ShowBoolValue(aValue: Long; WhenTrue, WhenFalse: string);
141 begin
142 if aValue <> 0 then
143 Memo1.Lines.Add(WhenTrue)
144 else
145 Memo1.Lines.Add(WhenFalse);
146 end;
147
148 procedure TForm1.ShowStrings(aCaption: string; List: TStrings);
149 var s: string;
150 i: integer;
151 begin
152 s := aCaption + ': ';
153 for i := 0 to List.Count - 1 do
154 begin
155 if i > 0 then
156 s := s + ', ';
157 s := s + List[i];
158 end;
159 Memo1.Lines.Add(s);
160 end;
161
162 function TForm1.HexString(s: AnsiString): string;
163 var i: integer;
164 begin
165 Result := '';
166 for i := 1 to length(s) do
167 Result += Format('%x ',[byte(s[i])]);
168 end;
169
170 procedure TForm1.AddPerfStats(Heading: string;
171 stats: TStrings);
172 var i: integer;
173 begin
174 with Memo1.Lines do
175 begin
176 if stats.count = 0 then exit;
177 Add('');
178 Add(Heading);
179 for i := 0 to stats.Count - 1 do
180 begin
181 if TableNameLookup.Locate('RDB$RELATION_ID',stats.Names[i],[]) then
182 Add(' ' + TableNameLookup.FieldByName('RDB$RELATION_NAME').AsString + ' = ' + stats.ValueFromIndex[i]);
183 end;
184 end;
185 end;
186
187
188 end.
189