go-sql-driver / go-sql-driver/mysql
Get error timestamp data when scan to struct after db ddl
- Dominant language
- Go
- Stars
- 15.3k
- Forks
- 2.3k
- Avg merge
- 2h 23m
- Merged PRs (30d)
- 10
Description
### Issue description
what did I do:
1.exec sql query and get err timestamp data when scan to struct after db ddl.
sql:
`SELECT state,round,remark,ctime FROM archive_track WHERE aid=? ORDER BY id DESC`
struct:
```
type Archive struct {
Timestamp time.Time `json:"timestamp"`
State int `json:"state"`
Round int `json:"round"`
Remark string `json:"remark,omitempty"`
}
```
go code:
```
a:=&Archive{}
rows.Scan(&a.State, &a.Round, &a.Remark, &a.Timestamp)
```
mysql table info:
```
CREATE TABLE `archive_track` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT ,
`aid` int(11) NOT NULL DEFAULT '0' ,
`state` tinyint(11) DEFAULT NULL,
`round` tinyint(4) NOT NULL DEFAULT '0' ,
`remark` text COMMENT '其他信息',
`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
`attribute` mediumint(8) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `ix_aid` (`aid`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
```
table data:
| id | aid |state | round |remark | ctime | mtime | attribute |
|:---|---|---|---| ---| ---|--- | ---:|
| 1 | 1 | 1 | 1| "" | 2017-03-27 17:07:10 | 2017-03-27 17:07:10 | 0 |
I can get correct data first:
`&a{aid:1,state:1,round:1 ,ctime:1490605630}`
but get err data after db ttl(modify state(tinyint) to state(int) ):
`&a{aid:0,state:0,round:0,ctime:-62135596800}.`
db ttl:
```
alter table archive_track modify state int
```
I can't get correct data anymore until I restart the program.
after I restart ,I can get correct data and err data don't appear anymore ,but why.It make me confuse.
### Configuration
*Driver version (or git SHA):QD6LqgLz2JMxXqns8TaxtK9AuHs=
*Go version:go1.7.4
*Server version:* E.g. MySQL 5.6,
*Server OS:Linux version 3.16.0-4-amd64
Contributor guide
Assessment
This issue has not been assessed yet.