account.rb 1.3 KB
Newer Older
J
Justin Collins 已提交
1
class Account < ActiveRecord::Base
2
  attr_accessible :name, :account_id, :admin
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

  def sql_it_up_yeah
    connection.exec_update "UPDATE `purchases` SET type = '#{self.type}' WHERE id = '#{self.id}'"

    sql = "UPDATE #{self.class.table_name} SET latest_version = #{version} where id = #{self.id}"
    self.class.connection.execute sql
  end

  def self.more_sql_connection
    self.connection.exec_query "UPDATE `purchases` SET type = '#{self.type}' WHERE id = '#{self.id}'"
  end

  def safe_sql_should_not_warn
    self.class.connection.execute "DESCRIBE  #{self.business_object.table_name}"
    connection.select_one "SELECT * FROM somewhere WHERE x=#{connection.quote(params[:x])}"
    connection.execute "DELETE FROM stuff WHERE id=#{self.id}"
  end
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

  def lots_of_string_building_sql
    sql =
      'SELECT count(*) as account_count, '+
      'FROM account_links stuff_links '+
      "WHERE account_links.stuff_id = #{@stuff.id} "

    if params[:more_ids]
      sql += " AND stuff IN "+
        "(SELECT something_id "+
        "FROM some_join_thing "+
        "WHERE something_id IN (#{params[:more_ids].join(',')}))"
    end
    sql += "GROUP BY title, id "
    Account.connection.select_all(sql)
  end
J
Justin Collins 已提交
36 37 38 39 40

  def self.get_all_countries(locale)
    q = "country_#{locale} ASC".to_s
    c = User.order(q)
  end
J
Justin Collins 已提交
41
end