Error in EscapeQuotes function

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
btrewern
Expert Boarder
Expert Boarder
Posts: 193
Joined: 06.10.2005, 18:51

Error in EscapeQuotes function

Post by btrewern »

Does anybody else think this function looks wrong

Code: Select all

function EscapeQuotes(const Value: string): string;
var
  I: Integer;
  PrevChar, PrevPrevChar: string;
begin
  Result := '';
  PrevChar := ' ';
  PrevPrevChar := ' ';
  for I := 1 to Length(Value) do
  begin
    Result := Result + Value[I];
    if (Value[I] = '''') and ((PrevChar <> '\') or
       (PrevChar = '\') or (PrevPrevChar = '\')) then
      Result := Result + '''';
    PrevPrevChar := PrevChar;
    PrevChar := Value[I];
  end;
end;
It's from ZDbcPostgreSQLUtils.pas. I assume that the writer meant the middle if statement to read

Code: Select all

    if (Value[I] = '''') and ((PrevChar <> '\') or
       ((PrevChar = '\') and (PrevPrevChar = '\'))) then
but I still don't think that would work with strings like \\\'
Anybody have any ideas?

Regards,

Ben.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Hi Ben,

A far as I can see you're right. Can you fix it? If you can change it in the latest SVN version and you submit a diff to this forum (or to firmos by pm) there's a good chance it wil be introduced in the codebase (unless the change is very big).

Concerning the \\\' case, as I don't know what the functionis used for, I can't predict if that situation is likely to occur. I that kind of string is passed to the function it will certainly give a bad result.

Mark
Image
Post Reply