Skip to content

Commit

Permalink
Refactor getInterfaceAsSql
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Nov 11, 2014
1 parent aab0b28 commit dcdbb72
Showing 1 changed file with 5 additions and 44 deletions.
49 changes: 5 additions & 44 deletions search.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gorm

import "strconv"
import "fmt"

type search struct {
db *DB
Expand Down Expand Up @@ -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
}

0 comments on commit dcdbb72

Please sign in to comment.