/
MaintFlg.xxm
86 lines (79 loc) · 1.92 KB
/
MaintFlg.xxm
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
[[@txDefs,txSession,DataLank,txFilter,txFilterSql,]][[!var
qr:TQueryResult;
i,ItemCount,TotalWeight:integer;
fl:array of record
id:integer;
ex:UTF8String;
name:string;
end;
f:TtxFilter;
fq:TtxSqlQueryFragments;
fs:UTF8String;
dry:boolean;
]][[
Context.ContentType:='text/plain';
Context.BufferSize:=0;
CheckMaintProtect(Context);
//ATTENTION: run under a specific user to get realms selection right!
dry:=Context['dry'].AsInteger<>0;
i:=0;
qr:=TQueryResult.Create(Session.DbCon,'SELECT id, name, expression FROM Flt',[]);
try
while qr.Read do
begin
SetLength(fl,i+1);
fl[i].id:=qr.GetInt('id');
fl[i].name:=qr.GetStr('name');
fl[i].ex:=UTF8Encode(qr.GetStr('expression'));
inc(i);
end;
finally
qr.Free;
end;
for i:=0 to Length(fl)-1 do
begin
Context.SendHTML('['+IntToStr(fl[i].id)+']'+fl[i].name+#13#10'...');
try
f:=TtxFilter.Create;
fq:=TtxSqlQueryFragments.Create(itObj);
try
f.FilterExpression:=fl[i].ex;
if f.ParseError<>'' then
begin
]]
PARSE_ERROR!!!
[[#f.ParseError]]
[[
end;
fq.AddFilter(f);
fq.Fields:='Count(*) AS ItemCount, SUM(Obj.weight) AS TotalWeight';
fq.Where:='Obj.rlm_id'+Session.Realms[rpView].SQL+' AND ('+fq.Where+')';
fq.OrderBy:='';
//fq.GroupBy
fs:=fq.SQL;
finally
f.Free;
fq.Free;
end;
qr:=TQueryResult.Create(Session.DbCon,fs,[]);
try
ItemCount:=qr.GetInt('ItemCount');
TotalWeight:=qr.GetInt('TotalWeight');
finally
qr.Free;
end;
Context.SendHTML(' '+IntToStr(ItemCount)+' ('+IntToStr(TotalWeight)+')');
if not dry then
Session.DbCon.Insert('Flg',['flt_id',fl[i].id,'count',ItemCount,'weight',TotalWeight,'ts',VNow]);
Context.SendHTML(' !'#13#10#13#10);
except
on e:Exception do
begin
]]
EXCEPTION!!!
[[#e.Message]]
[[
end;
end;
end;
Context.SendHTML('---'#13#10);