Firebird + empty strings, a problem

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
Milos
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 16.07.2022, 19:16

Firebird + empty strings, a problem

Post by Milos »

Hi all, first post so let me just start by saying thank you for your library!

I stumbled upon a problem when looking at a table with some string fields empty (not null, just empty)

Actual data in DB:

Code: Select all

ID Name1 Name2
1  'A'     '1'
2  'B'     ''
3  ''      '3'
4  'D'     '4'
mormot (or zeos) returns:
{"ID":1,"Name1":"A","Name2":"1"}
{"ID":2,"Name1":"B","Name2":""}
{"ID":3,"Name1":"A","Name2":"3"} --- Name1 should be blank!
{"ID":4,"Name1":"D","Name2":"4"}

I did lots of digging and it turned out that this function

function TZInterbase6XSQLDAResultSet.GetPAnsiChar(ColumnIndex: Integer; out Len: NativeUInt): PAnsiChar;

incorrectly returned 'A' as result for 3rd record's "Name1" field, while Len parameter was correctly returned as zero.

The other GetPAnsiChar function which doesn't take Len parameter correctly returned empty string.

The source of the problem may be in GetPCharFromTextVar function which is called by above.
Unless if there is a better way the problem can be fixed by changing the case for SQL_VARYING in GetPCharFromTextVar to this

Code: Select all

    SQL_VARYING:
      begin
        Len := PISC_VARYING(sqldata).strlen;
        if Len = 0
           then P := nil
           else P := @PISC_VARYING(sqldata).str[0];
      end;
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Firebird + empty strings, a problem

Post by marsupilami »

Hello Milos,

which Version of Zeos do you use? As far as I can see Zeos 7.2 as well as Zeos 8 use the same method for fetching values of type SQL_VARYING. I did your test on my computer and get the expected result:
ID NAME1 NAME2
1  "A"   "1"
2  "B"   ""
3  ""    "3"
4  "D"   "4"
Milos
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 16.07.2022, 19:16

Re: Firebird + empty strings, a problem

Post by Milos »

I appologize, this should be in 7.2 forum, I tried to find a way to contact an admin to tell them but I couldn't find a link
Milos
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 16.07.2022, 19:16

Re: Firebird + empty strings, a problem

Post by Milos »

Also I am using FB 2.5 in case it matters.
Milos
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 16.07.2022, 19:16

Re: Firebird + empty strings, a problem

Post by Milos »

Which function did you test?

GetPAnsiChar function that doesn't have Len parameter fixes the problem within itself by doing

Code: Select all

  ZSetString(P, Len, FRawTemp);
  Result := Pointer(FRawTemp);
but the one that does have Len param leaves the string content as-is.
Milos
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 16.07.2022, 19:16

Re: Firebird + empty strings, a problem

Post by Milos »

Can an admin move this to 7.2 please?

Also I can provide a sample project if needed, using Mormot, but not using zeos because I am not familiar enough with how it works sorry.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Firebird + empty strings, a problem

Post by marsupilami »

Milos wrote: 05.08.2022, 11:18 Can an admin move this to 7.2 please?
Moved ;)
Milos wrote: 05.08.2022, 11:18Also I can provide a sample project if needed, using Mormot, but not using zeos because I am not familiar enough with how it works sorry.
That is not necessary at the moment. I just didn't have the possibility to look into this yet. :(
Milos
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 16.07.2022, 19:16

Re: Firebird + empty strings, a problem

Post by Milos »

No problem and thank you for your work.

Mormot souce code has since been modified to take this into consideration i.e. it checks the Len parameter in order to determine if string is actually empty so a Mormot example would no longer show a problem, but I think it's still worth making a change in Zeos.
Fr0sT
Zeos Dev Team
Zeos Dev Team
Posts: 280
Joined: 08.05.2014, 12:08

Re: Firebird + empty strings, a problem

Post by Fr0sT »

This is the bug indeed, though calling functions should never use a value when Len is 0 - but we live in a non-ideal world so additional check wouldn't hurt.
Created PR with your fix
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Firebird + empty strings, a problem

Post by marsupilami »

I applied the patch to Zeos 8.0 and Zeos 7.2. Thank you :)
Post Reply