-
Notifications
You must be signed in to change notification settings - Fork 11
/
YOTM.DB.pas
74 lines (59 loc) · 1.42 KB
/
YOTM.DB.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
unit YOTM.DB;
interface
uses
HGM.SQLite, HGM.SQLang, System.Generics.Collections,
HGM.Controls.VirtualTable;
type
TOnLogEvent = procedure(Text: string) of object;
TDB = class
private
FDataBase: TSQLiteDatabase;
FDataBaseName: string;
FCreated: Boolean;
FOnLog: TOnLogEvent;
procedure DoLog(Text: string);
procedure SetOnLog(const Value: TOnLogEvent);
procedure OnQuery(Sender: TObject; SQL: string);
public
constructor Create(FileName: string);
destructor Destroy; override;
procedure Log(Text: string);
property DataBaseName: string read FDataBaseName;
property DB: TSQLiteDatabase read FDataBase;
property Created: Boolean read FCreated;
property OnLog: TOnLogEvent read FOnLog write SetOnLog;
end;
var
FDB: TDB; //Áàçà
implementation
{ TDB }
constructor TDB.Create(FileName: string);
begin
FCreated := False;
FDataBase := TSQLiteDatabase.Create(FileName);
FDataBase.OnQuery := OnQuery;
FCreated := True;
end;
destructor TDB.Destroy;
begin
FDataBase.Free;
inherited;
end;
procedure TDB.DoLog(Text: string);
begin
if Assigned(FOnLog) then
FOnLog(Text);
end;
procedure TDB.Log(Text: string);
begin
DoLog(Text);
end;
procedure TDB.OnQuery(Sender: TObject; SQL: string);
begin
DoLog(SQL);
end;
procedure TDB.SetOnLog(const Value: TOnLogEvent);
begin
FOnLog := Value;
end;
end.