[bug_fixed] PostgresSQL EncodeString Bug Delphi 2009
Moderators: gto, EgonHugeist, olehs
[bug_fixed] PostgresSQL EncodeString Bug Delphi 2009
hi,
the "EncodeString" function in ZDbcPostgresqlUtils.pas has a bug. If parameters of function is "String" (in D2009) the variables SrcBuffer and DestBuffer must be PChar. It work if applied this, but i do not know what is the impact with the other type of 'string' (stBytes or stAsciiStream).
PS: sorry for my poor english
Alex
the "EncodeString" function in ZDbcPostgresqlUtils.pas has a bug. If parameters of function is "String" (in D2009) the variables SrcBuffer and DestBuffer must be PChar. It work if applied this, but i do not know what is the impact with the other type of 'string' (stBytes or stAsciiStream).
PS: sorry for my poor english
Alex
mdaems wrote:cyberal77,
Thanks for reporting. I just committed the patch you propose.
(SVN rev. 607
Mark
Hi i´m using the 628 revision and the problem happend again. I attached a file project to produce the error. In this project is used a ExecSQL method with parameters.
tracing into source the problem occurs on
ZDbcPostgreSqlUtils.pas -> function EncodeString lines 596 to 610
Using Pg 8.3
Database encoding win1252
D2009
Zeos revision 628
You do not have the required permissions to view the files attached to this post.
I have downloaded through SVN, who i can download this path ?seawolf wrote:Did you have download it through SVN? Or Did you have download a snapshot?
Because it looks like that patch not have been committed yet, so you must apply manually
I thinked that the path was applied on revision 607..
thanks
Take a look here and check if ZDbcPostgreSqlUtils.pas is patched
In unit ZDbcPostgreSqlUtils.pas there is one more function to patch
(line 585 more or less)
function EncodeString(CharactersetCode: TZPgCharactersetType; Value: string): string;
var
I, LastState: Integer;
SrcLength, DestLength: Integer;
SrcBuffer, DestBuffer: PChar;
begin
SrcLength := Length(Value);
SrcBuffer := PChar(Value);
DestLength := 2;
LastState := 0;
for I := 1 to SrcLength do
begin
LastState := pg_CS_stat(LastState,integer(SrcBuffer^),CharactersetCode);
if (SrcBuffer^ in [#0, '''']) or ((SrcBuffer^ = '\') and (LastState = 0)) then
Inc(DestLength, 4)
else
Inc(DestLength);
Inc(SrcBuffer);
end;
SrcBuffer := PChar(Value);
SetLength(Result, DestLength);
DestBuffer := PChar(Result);
DestBuffer^ := '''';
Inc(DestBuffer);
LastState := 0;
for I := 1 to SrcLength do
begin
LastState := pg_CS_stat(LastState,integer(SrcBuffer^),CharactersetCode);
if (SrcBuffer^ in [#0, '''']) or ((SrcBuffer^ = '\') and (LastState = 0)) then
begin
DestBuffer[0] := '\';
DestBuffer[1] := Char(Ord('0') + (Byte(SrcBuffer^) shr 6));
DestBuffer[2] := Char(Ord('0') + ((Byte(SrcBuffer^) shr 3) and $07));
DestBuffer[3] := Char(Ord('0') + (Byte(SrcBuffer^) and $07));
Inc(DestBuffer, 4);
end
else
begin
DestBuffer^ := SrcBuffer^;
Inc(DestBuffer);
end;
Inc(SrcBuffer);
end;
DestBuffer^ := '''';
end;
Try do this changing. It works fine to me
(line 585 more or less)
function EncodeString(CharactersetCode: TZPgCharactersetType; Value: string): string;
var
I, LastState: Integer;
SrcLength, DestLength: Integer;
SrcBuffer, DestBuffer: PChar;
begin
SrcLength := Length(Value);
SrcBuffer := PChar(Value);
DestLength := 2;
LastState := 0;
for I := 1 to SrcLength do
begin
LastState := pg_CS_stat(LastState,integer(SrcBuffer^),CharactersetCode);
if (SrcBuffer^ in [#0, '''']) or ((SrcBuffer^ = '\') and (LastState = 0)) then
Inc(DestLength, 4)
else
Inc(DestLength);
Inc(SrcBuffer);
end;
SrcBuffer := PChar(Value);
SetLength(Result, DestLength);
DestBuffer := PChar(Result);
DestBuffer^ := '''';
Inc(DestBuffer);
LastState := 0;
for I := 1 to SrcLength do
begin
LastState := pg_CS_stat(LastState,integer(SrcBuffer^),CharactersetCode);
if (SrcBuffer^ in [#0, '''']) or ((SrcBuffer^ = '\') and (LastState = 0)) then
begin
DestBuffer[0] := '\';
DestBuffer[1] := Char(Ord('0') + (Byte(SrcBuffer^) shr 6));
DestBuffer[2] := Char(Ord('0') + ((Byte(SrcBuffer^) shr 3) and $07));
DestBuffer[3] := Char(Ord('0') + (Byte(SrcBuffer^) and $07));
Inc(DestBuffer, 4);
end
else
begin
DestBuffer^ := SrcBuffer^;
Inc(DestBuffer);
end;
Inc(SrcBuffer);
end;
DestBuffer^ := '''';
end;
Try do this changing. It works fine to me