|
@@ -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
|
|
|
}
|