Skip to content

Commit

Permalink
renaming bind_values to binds where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 26, 2010
1 parent 104d0b2 commit e73b0b8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -448,8 +448,8 @@ class << self # Class methods
# # You can use the same string replacement techniques as you can with ActiveRecord#find
# Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
# > [#<Post:0x36bff9c @attributes={"first_name"=>"The Cheap Man Buys Twice"}>, ...]
def find_by_sql(sql, bind_values = [])
connection.select_all(sanitize_sql(sql), "#{name} Load", bind_values).collect! { |record| instantiate(record) }
def find_by_sql(sql, binds = [])
connection.select_all(sanitize_sql(sql), "#{name} Load", binds).collect! { |record| instantiate(record) }
end

# Creates an object (or multiple objects) and saves it to the database, if validations pass.
Expand Down
Expand Up @@ -3,12 +3,12 @@ module ConnectionAdapters # :nodoc:
module DatabaseStatements
# Returns an array of record hashes with the column names as keys and
# column values as values.
def select_all(sql, name = nil, bind_values = [])
def select_all(sql, name = nil, binds = [])
if supports_statement_cache?
select(sql, name, bind_values)
select(sql, name, binds)
else
return select(sql, name) if bind_values.empty?
binds = bind_values.dup
return select(sql, name) if binds.empty?
binds = binds.dup
select sql.gsub('?') {
quote(*binds.shift.reverse)
}, name
Expand Down Expand Up @@ -48,7 +48,7 @@ def execute(sql, name = nil)
undef_method :execute

# Executes +sql+ statement in the context of this connection using
# +bind_values+ as the bind substitutes. +name+ is logged along with
# +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement.
def exec(sql, name = 'SQL', binds = [])
end
Expand Down Expand Up @@ -274,7 +274,7 @@ def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
protected
# Returns an array of record hashes with the column names as keys and
# column values as values.
def select(sql, name = nil, bind_values = [])
def select(sql, name = nil, binds = [])
end
undef_method :select

Expand Down
Expand Up @@ -99,8 +99,8 @@ def quote_table_name(name)
end

# Returns a bind substitution value given a +column+ and list of current
# +bind_values+
def substitute_for(column, bind_values)
# +binds+
def substitute_for(column, binds)
Arel.sql '?'
end

Expand Down
Expand Up @@ -326,12 +326,12 @@ def clear_cache!
@statements.clear
end

def exec(sql, name = 'SQL', bind_values = [])
def exec(sql, name = 'SQL', binds = [])
log(sql, name) do
result = nil

cache = {}
if bind_values.empty?
if binds.empty?
stmt = @connection.prepare(sql)
else
cache = @statements[sql] ||= {
Expand All @@ -340,7 +340,7 @@ def exec(sql, name = 'SQL', bind_values = [])
stmt = cache[:stmt]
end

stmt.execute(*bind_values.map { |col, val|
stmt.execute(*binds.map { |col, val|
col ? col.type_cast(val) : val
})
if metadata = stmt.result_metadata
Expand All @@ -353,7 +353,7 @@ def exec(sql, name = 'SQL', bind_values = [])
end

stmt.free_result
stmt.close if bind_values.empty?
stmt.close if binds.empty?

result
end
Expand Down
Expand Up @@ -143,11 +143,11 @@ def quoted_date(value) #:nodoc:

# DATABASE STATEMENTS ======================================

def exec(sql, name = nil, bind_values = [])
def exec(sql, name = nil, binds = [])
log(sql, name) do

# Don't cache statements without bind values
if bind_values.empty?
if binds.empty?
stmt = @connection.prepare(sql)
cols = stmt.columns
else
Expand All @@ -157,7 +157,7 @@ def exec(sql, name = nil, bind_values = [])
stmt = cache[:stmt]
cols = cache[:cols] ||= stmt.columns
stmt.reset!
stmt.bind_params bind_values.map { |col, val|
stmt.bind_params binds.map { |col, val|
col ? col.type_cast(val) : val
}
end
Expand Down Expand Up @@ -313,8 +313,8 @@ def empty_insert_statement_value
end

protected
def select(sql, name = nil, bind_values = []) #:nodoc:
exec(sql, name, bind_values).map do |row|
def select(sql, name = nil, binds = []) #:nodoc:
exec(sql, name, binds).map do |row|
record = {}
row.each do |key, value|
record[key.sub(/^"?\w+"?\./, '')] = value if key.is_a?(String)
Expand Down

0 comments on commit e73b0b8

Please sign in to comment.