Skip to content

Inconsistent time.Time value when changing interpolateParams #1252

Closed
@mcartmell

Description

@mcartmell

Issue description

When reading a time.Time value from a DATETIME column of value 0000-01-01 00:00:00, the year returned is inconsistent when using different values for the interpolateParams parameter.

I would expect the time value to be the same regardless of the interpolateParams setting.

I noticed this issue when upgrading from v1.5.0 to v1.6.0. Could not reproduce on v1.5.0.

Example code

package main

import (
	"database/sql"
	"fmt"
	"time"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	var results []time.Time
	vals := []bool{false, true}
	for _, val := range vals {
		db, err := sql.Open("mysql", fmt.Sprintf("user:password@/dbname?parseTime=true&interpolateParams=%t", val))
		if err != nil {
			panic(err)
		}

		if _, err := db.Exec("create temporary table `time_params_test` (`id` int, `dt` datetime);"); err != nil {
			panic(err)
		}

		if _, err := db.Exec("insert into `time_params_test` values(1, '0000-01-01 00:00:00');"); err != nil {
			panic(err)
		}

		var res time.Time
		row := db.QueryRow("select dt from `time_params_test` where id = ?;", 1)
		if err := row.Scan(&res); err != nil {
			panic(err)
		}
		results = append(results, res)
	}
	fmt.Printf(`
interpolateParams=false: %v
interpolateParams=true : %v
match=%t`, results[0], results[1], results[0] == results[1])
}

Error log

interpolateParams=false: 0000-01-01 00:00:00 +0000 UTC
interpolateParams=true : 0001-01-01 00:00:00 +0000 UTC
match=false

Configuration

Driver version (or git SHA): v1.6.0

Go version: v1.16.3

Server version: MySQL 5.7.32

Server OS: OS X 10.15

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