Skip to content

All columns on the query result are empty when the first field is empty #1094

Closed
@DouglasPioStudiare

Description

@DouglasPioStudiare

Issue description

When run query shoud return values as "", "123", but instead return "", "".

Example code

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"log"
	"os"
)

type ResultStruct struct {
	field1 string `db:"field1"`
	field2 string `db:"field2"`
}

func main() {
	db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", os.Getenv("USER"), os.Getenv("PASS"), os.Getenv("ENDPOINT"), os.Getenv("PORT"), os.Getenv("DBNAME")))
	if err = db.Ping(); err != nil {
		log.Fatal("Error : " + err.Error())
	}
	defer db.Close()

	params := "123,456,789,121"

	query := fmt.Sprintf(`select field1, field2 from test_table where field1 in (%s) or field2 in (%s)`, params, params)

	rows, selectErr := db.Query(query)
	if selectErr != nil {
		log.Fatal("Error : " + selectErr.Error())
	}

	for rows.Next() {
		var rs ResultStruct

                err := rows.Scan(&rs.field1, &rs.field2)
		if err != nil {
			log.Fatal("Error : " + err.Error())
		}

		log.Printf("field1: %v | field2: %v", rs.field1, rs.field2)
	}
}

Error log

Error : sql: Scan error on column index 0, name "field1": unsupported Scan, storing driver.Value type <nil> into type *string

Configuration

Driver version (or git SHA): Implements a Travis CI task (#1070) git: 681ffa8

Go version: 1.12.7

Server version: MySQL 5.6.48

Server OS: Manjaro Linux 18.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions