def self.union(*unions) u_sql = unions[0].to_query a = *unions a.each do |u| u_sql << " UNION " << u.to_query end u_sql end
def self.union_all(*unions) u_sql = unions[0].to_query a = *unions a.each do |u| u_sql << " UNION ALL " << u.to_query end u_sql end
def record @record end
def params @params end
def merge_param(param) @params = @params.merge(param) end
def columns @columns end
def orders @orders end
def groups @groups end
def conditions @conditions end
def joins @joins end
def havings @havings end
def firsts @firsts end
def lasts @lasts end
def limit @limit end
def limit=(att) @limit = att end
def offset @offset end
def offset=(att) @offset = att end
def table_name @table_name end
def to_columns str = "" @columns.each do |item| str << item + ',' end str = str.chop (str << @table_name << ".*") if columns.size == 0 str end
def to_orders str = "" @orders.each do |item| str << item + ',' end str.chop end
def to_groups str = "" @groups.each do |item| str << item + ',' end str.chop end
def to_conditions str = "" @conditions.each do |item| str << item + ' ' end str.chop end
def to_havings str = "" @havings.each do |item| str << item + ' ' end str.chop end
def to_firsts str = "" @firsts.each do |item| str << item + ' ' end str.chop end
def to_lasts str = "" @lasts.each do |item| str << item + ' ' end str.chop end
def to_joins str = "" @joins.each do |item| str << item + ' ' end str.chop end
def to_query first = to_firsts condition = to_conditions join = to_joins column = to_columns group = to_groups having = to_havings order = to_orders last = to_lasts sql = "SELECT " sql << column if !column.empty? sql << " FORM " sql << @table_name sql << " " << join if !join.empty? sql << " WHERE " << condition if !condition.empty? sql << group if !group.empty? sql << having if !having.empty? sql << order if !order.empty? sql << " LIMIT " << @limit.to_s if !@limit.nil?
if !@limit.nil? sql << "," << @offset.to_s if !@offset.nil? else sql << "0," << @offset.to_s if !@offset.nil? end
(sql << " " << last) if !last.empty?
(sql.insert 0,(first << " ")) if !first.empty? sql end