martinrybak / SQLClient

Native Microsoft SQL Server client for iOS
http://objcsharp.wordpress.com/2013/10/15/an-open-source-sql-server-library-for-ios/
MIT License
124 stars 51 forks source link

result of NULL value is not always correct #4

Closed gagaxj closed 7 years ago

gagaxj commented 10 years ago

I noticed an issue which is quite repeatable.

You can just set up a test table like below to repeat the issue. Let's say a column named myColumn, it is either varchar(5) or decimal(3,1). Have 3 rows of result. Row1, Row2, Row3.

If All these rows have NULL value of myColumn, the sql query result is fine. If only Row3 is NULL, it is also fine. If only Row2 is NULL, while Row1 is not, then there is a Problem. The query result for Row2 is not NULL, instead it uses the value from Row1.

I believe there is something wrong inside the function

Please fix it, thanks.

nhgrif commented 10 years ago

I've been working through the null issues here this morning and can confirm this issue.

nhgrif commented 10 years ago

I've found the source of this issue. It's line 233 of SQLClient.m. In some FreeTDS example code I've found, they use the value of pcol->status to check whether or not the column is null, while SQLClient only checks whether or not pcol->buffer is null. For whatever reason, the FreeTDS people decided not to reinitialize everything between each row.

if (pcol->status == -1) //column is null else //not null

I will create a pull request.

BenchR267 commented 7 years ago

@nhgrif This issue is still not fixed. Did you create your pull request? Was it merged?

martinrybak commented 7 years ago

This was fixed in PR #12