[freetds] empty strings select as null bug

Geoff Montee geoff.montee at gmail.com
Wed Jun 10 18:37:59 EDT 2015


On Wed, Jun 10, 2015 at 7:27 AM, Jeffrey Shaw <shawjef3 at gmail.com> wrote:
>
> I can use PostgreSQL's tds_fdw to use dblib to select from SQL Server. The
> query is
>
> select id, string is null from distribution.dbo_strings;
>
> TDS Version = 4.2
> id | ?column?
> ----+----------
>   1 | f
>
> TDS Version = 7.0
>  id | ?column?
> ----+----------
>   1 | t

As the developer of tds_fdw, I should probably point out to the
FreeTDS developers where my null test code is in case this is a bug on
my end.

tds_fdw assumes a column is NULL if dbdatlen() returns 0:

https://github.com/GeoffMontee/tds_fdw/blob/fd4696695149b0be143e11b70df14b42acdd899d/src/tds_fdw.c#L1816

http://www.freetds.org/reference/a00341.html#gae666d141533126babb0235af21bdca0f

I implemented it this way because I assumed dbdatlen() should be equal
to 1 for a null terminator character if a string is empty. Let me know
if this is a bad null test.

Could this behavior be related to iconv or character set conversions
in TDS 7.0 and higher?

Thanks,

Geoff


More information about the FreeTDS mailing list