Skip to content

Commit fd971de

Browse files
committed
CSVColParser: correctly set nil values in Rows
1 parent 3476f31 commit fd971de

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

rows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const invalidate = "☠☠☠ MEMORY OVERWRITTEN ☠☠☠ "
1515
// CSVColumnParser is a function which converts trimmed csv
1616
// column string to a []byte representation. Currently
1717
// transforms NULL to nil
18-
var CSVColumnParser = func(s string) []byte {
18+
var CSVColumnParser = func(s string) interface{} {
1919
switch {
2020
case strings.ToLower(s) == "null":
2121
return nil

rows_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func TestRowsScanError(t *testing.T) {
432432

433433
func TestCSVRowParser(t *testing.T) {
434434
t.Parallel()
435-
rs := NewRows([]string{"col1", "col2"}).FromCSVString("a,NULL")
435+
rs := NewRows([]string{"col1", "col2", "col3"}).FromCSVString("a,NULL,NULL")
436436
db, mock, err := New()
437437
if err != nil {
438438
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
@@ -448,9 +448,10 @@ func TestCSVRowParser(t *testing.T) {
448448
defer rw.Close()
449449
var col1 string
450450
var col2 []byte
451+
var col3 *string
451452

452453
rw.Next()
453-
if err = rw.Scan(&col1, &col2); err != nil {
454+
if err = rw.Scan(&col1, &col2, &col3); err != nil {
454455
t.Fatalf("unexpected error: %s", err)
455456
}
456457
if col1 != "a" {
@@ -459,6 +460,9 @@ func TestCSVRowParser(t *testing.T) {
459460
if col2 != nil {
460461
t.Fatalf("expected col2 to be nil, but got [%T]:%+v", col2, col2)
461462
}
463+
if col3 != nil {
464+
t.Fatalf("expected col3 to be nil, but got [%T]:%+v", col2, col2)
465+
}
462466
}
463467

464468
func TestCSVParserInvalidInput(t *testing.T) {

0 commit comments

Comments
 (0)