aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/go-xorm/builder/cond_notin.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-06-07 01:19:32 -0400
committerUnknwon <u@gogs.io>2017-06-07 01:19:32 -0400
commitb40dc550ed15efd2c6faa1ea619888a400499a84 (patch)
treea5a064eed5e4e913fdbba23f8ab278844655863d /vendor/github.com/go-xorm/builder/cond_notin.go
parentc210984b40a23f20bebe1f905ff6b1297c3ad901 (diff)
vendor: update github.com/go-xorm/* (#4419)
Diffstat (limited to 'vendor/github.com/go-xorm/builder/cond_notin.go')
-rw-r--r--vendor/github.com/go-xorm/builder/cond_notin.go57
1 files changed, 40 insertions, 17 deletions
diff --git a/vendor/github.com/go-xorm/builder/cond_notin.go b/vendor/github.com/go-xorm/builder/cond_notin.go
index 47c16be2..dc3ac49a 100644
--- a/vendor/github.com/go-xorm/builder/cond_notin.go
+++ b/vendor/github.com/go-xorm/builder/cond_notin.go
@@ -6,6 +6,7 @@ package builder
import (
"fmt"
+ "reflect"
"strings"
)
@@ -18,16 +19,21 @@ func NotIn(col string, values ...interface{}) Cond {
return condNotIn{col, values}
}
+func (condNotIn condNotIn) handleBlank(w Writer) error {
+ _, err := fmt.Fprint(w, "0=0")
+ return err
+}
+
func (condNotIn condNotIn) WriteTo(w Writer) error {
if len(condNotIn.vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
switch condNotIn.vals[0].(type) {
case []int8:
vals := condNotIn.vals[0].([]int8)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -39,7 +45,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int16:
vals := condNotIn.vals[0].([]int16)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -51,7 +57,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int:
vals := condNotIn.vals[0].([]int)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -63,7 +69,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int32:
vals := condNotIn.vals[0].([]int32)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -75,7 +81,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int64:
vals := condNotIn.vals[0].([]int64)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -87,7 +93,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint8:
vals := condNotIn.vals[0].([]uint8)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -99,7 +105,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint16:
vals := condNotIn.vals[0].([]uint16)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -111,7 +117,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint:
vals := condNotIn.vals[0].([]uint)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -123,7 +129,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint32:
vals := condNotIn.vals[0].([]uint32)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -135,7 +141,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint64:
vals := condNotIn.vals[0].([]uint64)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -147,7 +153,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []string:
vals := condNotIn.vals[0].([]string)
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -159,7 +165,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []interface{}:
vals := condNotIn.vals[0].([]interface{})
if len(vals) <= 0 {
- return ErrNoNotInConditions
+ return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@@ -189,11 +195,28 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
return err
}
default:
- questionMark := strings.Repeat("?,", len(condNotIn.vals))
- if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
- return err
+ v := reflect.ValueOf(condNotIn.vals[0])
+ if v.Kind() == reflect.Slice {
+ l := v.Len()
+ if l == 0 {
+ return condNotIn.handleBlank(w)
+ }
+
+ questionMark := strings.Repeat("?,", l)
+ if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
+ return err
+ }
+
+ for i := 0; i < l; i++ {
+ w.Append(v.Index(i).Interface())
+ }
+ } else {
+ questionMark := strings.Repeat("?,", len(condNotIn.vals))
+ if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
+ return err
+ }
+ w.Append(condNotIn.vals...)
}
- w.Append(condNotIn.vals...)
}
return nil
}