Skip to content

Parsing time enabled silently ignores invalid dates and stops any subsequent rows reads #683

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
datio opened this issue Oct 11, 2017 · 4 comments

Comments

@datio
Copy link

datio commented Oct 11, 2017

Issue description

The time parse errors (out of range / cannot parse) are silently ignored.
Any subsequent results with rows.Next() are not returned.

Example code

Collumn object definition:
`Birthday` date NOT NULL DEFAULT '0000-00-00'

Affecting collumn contents:
1965-00-00

go vars:
var rows *sql.Rows
var birthday *time.Time

DSN parameters:
parseTime=true&autocommit=false

Configuration

Driver version (or git SHA): Can't say for sure, the FETCH_HEAD contents include:

a8b7ed4454a6a4f98f85d3ad558cd6d97cec6959	branch 'master' of https://github.com/go-sql-driver/mysql

Go version: go1.9.1 linux/amd64

Server version: mysql Ver 15.1 Distrib 10.2.8-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Server OS: Linux 3937cad50f1a 4.4.0-96-generic #119-Ubuntu SMP Tue Sep 12 14:59:54 UTC 2017 x86_64 GNU/Linux

The server runs inside a docker container BTW.

@datio
Copy link
Author

datio commented Oct 11, 2017

When I use a string variable var birthday string, I get the following errors:

[mysql] 2017/10/11 23:51:33 packets.go:450: busy buffer
[mysql] 2017/10/11 23:51:33 packets.go:431: busy buffer
parsing time "1970-05-08T00:00:00Z": extra text: T00:00:00Z

or

[mysql] 2017/10/11 23:58:56 packets.go:450: busy buffer
[mysql] 2017/10/11 23:58:56 packets.go:431: busy buffer
parsing time "1965-00-00": month out of range

@methane
Copy link
Member

methane commented Oct 12, 2017

reproducible code, schema and data?

@datio datio closed this as completed Oct 12, 2017
@datio
Copy link
Author

datio commented Oct 12, 2017

Schema, data:
http://sqlfiddle.com/#!9/9e5a31/2

Code:

var userRows *sql.Rows
var userID int
var birthday *time.Time 

userRows, err = txn.Query(`
  SELECT user_id, birthday
  FROM users
`)

for userRows.Next() {
  err = userRows.Scan(&userID, &birthday)
  if err !=nil {
    // There's no error fired...
  }
}

@methane
Copy link
Member

methane commented Apr 18, 2018

I'm sorry, I was wrong. I've deleted previous message.

@datio You just missed checking userRows.Err() after for loop.
I can confirm everything is fine with this code.

	for rows.Next() {
		var userID int
		var birthday *time.Time
		if err := rows.Err(); err != nil {
			panic(err)
		}
		err = rows.Scan(&userID, &birthday)
		fmt.Printf("err=%v, userid=%v, birthday=%v\n", err, userID, birthday)
	}
	fmt.Printf("Last: %v\n", rows.Err())

@methane methane closed this as completed Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants