go-xorm / xorm

Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
BSD 3-Clause "New" or "Revised" License
6.67k stars 754 forks source link

SQL error occurs when selecting table if delete timestamp is an UNIX timestamp #998

Open chenjianying opened 6 years ago

chenjianying commented 6 years ago

Now, I use a big int column as delete timestamp of table which is stored with an UNIX timestamp, but XORM build out an invalid SQL with delete_timestamp = '01-00-01 xxxx', NOT delete_timestamp=0.

So I try to modified code below to fix this issue.

// CondDeleted returns the conditions whether a record is soft deleted.
func (engine *Engine) CondDeleted(sqlTypeName, colName string) builder.Cond {
    if engine.dialect.DBType() == core.MSSQL {
        return builder.IsNull{colName}
    }

    switch sqlTypeName {
    case core.BigInt, core.Int:
        return builder.IsNull{colName}.Or(builder.Eq{colName: 0})
    default:
        return builder.IsNull{colName}.Or(builder.Eq{colName: zeroTime1})
    }
}
lunny commented 6 years ago

could you send a pull request?