diff --git a/database/gdb/gdb_driver_mysql.go b/database/gdb/gdb_driver_mysql.go index 609d274a0..43daef7b1 100644 --- a/database/gdb/gdb_driver_mysql.go +++ b/database/gdb/gdb_driver_mysql.go @@ -42,7 +42,7 @@ func (d *DriverMysql) Open(config *ConfigNode) (*sql.DB, error) { } } else { source = fmt.Sprintf( - "%s:%s@tcp(%s:%s)/%s?charset=%s&multiStatements=true&parseTime=true&loc=Local", + "%s:%s@tcp(%s:%s)/%s?charset=%s&multiStatements=true&parseTime=true", config.User, config.Pass, config.Host, config.Port, config.Name, config.Charset, ) } diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index 0a1130cad..a36f920b6 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -573,8 +573,8 @@ func formatWhereKeyValue(db DB, buffer *bytes.Buffer, newArgs []interface{}, key return newArgs } -// handleArguments is a nice function which handles the query and its arguments before committing to -// underlying driver. +// handleArguments is an important function, which handles the sql and all its arguments +// before committing them to underlying driver. func handleArguments(sql string, args []interface{}) (newSql string, newArgs []interface{}) { newSql = sql // insertHolderCount is used to calculate the inserting position for the '?' holder. @@ -659,17 +659,22 @@ func handleArguments(sql string, args []interface{}) (newSql string, newArgs []i continue // Special handling for gtime.Time/*gtime.Time. + // + // DO NOT use its underlying gtime.Time.Time as its argument, + // because the std time.Time will be converted to certain timezone + // according to underlying driver. An the underlying driver also + // converts the time.Time to string automatically as the following does. case gtime.Time: - newArgs = append(newArgs, v.Time) + newArgs = append(newArgs, v.String()) continue case *gtime.Time: - newArgs = append(newArgs, v.Time) + newArgs = append(newArgs, v.String()) continue default: // It converts the struct to string in default - // if it implements the String interface. + // if it has implemented the String interface. if v, ok := arg.(apiString); ok { newArgs = append(newArgs, v.String()) continue diff --git a/database/gdb/gdb_z_mysql_model_test.go b/database/gdb/gdb_z_mysql_model_test.go index 2086b673f..89a2429f8 100644 --- a/database/gdb/gdb_z_mysql_model_test.go +++ b/database/gdb/gdb_z_mysql_model_test.go @@ -2841,7 +2841,7 @@ func Test_Model_HasField(t *testing.T) { func Test_Model_Issue1002(t *testing.T) { table := createTable() defer dropTable(table) - db.SetDebug(true) + result, err := db.Table(table).Data(g.Map{ "id": 1, "passport": "port_1", @@ -2904,24 +2904,6 @@ func Test_Model_Issue1002(t *testing.T) { // where + time.Time arguments, UTC. t1, _ := time.Parse("2006-01-02 15:04:05", "2020-10-27 19:03:32") t2, _ := time.Parse("2006-01-02 15:04:05", "2020-10-27 19:03:34") - gtest.C(t, func(t *gtest.T) { - v, err := db.Table(table).Fields("id").Where("create_time>? and create_time? and create_time? and create_time? and create_time