Error in TDatasetUtils.DefineKeyFields

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
merlin352
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 15.10.2009, 12:20

Error in TDatasetUtils.DefineKeyFields

Post 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;
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Error in TDatasetUtils.DefineKeyFields

Post by marsupilami »

Hello merlin,

I applied the patch to Zeos 7.2.

With best regards,

Jan
Fr0sT
Zeos Dev Team
Zeos Dev Team
Posts: 280
Joined: 08.05.2014, 12:08

Re: Error in TDatasetUtils.DefineKeyFields

Post 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.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Error in TDatasetUtils.DefineKeyFields

Post 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
Fr0sT
Zeos Dev Team
Zeos Dev Team
Posts: 280
Joined: 08.05.2014, 12:08

Re: Error in TDatasetUtils.DefineKeyFields

Post by Fr0sT »

Perfect 8)
Post Reply