tds icon indicating copy to clipboard operation
tds copied to clipboard

How to check if tds.Num represents a NULL value

Open hqin opened this issue 4 years ago • 2 comments

After scanning successfully a NULL value into tds.Num, what is the public method to determine if is NULL or not? tds.Num has only String() and Rat() methods?

tds.Num{r:big.Rat{a:big.Int{neg:false, abs:big.nat(nil)}, b:big.Int{neg:false, abs:big.nat(nil)}}, precision:0, scale:0, isNull:true}

hqin avatar Jun 26 '21 04:06 hqin

Thanks for reporting, good catch. I should add a NullNum type which has a Valid member, similar to NullString. Another option would be to return a nil pointer when the num is nil. I'll try to work on it next week. Out of curiosity, do you know how SAP's official driver handles this ?

thda avatar Jun 28 '21 09:06 thda

Unfortunately SAP's go-ase driver does not handle it properly either. FYI, github.com/denisenkom/go-mssqldb handles null decimal using sql.NullString. github.com/cockroachdb/apd/v2 has apd.Decimal and apd.NullDecimal

hqin avatar Sep 07 '21 22:09 hqin