-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add flag to restore v1.2 time rounding behavior #713
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
Comments
I'm very conservative about adding options. More options makes people don't read manual, In this case,
|
As my understanding, you can fix it by using What is rational for adding new option in new version? |
@methane When I insert |
That's default behavior of MySQL, not this driver. |
I'd say it already has more than enough options to discourage people from reading manual. For example using spoilers: allowAllFiles=true disables the file Whitelist for LOAD DATA LOCAL INFILE and allows all files.Might be insecure!
|
It doesn't change my mind. Adding option makes hard to maintain for long time in long-time run.
In this case, the problem looks solved in application layer. |
See also: rails/rails#18067 Rails (ActiveRecord = ORM, not driver) cares this backward incompatible change between 5.6 and 5.5. I think it's good example. Driver should be transparent. Driver should pass complete information |
And see also too: https://bugs.mysql.com/bug.php?id=68760 |
ok, I see your point @methane package mymysql
import "time"
import "database/sql"
import "database/sql/driver"
import "github.com/go-sql-driver/mysql"
type stmt struct {
driver.Stmt
}
func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
for i, v := range args {
switch v := v.(type) {
case time.Time:
args[i] = v.Truncate(time.Second)
case *time.Time:
*v = v.Truncate(time.Second)
}
}
return s.Stmt.Exec(args)
}
type conn struct {
driver.Conn
}
func (c *conn) Prepare(query string) (driver.Stmt, error) {
s, err := c.Conn.Prepare(query)
if err != nil {
return nil, err
}
return &stmt{s}, nil
}
type myMySQL struct {
my mysql.MySQLDriver
}
func (d myMySQL) Open(dsn string) (driver.Conn, error) {
c, err := d.my.Open(dsn)
if err != nil {
return nil, err
}
return &conn{c}, nil
}
func init() {
sql.Register("mymysql", myMySQL{})
} |
In v1.2 time is rounded DOWN, in v1.3 time is rounded UP. Can we introduce a flag for backward compatibility?
The text was updated successfully, but these errors were encountered: