in CRGrid.pas,
function TCRColumn.GetFilterExpression(const RawFilter: string): string;
Code: Select all
if Assigned(Field) then
if (Field.DataSet is TCustomDADataSet) then begin
if not (dgeLocalFilter in TCRDBGrid(Grid).OptionsEx) and
(Field.FieldName <> TCRFieldDesc(TDBAccessUtils.GetIRecordSet(TCustomDADataSet(Field.DataSet)).Fields[0]).ActualName) then
FieldName := TCRFieldDesc(TDBAccessUtils.GetIRecordSet(TCustomDADataSet(Field.DataSet)).Fields[0]).ActualName
else
FieldName := Field.FieldName;
if not (dgeLocalFilter in TCRDBGrid(Grid).OptionsEx) and
(TCRFieldDesc(TDBAccessUtils.GetIRecordSet(TCustomDADataSet(Field.DataSet)).Fields[0]).TableInfo.TableAlias <> '') then
FieldName := TCRFieldDesc(TDBAccessUtils.GetIRecordSet(TCustomDADataSet(Field.DataSet)).Fields[0]).TableInfo.TableAlias + '.' + FieldName;
end
else
FieldName := Field.FieldName;
The constant 0 can not be right there.
The right thing to do is:
Code: Select all
xFld : TFieldDescs;
if not Assigned(Field) then Exit;
if not (dgeLocalFilter in TCRDBGrid(Grid).OptionsEx) and (Field.DataSet is TCustomDADataSet) then begin
xFld := TDBAccessUtils.GetIRecordSet(TCustomDADataSet(Field.DataSet)).Fields;
for i := 0 to xFld.Count -1 do begin
if (xFld[i].FieldNo = Field.FieldNo) then begin //not in same order!
if Assigned(TCRFieldDesc(xFld[i]).TableInfo) and (TCRFieldDesc(xFld[i]).TableInfo.TableAlias <> '') then begin
FieldName := TCRFieldDesc(xFld[i]).TableInfo.TableAlias + '.' + TCRFieldDesc(xFld[i]).ActualName;
end else begin
if Field.Origin = '' then
FieldName := Field.FieldName
else
FieldName := Field.Origin
end;
Break;
end;
end; //for
if (FieldName = '') then Exit; //Field not found!
end else
FieldName := Field.FieldName;
Firebird REQUIRE that if a table alias is used then only the alias can be used in the query, not the original table name. Other database are more permissive.
For this the value of Field.Origin is wrong if using aliases (the code above take care of this).
Fire who wrote it and also who tested it!
