Skip to content
Browse files

Rename quote to quote_value so the name can be used in AR models. #3628

… [Koz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5007 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 97487c4 commit b445ab986a2c177621a2154b0559be4c700abeeb @NZKoz NZKoz committed Sep 4, 2006
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Rename AR::Base#quote so people can use that name in their models. #3628 [Koz]
+
* Add deprecation warning for inferred foreign key. #6029 [Josh Susser]
* Fixed the Ruby/MySQL adapter we ship with Active Record to work with the new authentication handshake that was introduced in MySQL 4.1, along with the other protocol changes made at that time #5723 [jimw@mysql.com]
View
10 activerecord/lib/active_record/associations.rb
@@ -1457,7 +1457,7 @@ def association_join
table_alias_for(through_reflection.klass.table_name, aliased_join_table_name),
aliased_join_table_name, polymorphic_foreign_key,
parent.aliased_table_name, parent.primary_key,
- aliased_join_table_name, polymorphic_foreign_type, klass.quote(parent.active_record.base_class.name)] +
+ aliased_join_table_name, polymorphic_foreign_type, klass.quote_value(parent.active_record.base_class.name)] +
" LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [table_name_and_alias,
aliased_table_name, primary_key, aliased_join_table_name, options[:foreign_key] || reflection.klass.to_s.classify.foreign_key
]
@@ -1472,7 +1472,7 @@ def association_join
aliased_table_name, "#{source_reflection.options[:as]}_id",
aliased_join_table_name, options[:foreign_key] || primary_key,
aliased_table_name, "#{source_reflection.options[:as]}_type",
- klass.quote(source_reflection.active_record.base_class.name)
+ klass.quote_value(source_reflection.active_record.base_class.name)
]
else
case source_reflection.macro
@@ -1501,15 +1501,15 @@ def association_join
aliased_table_name, "#{reflection.options[:as]}_id",
parent.aliased_table_name, parent.primary_key,
aliased_table_name, "#{reflection.options[:as]}_type",
- klass.quote(parent.active_record.base_class.name)
+ klass.quote_value(parent.active_record.base_class.name)
]
when reflection.macro == :has_one && reflection.options[:as]
" LEFT OUTER JOIN %s ON %s.%s = %s.%s AND %s.%s = %s " % [
table_name_and_alias,
aliased_table_name, "#{reflection.options[:as]}_id",
parent.aliased_table_name, parent.primary_key,
aliased_table_name, "#{reflection.options[:as]}_type",
- klass.quote(reflection.active_record.base_class.name)
+ klass.quote_value(reflection.active_record.base_class.name)
]
else
foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key
@@ -1530,7 +1530,7 @@ def association_join
join << %(AND %s.%s = %s ) % [
aliased_table_name,
reflection.active_record.connection.quote_column_name(reflection.active_record.inheritance_column),
- klass.quote(klass.name.demodulize)] unless klass.descends_from_active_record?
+ klass.quote_value(klass.name.demodulize)] unless klass.descends_from_active_record?
join << "AND #{interpolate_sql(sanitize_sql(reflection.options[:conditions]))} " if reflection.options[:conditions]
join
end
View
2 activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -118,7 +118,7 @@ def insert_record(record)
attributes[column.name] = record.quoted_id
else
if record.attributes.has_key?(column.name)
- value = @owner.send(:quote, record[column.name], column)
+ value = @owner.send(:quote_value, record[column.name], column)
attributes[column.name] = value unless value.nil?
end
end
View
2 activerecord/lib/active_record/associations/has_many_association.rb
@@ -184,7 +184,7 @@ def construct_sql
when @reflection.options[:as]
@finder_sql =
"#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " +
- "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}"
+ "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
@finder_sql << " AND (#{conditions})" if conditions
else
View
4 activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -127,7 +127,7 @@ def construct_join_attributes(associate)
def construct_quoted_owner_attributes(reflection)
if as = reflection.options[:as]
{ "#{as}_id" => @owner.quoted_id,
- "#{as}_type" => reflection.klass.quote(
+ "#{as}_type" => reflection.klass.quote_value(
@owner.class.base_class.name.to_s,
reflection.klass.columns_hash["#{as}_type"]) }
else
@@ -164,7 +164,7 @@ def construct_joins(custom_joins = nil)
if @reflection.source_reflection.options[:as]
polymorphic_join = "AND %s.%s = %s" % [
@reflection.table_name, "#{@reflection.source_reflection.options[:as]}_type",
- @owner.class.quote(@reflection.through_reflection.klass.name)
+ @owner.class.quote_value(@reflection.through_reflection.klass.name)
]
end
end
View
2 activerecord/lib/active_record/associations/has_one_association.rb
@@ -69,7 +69,7 @@ def construct_sql
when @reflection.options[:as]
@finder_sql =
"#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " +
- "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}"
+ "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
else
@finder_sql = "#{@reflection.table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}"
end
View
33 activerecord/lib/active_record/base.rb
@@ -523,12 +523,12 @@ def count_by_sql(sql)
# for looping over a collection where each element require a number of aggregate values. Like the DiscussionBoard
# that needs to list both the number of posts and comments.
def increment_counter(counter_name, id)
- update_all "#{counter_name} = #{counter_name} + 1", "#{primary_key} = #{quote(id)}"
+ update_all "#{counter_name} = #{counter_name} + 1", "#{primary_key} = #{quote_value(id)}"
end
# Works like increment_counter, but decrements instead.
def decrement_counter(counter_name, id)
- update_all "#{counter_name} = #{counter_name} - 1", "#{primary_key} = #{quote(id)}"
+ update_all "#{counter_name} = #{counter_name} - 1", "#{primary_key} = #{quote_value(id)}"
end
@@ -818,10 +818,16 @@ def descends_from_active_record? # :nodoc:
superclass == Base || !columns_hash.include?(inheritance_column)
end
- def quote(value, column = nil) #:nodoc:
+
+ def quote_value(value, column = nil) #:nodoc:
connection.quote(value,column)
end
+ def quote(value, column = nil) #:nodoc:
+ connection.quote(value, column)
+ end
+ deprecate :quote
+
# Used to sanitize objects before they're used in an SELECT SQL-statement. Delegates to <tt>connection.quote</tt>.
def sanitize(object) #:nodoc:
connection.quote(object)
@@ -1010,7 +1016,7 @@ def find_from_ids(ids, options)
def find_one(id, options)
conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions]
- options.update :conditions => "#{table_name}.#{primary_key} = #{quote(id,columns_hash[primary_key])}#{conditions}"
+ options.update :conditions => "#{table_name}.#{primary_key} = #{quote_value(id,columns_hash[primary_key])}#{conditions}"
# Use find_every(options).first since the primary key condition
# already ensures we have a single record. Using find_initial adds
@@ -1024,7 +1030,7 @@ def find_one(id, options)
def find_some(ids, options)
conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions]
- ids_list = ids.map { |id| quote(id,columns_hash[primary_key]) }.join(',')
+ ids_list = ids.map { |id| quote_value(id,columns_hash[primary_key]) }.join(',')
options.update :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}"
result = find_every(options)
@@ -1385,7 +1391,7 @@ def sanitize_sql(condition)
# { :name => "foo'bar", :group_id => 4 } returns "name='foo''bar' and group_id= 4"
def sanitize_sql_hash(hash)
hash.collect { |attrib, value|
- "#{table_name}.#{connection.quote_column_name(attrib)} = #{quote(value)}"
+ "#{table_name}.#{connection.quote_column_name(attrib)} = #{quote_value(value)}"
}.join(" AND ")
end
@@ -1503,7 +1509,7 @@ def id_before_type_cast #:nodoc:
end
def quoted_id #:nodoc:
- quote(id, column_for_attribute(self.class.primary_key))
+ quote_value(id, column_for_attribute(self.class.primary_key))
end
# Sets the primary ID.
@@ -1767,7 +1773,7 @@ def update
connection.update(
"UPDATE #{self.class.table_name} " +
"SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} " +
- "WHERE #{self.class.primary_key} = #{quote(id)}",
+ "WHERE #{self.class.primary_key} = #{quote_value(id)}",
"#{self.class.name} Update"
)
end
@@ -1983,17 +1989,24 @@ def attributes_protected_by_default
def attributes_with_quotes(include_primary_key = true)
attributes.inject({}) do |quoted, (name, value)|
if column = column_for_attribute(name)
- quoted[name] = quote(value, column) unless !include_primary_key && column.primary
+ quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary
end
quoted
end
end
# Quote strings appropriately for SQL statements.
- def quote(value, column = nil)
+ def quote_value(value, column = nil)
self.class.connection.quote(value, column)
end
+ # Deprecated, use quote_value
+ def quote(value, column = nil)
+ self.class.connection.quote(value, column)
+ end
+ deprecate :quote
+
+
# Interpolate custom sql string in instance context.
# Optional record argument is meant for custom insert_sql.
def interpolate_sql(sql, record = nil)
View
4 activerecord/lib/active_record/locking/optimistic.rb
@@ -66,8 +66,8 @@ def update_with_lock #:nodoc:
affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking")
UPDATE #{self.class.table_name}
SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))}
- WHERE #{self.class.primary_key} = #{quote(id)}
- AND #{self.class.quoted_locking_column} = #{quote(previous_value)}
+ WHERE #{self.class.primary_key} = #{quote_value(id)}
+ AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}
end_sql
unless affected_rows == 1

0 comments on commit b445ab9

Please sign in to comment.
Something went wrong with that request. Please try again.