javasgl

Results 10 comments of javasgl

```master: Could not introduce github.com/grpc-ecosystem/grpc-gateway@master, as it has a dependency on github.com/golang/protobuf with constraint aa810b61a9c79d51363740d207bb46cf8e620ed5, which has no overlap with existing constraint master from github.com/grpc-ecosystem/go-grpc-middleware@master```

+1 墙裂需要这个功能,不然动态添加Cols太痛苦了, 而AllCols 和 MustCols 又太极端了,全部要求field存在,不然会更新为默认零值

同时,即使指定了默认值,生成的语句也不是按照默认值来的 ``` payTime time.Time `xorm:"not null default '0001-01-01 00:00:00' pay_time"` ``` 生成的语句依然是: ``` INSERT INTO `user` (`pay_time`) Values(?) []interface{}{""} ``` 此时,指定了`not null`,所以 time.Time在这里又变成了 "" ,而不是之前的 interface{}(nil). 此时,如果mysql数据的sql_mode设置的是严格模式(一般情况下都是严格模式),这这种日期会被认为是非法的日期,从而导致插入数据库不成功。

xorm 生成sql的表现如果这么不可控的话,如果遇上特定sql_mode的设置,更容易出问题。

避免这么多不可控因素最好的方案就是,对于 time.Time 的默认值,首先按照 struct tag中定义的 default value来传递,如果struct tag 中没有定义default 值,那么应该采用golang的默认值: '0001-01-01 00:00:00' ,而不是一会儿是 "", 一会又是 interface{}(nil)

@lunny 来帮忙看看是不是这么个情况?或者可以代码中可以手动指定 session级别的sql_mode?

升级xorm后,sql中的time.Time默认值变为 interface{}(nil) 指定字段NOT NULL后,sql中的time.Time默认值为"", 均无法满足原有数据库字段NOT NULL DEFAULT '0000-00-00 00:00:00'的要求.(msyql5.7 严格模式下) 因此,目前一个兼容方案是 当 time.Time isZero,插入数据时省略该字段 ``` if user.LoginTime.IsZero(){ session = session.Omit("login_time") } ```

没有默认值时,建议最好不要用nil. 原因有三: 第一, golang中 time.Time 和 nil 是不能直接相等的,time.Time 的默认值不是 nil ``` t := new(time.Time) if *t == nil { // panic . cannot convert nil to type time.Time fmt.Println("err") }...

if u use dep, change revision to `9aa49832a739dcd78a5542ff189fb82c3e423116` can resolve this problem,but i`m not sure is there any other problems