-
Notifications
You must be signed in to change notification settings - Fork 3
/
uDBWriter.pas
83 lines (69 loc) · 1.7 KB
/
uDBWriter.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
unit uDBWriter;
interface
uses
pFIBQuery, pFIBDatabase, uVehicles3C, pFIBProps;
type
TDBWriter = class
qrWrite: TpFIBQuery;
trWrite: TpFIBTransaction;
FVID: TVehIdent;
private
procedure SetVID(const Value: TVehIdent);
{ Private declarations }
public
constructor Create(DB: TpFIBDatabase); overload;
destructor Destroy; override;
procedure ExecQuery(strQuery: String; Commit: Boolean = True);
procedure CommitWork;
procedure RollbackWork;
property VID: TVehIdent read FVID write SetVID;
end;
implementation
{ TDBWriter }
procedure TDBWriter.CommitWork;
begin
if trWrite.InTransaction then trWrite.Commit;
end;
constructor TDBWriter.Create(DB: TpFIBDatabase);
begin
inherited Create;
trWrite := TpFIBTransaction.Create(nil);
trWrite.DefaultDatabase := DB;
trWrite.TPBMode := tpbDefault;
trWrite.TRParams.Text :=
'write' + #13#10 +
'read_committed' + #13#10 +
'rec_version' + #13#10 +
'nowait';
qrWrite := TpFIBQuery.Create(nil);
qrWrite.Database := DB;
qrWrite.Transaction := trWrite;
end;
destructor TDBWriter.Destroy;
begin
qrWrite.Free;
if trWrite.InTransaction then trWrite.Rollback;
trWrite.Free;
inherited;
end;
procedure TDBWriter.ExecQuery(strQuery: String; Commit: Boolean);
begin
qrWrite.Close;
if Commit then
qrWrite.Options := [qoStartTransaction, qoAutoCommit]
else
qrWrite.Options := [qoStartTransaction];
qrWrite.SQL.Text := strQuery;
qrWrite.ExecQuery;
end;
procedure TDBWriter.RollbackWork;
begin
if trWrite.InTransaction then trWrite.Rollback;
end;
procedure TDBWriter.SetVID(const Value: TVehIdent);
begin
FVID.ID := Value.ID;
FVID.SN := Value.SN;
FVID.Phone := Value.Phone;
end;
end.