Skip to content
This repository has been archived by the owner on Jun 14, 2019. It is now read-only.

Fix empty IN/NOT IN conditions #4

Merged
merged 1 commit into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cond_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ func In(col string, values ...interface{}) Cond {
}

func (condIn condIn) handleBlank(w Writer) error {
if _, err := fmt.Fprintf(w, "%s IN ()", condIn.col); err != nil {
return err
}
return nil
_, err := fmt.Fprint(w, "0=1")
return err
}

func (condIn condIn) WriteTo(w Writer) error {
Expand Down
6 changes: 2 additions & 4 deletions cond_notin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ func NotIn(col string, values ...interface{}) Cond {
}

func (condNotIn condNotIn) handleBlank(w Writer) error {
if _, err := fmt.Fprintf(w, "%s NOT IN ()", condNotIn.col); err != nil {
return err
}
return nil
_, err := fmt.Fprint(w, "0=0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not "1=0"? consider x.NotIn("id", []int64{}).Delete(new(User))

Copy link
Contributor Author

@ethantkoenig ethantkoenig May 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't your example delete all users (i.e. every user whose id is not in the empty list)? So we would want "0=0", not "1=0".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

return err
}

func (condNotIn condNotIn) WriteTo(w Writer) error {
Expand Down