DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
5.95k stars 404 forks source link

CSVColParser: correctly set nil values in Rows #318

Closed IvoGoman closed 11 months ago

IvoGoman commented 11 months ago

I am using a struct with a *string such as

type Result struct {
    Value    *string `json:"value,omitempty"`
}

Previously the NULL passed to FromCSVString(..) was not working correctly. After scanning the result Rows of the query into the struct resulted in an empty string. With this change the mock behaves like the DB and the Value field is nil

vtolstov commented 11 months ago

Does with this change I can create csv with null value for int for example? Or determine empty string or null?

IvoGoman commented 11 months ago

Does with this change I can create csv with null value for int for example? Or determine empty string or null?

Yes, the intention of this PR is to reflect any NULL in the CSV correctly with pointer variables such *int or sql.NullInt etc.