Permalink
Browse files

renaming bind_values to binds where it makes sense

  • Loading branch information...
1 parent 104d0b2 commit e73b0b84d939af241dfbba8931d8add9724595e4 @tenderlove tenderlove committed Oct 26, 2010
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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] ||= {
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)

0 comments on commit e73b0b8

Please sign in to comment.