Page 1 of 1

Backslash truncated delphi7 + postgres8.1 + zeosdbo 6.6.2-rc

Posted: 13.01.2008, 15:35
by _dbczl2007_
Hi,

I have the following table:
CREATE TABLE test (a text)
then I insert some data:
INSERT INTO test VALUES ('\\path\\testdir\\')
When doing
SELECT * FROM test
in the pqAdmin III Query application the results are as expected (\path\testdir\).

When using Delphi7 + zeosdbo-6.6.2-rc I get
pathtestdir
The backslash is gone! Why? I have tried a lot of different stuff codepage, client_encoding, forcing binary stream instead of ascii stream.

I have also been experiencing with different implementations of utf8_encoding, but no matter how I do it, my client app wont display (or retreive for that matter) the backslash, only pgAdmin will...

Can someone please help me on this.

Kind regards,

Jon

Posted: 14.01.2008, 18:54
by gto
I think you can use \\\\ instead of \\.

The backslash is used to escape the next char at right. If you post four backslashes, you'll be escaping two, and then it will work. At least it should :)

Posted: 14.01.2008, 19:38
by _dbczl2007_
A workaround is to use the postgresql-7 driver instead of version 8! Why I don't know. See related issue posted here Backward slash (\) problem...

Well well. If anyone have another solution, I am very interested!!!

Posted: 15.01.2008, 12:23
by btrewern
It seems there is a problem in TZPostgreSQLResultSet.GetBlob.

if you replace

Code: Select all

    if FPlainDriver.GetIsNull(FQueryHandle, RowNo - 1, ColumnIndex - 1) = 0 then
    begin
      Stream := nil;
      try
//        Stream := TStringStream.Create(DecodeString(GetRawString(ColumnIndex)));
        Stream := TStringStream.Create(FPlainDriver.DecodeBYTEA(GetString(ColumnIndex)));
        Result := TZAbstractBlob.CreateWithStream(Stream);
      finally
        if Assigned(Stream) then
          Stream.Free;
      end;
with

Code: Select all

    if FPlainDriver.GetIsNull(FQueryHandle, RowNo - 1, ColumnIndex - 1) = 0 then
    begin
      Stream := nil;
      try
//        Stream := TStringStream.Create(DecodeString(GetRawString(ColumnIndex)));
        Stream := TStringStream.Create(GetString(ColumnIndex));
        Result := TZAbstractBlob.CreateWithStream(Stream);
      finally
        if Assigned(Stream) then
          Stream.Free;
      end;
text fields look like they work correctly:). I'm not sure if this then affects bytea fields though. Could anyone who uses bytea fields check to see if this messes them up.

Ben.

Posted: 15.01.2008, 13:12
by btrewern
It looks as if the following works correctly. In the TZPostgreSQLResultSet.GetBlob function of the ZDbcPostgreSqlResultSet file replace

Code: Select all

    if FPlainDriver.GetIsNull(FQueryHandle, RowNo - 1, ColumnIndex - 1) = 0 then
    begin
      Stream := nil;
      try
//        Stream := TStringStream.Create(DecodeString(GetRawString(ColumnIndex)));
        Stream := TStringStream.Create(FPlainDriver.DecodeBYTEA(GetString(ColumnIndex)));
        Result := TZAbstractBlob.CreateWithStream(Stream);
      finally
        if Assigned(Stream) then
          Stream.Free;
      end;
    end else
      Result := TZAbstractBlob.CreateWithStream(nil);
with

Code: Select all

    if FPlainDriver.GetIsNull(FQueryHandle, RowNo - 1, ColumnIndex - 1) = 0 then
    begin
      Stream := nil;
      try
//        Stream := TStringStream.Create(DecodeString(GetRawString(ColumnIndex)));
        if GetMetadata.GetColumnType(ColumnIndex) = stBinaryStream then
          Stream := TStringStream.Create(FPlainDriver.DecodeBYTEA(GetString(ColumnIndex)))
        else
          Stream := TStringStream.Create(GetString(ColumnIndex));
        Result := TZAbstractBlob.CreateWithStream(Stream);
      finally
        if Assigned(Stream) then
          Stream.Free;
      end;
    end else
      Result := TZAbstractBlob.CreateWithStream(nil);
Regards,

Ben

Posted: 16.01.2008, 13:32
by mdaems
Ben,

I have to believe you and hope this code is also compatible with versions before 8.1.

SVN rev. 330

Mark