mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Query doesn't work with non ASCII uppercase symbols (#20438).
git-svn-id: http://svn.redmine.org/redmine/trunk@14476 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
df1093a4af
commit
d4723bb05f
@ -779,9 +779,9 @@ class Query < ActiveRecord::Base
|
|||||||
date = Date.today
|
date = Date.today
|
||||||
sql = date_clause(db_table, db_field, date.beginning_of_year, date.end_of_year, is_custom_filter)
|
sql = date_clause(db_table, db_field, date.beginning_of_year, date.end_of_year, is_custom_filter)
|
||||||
when "~"
|
when "~"
|
||||||
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{self.class.connection.quote_string(value.first.to_s.downcase)}%'"
|
sql = sql_contains("#{db_table}.#{db_field}", value.first)
|
||||||
when "!~"
|
when "!~"
|
||||||
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{self.class.connection.quote_string(value.first.to_s.downcase)}%'"
|
sql = sql_contains("#{db_table}.#{db_field}", value.first, false)
|
||||||
else
|
else
|
||||||
raise "Unknown query operator #{operator}"
|
raise "Unknown query operator #{operator}"
|
||||||
end
|
end
|
||||||
@ -789,6 +789,12 @@ class Query < ActiveRecord::Base
|
|||||||
return sql
|
return sql
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a SQL LIKE statement with wildcards
|
||||||
|
def sql_contains(db_field, value, match=true)
|
||||||
|
value = "'%#{self.class.connection.quote_string(value.to_s)}%'"
|
||||||
|
Redmine::Database.like(db_field, value, :match => match)
|
||||||
|
end
|
||||||
|
|
||||||
# Adds a filter for the given custom field
|
# Adds a filter for the given custom field
|
||||||
def add_custom_field_filter(field, assoc=nil)
|
def add_custom_field_filter(field, assoc=nil)
|
||||||
options = field.format.query_filter_options(field, self)
|
options = field.format.query_filter_options(field, self)
|
||||||
|
|||||||
@ -159,15 +159,7 @@ module Redmine
|
|||||||
private :search_tokens_condition
|
private :search_tokens_condition
|
||||||
|
|
||||||
def search_token_match_statement(column, value='?')
|
def search_token_match_statement(column, value='?')
|
||||||
if Redmine::Database.postgresql?
|
Redmine::Database.like(column, value)
|
||||||
if Redmine::Database.postgresql_unaccent?
|
|
||||||
"unaccent(#{column}) ILIKE unaccent(#{value})"
|
|
||||||
else
|
|
||||||
"#{column} ILIKE #{value}"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
"#{column} LIKE #{value}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
private :search_token_match_statement
|
private :search_token_match_statement
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,21 @@ module Redmine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a SQL statement for case/accent (if possible) insensitive match
|
||||||
|
def like(left, right, options={})
|
||||||
|
neg = (options[:match] == false ? 'NOT ' : '')
|
||||||
|
|
||||||
|
if postgresql?
|
||||||
|
if postgresql_unaccent?
|
||||||
|
"unaccent(#{left}) #{neg}ILIKE unaccent(#{right})"
|
||||||
|
else
|
||||||
|
"#{left} #{neg}ILIKE #{right}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
"#{left} #{neg}LIKE #{right}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Resets database information
|
# Resets database information
|
||||||
def reset
|
def reset
|
||||||
@postgresql_unaccent = nil
|
@postgresql_unaccent = nil
|
||||||
|
|||||||
@ -592,12 +592,22 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_operator_contains
|
def test_operator_contains
|
||||||
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
issue = Issue.generate!(:subject => 'AbCdEfG')
|
||||||
query.add_filter('subject', '~', ['uNable'])
|
|
||||||
assert query.statement.include?("LOWER(#{Issue.table_name}.subject) LIKE '%unable%'")
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.add_filter('subject', '~', ['cdeF'])
|
||||||
result = find_issues_with_query(query)
|
result = find_issues_with_query(query)
|
||||||
assert result.empty?
|
assert_include issue, result
|
||||||
result.each {|issue| assert issue.subject.downcase.include?('unable') }
|
result.each {|issue| assert issue.subject.downcase.include?('cdef') }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_operator_does_not_contain
|
||||||
|
issue = Issue.generate!(:subject => 'AbCdEfG')
|
||||||
|
|
||||||
|
query = IssueQuery.new(:name => '_')
|
||||||
|
query.add_filter('subject', '!~', ['cdeF'])
|
||||||
|
result = find_issues_with_query(query)
|
||||||
|
assert_not_include issue, result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_range_for_this_week_with_week_starting_on_monday
|
def test_range_for_this_week_with_week_starting_on_monday
|
||||||
@ -625,13 +635,6 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
query.statement
|
query.statement
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_operator_does_not_contains
|
|
||||||
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
|
||||||
query.add_filter('subject', '!~', ['uNable'])
|
|
||||||
assert query.statement.include?("LOWER(#{Issue.table_name}.subject) NOT LIKE '%unable%'")
|
|
||||||
find_issues_with_query(query)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_filter_assigned_to_me
|
def test_filter_assigned_to_me
|
||||||
user = User.find(2)
|
user = User.find(2)
|
||||||
group = Group.find(10)
|
group = Group.find(10)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user