diff options
author | Mark Longair <mhl@pobox.com> | 2013-08-29 10:13:18 +0100 |
---|---|---|
committer | Mark Longair <mhl@pobox.com> | 2013-08-29 14:53:10 +0100 |
commit | 17199cf44fd4ad8dcf700a13126607c42bb3be34 (patch) | |
tree | 03a3c4919d8e236725e1bb32db91ab6774e641cd /app/controllers/public_body_controller.rb | |
parent | 0b12ae4013ccbbee07b1d59c095b6508aedbfdcd (diff) |
Tidy up SQL query strings
In the list method of PublicBodyController, capitalize
the SQL keywords consistenly and don't include extraneous
whitespace in the strings. (On the former point,
previously only some were - the convention is a matter of
some debate, but in this case the you editor's not doing
to do syntax highlighting of SQL so having the keywords
capitalized helps its readibility, I think.)
I wouldn't normally do this kind of cosmetic tidying up,
since it affects the tidiness of diffs and merges, but in
this case I'm going to change all these lines in the
next commit anyway, so that reasoning doesn't apply.
Diffstat (limited to 'app/controllers/public_body_controller.rb')
-rw-r--r-- | app/controllers/public_body_controller.rb | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 374866eda..e51edc7bd 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -89,30 +89,30 @@ class PublicBodyController < ApplicationController @tag = params[:tag] @locale = self.locale_from_params() default_locale = I18n.default_locale.to_s - locale_condition = "(upper(public_body_translations.name) LIKE upper(?) - OR upper(public_body_translations.notes) LIKE upper (?)) - AND public_body_translations.locale = ? - AND public_bodies.id <> #{PublicBody.internal_admin_body.id}" + locale_condition = "(upper(public_body_translations.name) LIKE upper(?)" \ + " OR upper(public_body_translations.notes) LIKE upper (?))" \ + " AND public_body_translations.locale = ?" \ + " AND public_bodies.id <> #{PublicBody.internal_admin_body.id}" if @tag.nil? or @tag == "all" @tag = "all" conditions = [locale_condition, @query, @query, default_locale] elsif @tag == 'other' category_list = PublicBodyCategories::get().tags().map{|c| "'"+c+"'"}.join(",") - conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id - and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @query, default_locale] + conditions = [locale_condition + " AND (SELECT count(*) FROM has_tag_string_tags WHERE has_tag_string_tags.model_id = public_bodies.id" \ + " AND has_tag_string_tags.model = 'PublicBody'" \ + " AND has_tag_string_tags.name IN (#{category_list})) = 0", @query, @query, default_locale] elsif @tag.size == 1 @tag.upcase! - conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @query, default_locale, @tag] + conditions = [locale_condition + " AND public_body_translations.first_letter = ?", @query, @query, default_locale, @tag] elsif @tag.include?(":") name, value = HasTagString::HasTagStringTag.split_tag_into_name_value(@tag) - conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id - and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @query, default_locale, name, value] + conditions = [locale_condition + " AND (SELECT count(*) FROM has_tag_string_tags WHERE has_tag_string_tags.model_id = public_bodies.id" \ + " AND has_tag_string_tags.model = 'PublicBody'" \ + " AND has_tag_string_tags.name = ? AND has_tag_string_tags.value = ?) > 0", @query, @query, default_locale, name, value] else - conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id - and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ?) > 0', @query, @query, default_locale, @tag] + conditions = [locale_condition + " AND (SELECT count(*) FROM has_tag_string_tags WHERE has_tag_string_tags.model_id = public_bodies.id" \ + " AND has_tag_string_tags.model = 'PublicBody'" \ + " AND has_tag_string_tags.name = ?) > 0", @query, @query, default_locale, @tag] end if @tag == "all" |