📄 wwfltdlg.pas
字号:
TableAliasList:= TStringList.create;
if SQLTables.count>0 then begin
for i:= 0 to SQLTables.count-1 do begin
tempTableName:= TwwSQLTablesCollectionItem(SQLTables.Items[i]).TableName;
tempAliasName:= TwwSQLTablesCollectionItem(SQLTables.Items[i]).TableAliasName;
if (tempTableName<>'') then begin
TableNameList.add(tempTableName);
if tempAliasName='' then
TableAliasList.add(TableNameList[i])
else
TableAliasList.add(tempAliasName);
end
end
end
else begin
if word='FROM' then begin
repeat
repeat { Get Next table in From list }
TableName:= GetWord(line, APos);
if TableName='' then begin
if (i>=querysql.count-1) then break;
inc(i);
line:=uppercase(querysql[i]);
APos:= 1;
end
until TableName<>'';
if (TableName[1]=Dbl) or (TableName[1]=Single) then
begin
TableNameList.Add(copy(TableName, 2, length(TableName)-2));
TableAliasList.Add(GetWord(line, APos));
end
else begin
TableNameList.Add(TableName);
TableAliasList.Add(TableName);
end;
if (GetWord(line, APos)<>',') then break;
until False;
end
end;
try
for tnidx:= 0 to TableNameList.count-1 do begin
{$ifdef wwDelphi3Up}
if (datasource.dataset is TBDEDataSet) and
(FieldsFetchMethod = fmUseTTable) then
begin
{$endif}
table.databaseName:= wwGetDatabaseName(datasource.dataset);
{ 10/25/97 - Get session name to assign to temporary table object }
{$ifdef win32}
table.sessionName:= wwGetSessionName(datasource.dataset);
{$endif}
table.tableName:= tableNameList[tnidx];
table.readOnly:= True;
DoInitTempDataSet(DataSource.dataset, TempDataSet);
{$Warnings Off}
table.GetFieldNames(TempFldList);
{$Warnings On}
{$ifdef wwDelphi3Up}
end
else if wwIsClass(datasource.dataset.classType, 'TClientDataSet') then
begin
PropInfo:= Typinfo.GetPropInfo(DataSource.DataSet.ClassInfo,'FieldInfo');
if PropInfo<>Nil then begin
RemoteFieldInfo:= TStrings(GetOrdProp(DataSource.DataSet, PropInfo));
if RemoteFieldInfo=nil then exit; // design time returns nil
parts:= TStringList.create;
for i:= 0 to RemoteFieldInfo.count-1 do
begin
strbreakApart(RemoteFieldInfo[i], ';', parts);
with AddDBFieldInfo do begin
PhysicalFieldName:= parts[0];
LogicalFieldName:= parts[1];
TableName:= parts[2];
Displaylabel:= parts[3];
FieldType:= TFieldType(GetEnumValue(TypeInfo(TFieldType), parts[4]));
Size:= strtoInt(parts[5]);
end
end;
parts.Free;
end
else exit;
end
else begin
wwSetDatabaseName(tempDataSet, wwGetDatabaseName(datasource.dataset));
wwSetSessionName(tempDataSet, wwGetSessionName(datasource.dataset));
if wwIsClass(Datasource.DataSet.ClassType, 'TCustomADODataSet') then
wwSetConnectionString(tempDataSet, wwGetConnectionString(datasource.dataset));
if wwIsClass(Datasource.DataSet.ClassType, 'TIBCustomDataSet') then
wwSetIBDatabase(tempDataSet, wwGetIBDatabase(datasource.dataset));
if wwIsClass(Datasource.DataSet.ClassType, 'TCustomADODataSet') or
wwIsClass(Datasource.DataSet.ClassType, 'TSimpleDataSet') then
wwSetConnection(tempDataSet, wwGetConnection(datasource.dataset));
if wwIsClass(Datasource.DataSet.ClassType, 'TCustomADODataSet') or
wwIsClass(Datasource.DataSet.ClassType, 'TIBCustomDataSet') then
begin
wwSetDatabaseCursorType(tempDataSet, 0);
wwSetDatabaseMaxRecords(tempDataSet, 1); { Limit result set }
end;
// wwSetRequestLive(DataSource.DataSet, True);
// PropInfo:= Typinfo.GetPropInfo(tempDataSet.ClassInfo,GetSQLPropertyName);
PropInfo:= Typinfo.GetPropInfo(GetCommandTextDataSet(tempDataSet).ClassInfo,GetSQLPropertyName);
if PropInfo<>Nil then begin
if (PropInfo^.Proptype^.Kind in [tkString, tklstring, tkwstring]) then begin
SetStrProp(GetCommandTextDataSet(tempDataSet), PropInfo,
'Select * from ' + TableNameList[tnidx]);
end
else begin
if IsWideSql(GetCommandTextDataSet(tempDataSet), propInfo) then
begin
widequerysql2:= TWideStrings(GetObjectProp(GetCommandTextDataSet(tempDataSet), PropInfo));
widequerysql2.clear;
widequerysql2.add('Select * from ' + TableNameList[tnidx]);
end
else begin
querysql2:= TStrings(GetOrdProp(GetCommandTextDataSet(tempDataSet), PropInfo));
querysql2.clear;
querysql2.add('Select * from ' + TableNameList[tnidx]);
end;
end;
DoInitTempDataSet(DataSource.dataset, TempDataSet);
{$Warnings Off}
tempDataSet.GetFieldNames(TempFldList);
{$Warnings On}
end
else exit;
end;
{$endif}
if not wwIsClass(datasource.dataset.classType, 'TClientDataSet') then
begin
for j:= 0 to TempFldList.Count-1 do begin
if TempAllFldList.indexOf(uppercase(TempFldList[j]))<0 then
TempAllFldList.add(uppercase(TempFldList[j]))
else continue; { Duplicate field name so ignore }
PhysFieldName:= TempFldList[j];
TempFldList[j]:= ComputeFieldName(TempFldList[j]);
newFldItem:= TwwDBFieldInfo.create;
with newFldItem do
begin
LogicalFieldName:= TempFldList[j];
TableName:= TableAliasList[tnidx];
PhysicalFieldName:= PhysFieldName;
FieldDef:= tempDataSet.FieldDefs.Find(PhysicalFieldName);
if FieldDef<>nil then
begin
FieldType:= FieldDef.DataType;
Size:= FieldDef.size;
end;
tempField:=tempDataSet.FindField(PhysicalFieldName);
if tempField=nil then begin { If field not found check query's fields }
tempField:= datasource.dataset.FindField(PhysicalFieldName);
if tempField=nil then DisplayLabel:= PhysicalFieldName
else DisplayLabel:= tempField.DisplayLabel;
end
else DisplayLabel:= tempField.DisplayLabel;
end;
FFldList.add(newFldItem);
end;
end;
end
finally
if sqlStringType then querysql.free;
tempDataSet.Free;
tempFldList.Free;
tempAllFldList.Free;
TableNameList.Free;
TableAliasList.Free;
end
end;
{ From internal Field Name, Map to Physical Table and Field names.
The FieldName and Physical Field Name would be the same except in the case
where two related tables have the same field name.
The logic assumes that the Delphi numbering scheme is based on the
relative order of the tables in the 'From' clause.
}
Function TwwFilterDialog.GetDBInfoForField(AFilterFieldName: wwSmallString): TwwDBFieldInfo;
var i: integer;
begin
result:= nil;
for i:= 0 to FFldList.count-1 do begin
if wwEqualStr(TwwDBFieldInfo(FFldList[i]).LogicalFieldName, AFilterFieldName) then
begin
result:= TwwDBFieldInfo(FFldList[i]);
break;
end;
end;
end;
Function TwwFilterDialog.PadUpperRange(size: integer; val: string): string;
begin
result:= wwPadUpperRange(size, val, UpperRangePadChar);
end;
Function TwwFilterDialog.Execute: boolean;
begin
result := ExecuteDialog;
end;
function TwwFilterDialog.GetEffectiveSQLUpperString: string;
begin
result:= 'Upper';
if FSQLUpperString<>'' then result:= FSQLUpperString;
end;
Function TwwFilterDialog.ExecuteDialog(ExecuteQuery: boolean = True;
ReturnWhereClause: TStrings = nil): boolean;
var
FOnFilter: TwwDataSetFilterEvent;
ApplyFilter: boolean;
SaveCursor: TCursor;
dbInfo: TwwDBFieldInfo;
Function QueryFormatDateTime(val: string): string;
var year, month, day, hour, min, sec, msec: word;
begin
result:= '';
if val='' then exit;
DecodeDate(StrToDateTime(val), Year, Month, Day);
DecodeTime(StrToDateTime(val), Hour, Min, Sec, MSec);
case QueryFormatDateMode of
qfdMonthDayYear:
Result:= inttostr(Month) + '/' + inttostr(Day) + '/' + inttostr(year) +
' ' + inttostr(hour) + ':' + inttostr(min) + ':' + inttostr(sec);
qfdDayMonthYear:
Result:= inttostr(Day) + '/' + inttostr(Month) + '/' + inttostr(year) +
' ' + inttostr(hour) + ':' + inttostr(min) + ':' + inttostr(sec);
qfdYearMonthDay:
Result:= inttostr(Year) + '/' + inttostr(Month) + '/' + inttostr(Day) +
' ' + inttostr(hour) + ':' + inttostr(min) + ':' + inttostr(sec);
end;
if Assigned(FOnEncodeDateTime) then
OnEncodeDateTime(StrToDateTime(val), dbInfo.FieldType, dbInfo.LogicalFieldName, Result)
end;
Function QueryFormatDate(val: string): string;
var year, month, day: word;
begin
result:= '';
if val='' then exit;
DecodeDate(StrToDateTime(val), Year, Month, Day);
case QueryFormatDateMode of
qfdMonthDayYear:
Result:= inttostr(Month) + '/' + inttostr(Day) + '/' + inttostr(year);
qfdDayMonthYear:
Result:= inttostr(Day) + '/' + inttostr(Month) + '/' + inttostr(year);
qfdYearMonthDay:
Result:= inttostr(Year) + '/' + inttostr(Month) + '/' + inttostr(Day);
end;
if Assigned(FOnEncodeDateTime) then
OnEncodeDateTime(StrToDateTime(val), dbInfo.FieldType, dbInfo.LogicalFieldName, Result)
end;
Function QueryFormatTime(val: string): string;
var hour, min, sec, msec: word;
begin
result:= '';
if val='' then exit;
DecodeTime(StrToTime(val), Hour, Min, Sec, MSec);
Result:= inttostr(hour) + ':' + inttostr(min) + ':' + inttostr(sec);
if Assigned(FOnEncodeDateTime) then
OnEncodeDateTime(StrToDateTime(val), dbInfo.FieldType, dbInfo.LogicalFieldName, Result)
end;
Procedure ExecQueryByNewQuery;
var i, j: integer;
DisplayName, FilterFieldName: wwSmallString;
FilterValue: string;
TableFieldName: string;
{ query: TQuery;}
querysql: TStrings;
PropInfo: PPropInfo;
FldInfo: TwwFieldInfo;
Found: boolean;
line: string;
tableName: wwSmallString;
MatchType: TwwFilterMatchType;
whereClause: TStrings;
FoundField: boolean;
quote: string[1];
nextword: wwSmallString;
First: boolean;
SearchDelimiter: string;
OrFlg,AndFlg : Boolean;
CurPos : Integer;
tempMinValue, tempMaxValue: string;
querysqlstring, sqlString: string;
SQLStringType: boolean;
wideQuerySql: TWideStrings;
//iswide: boolean;
Function IsValueType(AFieldType: TFieldType): boolean;
begin
result:=
(AFieldType in
[ftDate, ftDateTime, ftSmallInt, ftInteger, ftWord, ftFloat, ftCurrency, ftBoolean,
{$ifdef wwDelphi6Up}
ftFMTBcd, ftTimeStamp, ftLargeInt,
{$endif}
ftBCD]);
{$ifdef win32}
if AFieldType=ftAutoInc then result:= True;
{$endif}
if (FilterMethod=fdByQueryModify) and
(AFieldType in [ftDateTime, ftTime]) then result:= True;
end;
begin
PropInfo:= Typinfo.GetPropInfo(GetCommandTextDataSet.ClassInfo,GetSQLPropertyName);
SQLStringType:= False;
if PropInfo<>Nil then
begin
if (PropInfo^.Proptype^.Kind in [tkString, tklstring, tkwstring]) then
begin
querysqlstring:= GetStrProp(GetCommandTextDataSet(DataSource.DataSet), PropInfo);
SQLStringType:=True;
querysql:= TStringlist.create;
querysql.Add(querysqlstring);
end
else begin
if IsWideSql(GetCommandTextDataSet, propInfo) then
begin
SQLStringType:= True;
widequerysql:= TWideStringList(Get
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -