|
|
|
@ -175,7 +175,7 @@ class Report::SqlStatement |
|
|
|
|
return(@select || default_select) if fields.empty? |
|
|
|
|
(@select ||= []).tap do |
|
|
|
|
@sql = nil |
|
|
|
|
fields.each do |f| |
|
|
|
|
fields.reject {|f| never_select.include? f}.each do |f| |
|
|
|
|
case f |
|
|
|
|
when Array |
|
|
|
|
if f.size == 2 and f.first.respond_to? :table_name then select field_name_for(f) |
|
|
|
@ -193,6 +193,22 @@ class Report::SqlStatement |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def unselect(*fields) |
|
|
|
|
@sql = nil |
|
|
|
|
@select = @select.reject do |field| |
|
|
|
|
fields.find { |f| f == field } |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def never_select(*fields) |
|
|
|
|
(@never_select ||= []).tap do |
|
|
|
|
unless fields.empty? |
|
|
|
|
@never_select += fields |
|
|
|
|
unselect *fields |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
## |
|
|
|
|
# Return the names which have been bound through select statements |
|
|
|
|
# @return [Array<String>] All fields for select part |
|
|
|
@ -210,7 +226,7 @@ class Report::SqlStatement |
|
|
|
|
def group_by(*fields) |
|
|
|
|
@sql = nil unless fields.empty? |
|
|
|
|
(@group_by ||= []).tap do |
|
|
|
|
fields.each do |e| |
|
|
|
|
fields.reject {|f| never_group_by.include? f}.each do |e| |
|
|
|
|
if e.is_a? Array and (e.size != 2 or !e.first.respond_to? :table_name) |
|
|
|
|
group_by(*e) |
|
|
|
|
else |
|
|
|
@ -221,6 +237,22 @@ class Report::SqlStatement |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def group_not_by(*fields) |
|
|
|
|
@sql = nil |
|
|
|
|
@group_by = @group_by.reject do |field| |
|
|
|
|
fields.find { |f| f == field } |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def never_group_by(*fields) |
|
|
|
|
(@never_group_by ||= []).tap do |
|
|
|
|
unless fields.empty? |
|
|
|
|
@never_group_by += fields |
|
|
|
|
group_not_by *fields |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
## |
|
|
|
|
# @return [TrueClass, FalseClass] Whether or not to add a group by part. |
|
|
|
|
def group_by? |
|
|
|
|