Firebird + empty strings, a problem
Posted: 16.07.2022, 19:51
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:
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
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'
{"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;