Skip to content

Over 24h (and less 100h) TIME type SELECT result #817

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

Closed
darmats opened this issue Jun 11, 2018 · 1 comment · Fixed by #818
Closed

Over 24h (and less 100h) TIME type SELECT result #817

darmats opened this issue Jun 11, 2018 · 1 comment · Fixed by #818
Labels
Milestone

Comments

@darmats
Copy link

darmats commented Jun 11, 2018

Issue description

SELECT TIME type, if over 24 hours, leading zero are added even if less 100 hours.
Why is this? (is there any meaning? or bug?)

Please excuse my poor English, and if I missed something, I'm sorry.

Preparations (in MySQL)

CREATE TABLE time_test (
  id INTEGER PRIMARY KEY,
  tm TIME
);
INSERT INTO time_test (id, tm) VALUES (1, '01:12:34');
INSERT INTO time_test (id, tm) VALUES (2, '23:12:34');
INSERT INTO time_test (id, tm) VALUES (3, '123:12:34');
INSERT INTO time_test (id, tm) VALUES (4, '24:12:34');

Example code

func TestTest(t *testing.T) {
	db, err := sql.Open("mysql", "your_dsn")
	if err != nil {
		panic(err)
	} else if err = db.Ping(); err != nil {
		panic(err)
	}

	for id := 1; id <= 4; id++ {
		rows, err := db.Query(`SELECT id, tm FROM time_test WHERE id = ?`, id)
		if err != nil {
			t.Fatal(err)
		}
		if !rows.Next() {
			t.Fatal("no rows found")
		}

		var holder struct {
			ID int
			Tm string
		}
		err = rows.Scan(&holder.ID, &holder.Tm)
		if err != nil {
			t.Fatal(err)
		}
		rows.Close()
		fmt.Printf("id %d: %q\n", holder.ID, holder.Tm)
	}
}

Output

id 1: "01:12:34"
id 2: "23:12:34"
id 3: "123:12:34"
id 4: "024:12:34" ... ❓

Configuration

Driver version (or git SHA): v1.4.0

Go version: go1.10.3 darwin/amd64

Server version: MySQL 5.7

Server OS: macOS 10.13.5

@methane
Copy link
Member

methane commented Jun 12, 2018

Nice catch. It seems bug of formatBinaryDateTime() which converts
binary representation into text.

methane added a commit to methane/mysql that referenced this issue Jun 12, 2018
methane added a commit to methane/mysql that referenced this issue Jun 12, 2018
methane added a commit to methane/mysql that referenced this issue Jun 12, 2018
methane added a commit to methane/mysql that referenced this issue Jun 12, 2018
@julienschmidt julienschmidt added this to the v1.5.0 milestone Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants