mirror of https://github.com/go-gorm/gorm.git
Refactor getInterfaceAsSql
This commit is contained in:
parent
828bf5d5fd
commit
b32c5badd2
49
search.go
49
search.go
|
@ -1,6 +1,6 @@
|
|||
package gorm
|
||||
|
||||
import "strconv"
|
||||
import "fmt"
|
||||
|
||||
type search struct {
|
||||
db *DB
|
||||
|
@ -125,54 +125,15 @@ func (s *search) table(name string) *search {
|
|||
}
|
||||
|
||||
func (s *search) getInterfaceAsSql(value interface{}) (str string) {
|
||||
var s_num int64
|
||||
var u_num uint64
|
||||
var isString, unsigned bool = false, false
|
||||
|
||||
switch value.(type) {
|
||||
case string:
|
||||
str = value.(string)
|
||||
isString = true
|
||||
case int:
|
||||
s_num = int64(value.(int))
|
||||
case int8:
|
||||
s_num = int64(value.(int8))
|
||||
case int16:
|
||||
s_num = int64(value.(int16))
|
||||
case int32:
|
||||
s_num = int64(value.(int32))
|
||||
case int64:
|
||||
s_num = int64(value.(int64))
|
||||
case uint:
|
||||
u_num = uint64(value.(uint))
|
||||
unsigned = true
|
||||
case uint8:
|
||||
u_num = uint64(value.(uint8))
|
||||
unsigned = true
|
||||
case uint16:
|
||||
u_num = uint64(value.(uint16))
|
||||
unsigned = true
|
||||
case uint32:
|
||||
u_num = uint64(value.(uint32))
|
||||
unsigned = true
|
||||
case uint64:
|
||||
u_num = uint64(value.(uint64))
|
||||
unsigned = true
|
||||
case string, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
str = fmt.Sprintf("%v", value)
|
||||
default:
|
||||
s.db.err(InvalidSql)
|
||||
}
|
||||
|
||||
if !isString {
|
||||
if unsigned {
|
||||
str = strconv.FormatUint(u_num, 10)
|
||||
} else {
|
||||
if s_num < 0 {
|
||||
str = ""
|
||||
} else {
|
||||
str = strconv.FormatInt(s_num, 10)
|
||||
if str == "-1" {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue