Page 1 of 1

Error in TDatasetUtils.DefineKeyFields

Posted: 20.01.2018, 02:51
by merlin352
Hello
Refresh throws an error when a fieldname contains a special character, like by ex. an Umlaut "äöü" (Yes I know this is bad practice, but I am working with an external Access-Database which contains such Fieldnames, and even Tablenames)

This is due, because DefineKeyFields only quotes Fieldnames containing " .-"

Code: Select all

function DefineKeyFields(Fields: TFields): string;
var
  I: Integer;
  Temp: string;
begin
  Result := '';
  for I := 0 to Fields.Count - 1 do
  begin
    if (Fields[I].FieldKind = fkData)
      and not (Fields[I].DataType in [ftBlob, ftMemo, ftBytes {$IFDEF WITH_WIDEMEMO}, ftWideMemo{$ENDIF}]) then
    begin
      if Result <> '' then
        Result := Result + ',';
      Temp := Fields[I].FieldName;
     if (ZFastCode.Pos(' ', Temp) > 0) or (ZFastCode.Pos('-', Temp) > 0) or (ZFastCode.Pos('.', Temp) > 0) then
        Temp := '"' + Temp + '"';
      Result := Result + Temp;
    end;
  end;
end;
The best solution is to quote ALL Fieldnames :

Code: Select all

function DefineKeyFields(Fields: TFields): string;
var
  I: Integer;
begin
  Result := '';
  for I := 0 to Fields.Count - 1 do
  begin
    if (Fields[I].FieldKind = fkData)
      and not (Fields[I].DataType in [ftBlob, ftMemo, ftBytes {$IFDEF WITH_WIDEMEMO}, ftWideMemo{$ENDIF}]) then
    begin
      if Result <> '' then
        Result := Result + ',';
      Result := Result +  '"' + Fields[I].FieldName+ '"';
    end;
  end;
end;

Re: Error in TDatasetUtils.DefineKeyFields

Posted: 21.01.2018, 16:49
by marsupilami
Hello merlin,

I applied the patch to Zeos 7.2.

With best regards,

Jan

Re: Error in TDatasetUtils.DefineKeyFields

Posted: 22.01.2018, 09:24
by Fr0sT
Maybe it's more correct to add Connection parameter and use Connection.GetMetadata.GetIdentifierConvertor.Quote for this purpose? The routine is called from 2 places only and is not intended for public usage so the change should be painless.

Re: Error in TDatasetUtils.DefineKeyFields

Posted: 22.01.2018, 18:02
by marsupilami
Hello Fr0sT :)
Fr0sT wrote:Maybe it's more correct to add Connection parameter and use Connection.GetMetadata.GetIdentifierConvertor.Quote for this purpose? The routine is called from 2 places only and is not intended for public usage so the change should be painless.
Yes - you are absolutely right. Egonhugeist told me tha same yesterday - which is why we introduced the changes in SVN Rev. 4092 ;)

Best regards,

Jan

Re: Error in TDatasetUtils.DefineKeyFields

Posted: 23.01.2018, 16:17
by Fr0sT
Perfect 8)