From b32c5badd2828eba50f24694c81065dd55f5e66e Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 11 Nov 2014 13:36:12 +0800 Subject: [PATCH] Refactor getInterfaceAsSql --- search.go | 49 +++++-------------------------------------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/search.go b/search.go index cda297b6..8591d659 100644 --- a/search.go +++ b/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 }