renaming bind_values to binds where it makes sense

This commit is contained in:
Aaron Patterson
2010-10-26 13:02:14 -07:00
parent 104d0b263e
commit e73b0b84d9
5 changed files with 19 additions and 19 deletions

View File

@@ -448,8 +448,8 @@ module ActiveRecord #:nodoc:
# # 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.

View File

@@ -3,12 +3,12 @@ module ActiveRecord
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
@@ -48,7 +48,7 @@ module ActiveRecord
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
@@ -274,7 +274,7 @@ module ActiveRecord
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

View File

@@ -99,8 +99,8 @@ module ActiveRecord
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

View File

@@ -326,12 +326,12 @@ module ActiveRecord
@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] ||= {
@@ -340,7 +340,7 @@ module ActiveRecord
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
@@ -353,7 +353,7 @@ module ActiveRecord
end
stmt.free_result
stmt.close if bind_values.empty?
stmt.close if binds.empty?
result
end

View File

@@ -143,11 +143,11 @@ module ActiveRecord
# 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
@@ -157,7 +157,7 @@ module ActiveRecord
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
@@ -313,8 +313,8 @@ module ActiveRecord
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)