Skip to content

Commit

Permalink
Fix NULL handling of not equal statements in SQL.
Browse files Browse the repository at this point in the history
We want to treat NULL values as not equal to the given value, so use IS
DISTINCT FROM instead.
  • Loading branch information
GUI committed Mar 23, 2016
1 parent 455eaf0 commit 77ed897
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/api-umbrella/web-app/app/models/log_search/sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def parse_query_builder(query)
when "equal"
operator = "="
when "not_equal"
operator = "<>"
# Use IS DISTINCT FROM instead of <> (aka !=), since we want to treat
# NULL values as not equal to the given value.
operator = "IS DISTINCT FROM"
when "begins_with"
operator = "LIKE"
value = "#{value}%"
Expand Down Expand Up @@ -303,7 +305,7 @@ def parse_query_builder(query)

if(index < levels.length - 1)
if(["not_equal", "not_begins_with"].include?(rule["operator"]))
level_operator = "<>"
level_operator = "IS DISTINCT FROM"
else
level_operator = "="
end
Expand Down Expand Up @@ -370,7 +372,7 @@ def sort!(sort)
end

def exclude_imported!
@query[:where] << "log_imported <> true"
@query[:where] << "log_imported IS DISTINCT FROM true"
end

def filter_by_date_range!
Expand Down

0 comments on commit 77ed897

Please sign in to comment.