Page 1 of 1

[bug_fixed] PostgresSQL EncodeString Bug Delphi 2009

Posted: 17.03.2009, 09:38
by cyberal77
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

Posted: 21.03.2009, 00:46
by mdaems
cyberal77,

Thanks for reporting. I just committed the patch you propose.
(SVN rev. 607

Mark

Posted: 23.04.2009, 12:53
by fhaut
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

Posted: 24.04.2009, 14:22
by seawolf
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

Posted: 24.04.2009, 22:14
by fhaut
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 have downloaded through SVN, who i can download this path ?

I thinked that the path was applied on revision 607..


thanks

Posted: 27.04.2009, 22:18
by seawolf
Take a look here and check if ZDbcPostgreSqlUtils.pas is patched

Posted: 28.04.2009, 12:20
by fhaut
seawolf wrote:Take a look here and check if ZDbcPostgreSqlUtils.pas is patched

Yes, it´s patched... problem remain :cry:

Posted: 29.04.2009, 20:38
by seawolf
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

Posted: 30.04.2009, 14:04
by fhaut
Now works

:thanks:

Posted: 02.05.2009, 16:50
by fhaut
fhaut wrote:Now works

:thanks:
[bug_report] created issue 181 on bugtracker

http://zeosbugs.firmos.at/view.php?id=181

Posted: 04.05.2009, 01:08
by mdaems
SVN Rev 632