make adapter_name switch dry

pull/6827/head
Philipp Tessenow 14 years ago
parent ce729a0f24
commit d4936329ef
  1. 9
      app/models/cost_query/query_utils.rb

@ -127,14 +127,13 @@ module CostQuery::QueryUtils
def iso_year_week(field, default_table = nil) def iso_year_week(field, default_table = nil)
field = field_name_for(field, default_table) field = field_name_for(field, default_table)
"-- code specific for #{adapter_name}\n\t" << \ "-- code specific for #{adapter_name}\n\t" << \
case adapter_name.to_s.downcase.to_sym if mysql?
when :mysql, :mysql2
"yearweek(#{field}, 1)" "yearweek(#{field}, 1)"
when :postgresql elsif postgresql?
"(EXTRACT(isoyear from #{field})*100 + \n\t\t" \ "(EXTRACT(isoyear from #{field})*100 + \n\t\t" \
"EXTRACT(week from #{field} - \n\t\t" \ "EXTRACT(week from #{field} - \n\t\t" \
"(EXTRACT(dow FROM #{field})::int+6)%7))" "(EXTRACT(dow FROM #{field})::int+6)%7))"
when :sqlite elsif sqlite?
# enjoy # enjoy
<<-EOS <<-EOS
case case
@ -197,7 +196,7 @@ module CostQuery::QueryUtils
end end
def mysql? def mysql?
adapter_name == :mysql [:mysql, :mysql2].include? adapter_name.to_s.downcase.to_sym
end end
def sqlite? def sqlite?

Loading…
Cancel
Save