Skip to content

Commit

Permalink
BuildCmp Value Error Message Changed
Browse files Browse the repository at this point in the history
  • Loading branch information
kpango committed Aug 14, 2018
1 parent 94701cb commit 66668ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,21 @@ func Lte(column string, value interface{}) Builder {

func buildLikeCmp(d Dialect, buf Buffer, pred string, column string, value interface{}) error {
if value == nil {
return ErrColumnNotSpecified
return ErrInvalidValue
}

v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.String:
// pass as is
return buildCmp(d, buf, pred, column, value)

case reflect.Ptr, reflect.Interface: // pointer or interface
// for pointers & interfaces check
return buildLikeCmp(d, buf, pred, column, v.Elem().Interface())

case reflect.Slice:

switch v.Type().Elem().Kind() {
case reflect.Uint8: // bytes
// interpolator will handle this case
Expand All @@ -142,10 +145,10 @@ func buildLikeCmp(d Dialect, buf Buffer, pred string, column string, value inter
// need to convert into string
return buildCmp(d, buf, pred, column, string(value.([]rune)))
}
fallthrough
default:
return ErrColumnNotSpecified

}

return ErrInvalidValue
}

// Like is `LIKE`.
Expand Down
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ var (
ErrInvalidSliceLength = errors.New("dbr: length of slice is 0. length must be >= 1")
ErrCantConvertToTime = errors.New("dbr: can't convert to time.Time")
ErrInvalidTimestring = errors.New("dbr: invalid time string")
ErrInvalidValue = errors.New("dbr: invalid value")
)

0 comments on commit 66668ec

Please sign in to comment.