Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent time.Time value when changing interpolateParams #1252

Closed
mcartmell opened this issue Aug 18, 2021 · 0 comments · Fixed by #1257
Closed

Inconsistent time.Time value when changing interpolateParams #1252

mcartmell opened this issue Aug 18, 2021 · 0 comments · Fixed by #1257

Comments

@mcartmell
Copy link

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

methane added a commit to methane/mysql that referenced this issue Aug 24, 2021
methane added a commit that referenced this issue Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant