Skip to content
This repository
Browse code

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...
commit b445ab986a2c177621a2154b0559be4c700abeeb 1 parent 97487c4
Michael Koziarski NZKoz authored
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *SVN*
2 2
  3 +* Rename AR::Base#quote so people can use that name in their models. #3628 [Koz]
  4 +
3 5 * Add deprecation warning for inferred foreign key. #6029 [Josh Susser]
4 6
5 7 * 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]
10 activerecord/lib/active_record/associations.rb
@@ -1457,7 +1457,7 @@ def association_join
1457 1457 table_alias_for(through_reflection.klass.table_name, aliased_join_table_name),
1458 1458 aliased_join_table_name, polymorphic_foreign_key,
1459 1459 parent.aliased_table_name, parent.primary_key,
1460   - aliased_join_table_name, polymorphic_foreign_type, klass.quote(parent.active_record.base_class.name)] +
  1460 + aliased_join_table_name, polymorphic_foreign_type, klass.quote_value(parent.active_record.base_class.name)] +
1461 1461 " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [table_name_and_alias,
1462 1462 aliased_table_name, primary_key, aliased_join_table_name, options[:foreign_key] || reflection.klass.to_s.classify.foreign_key
1463 1463 ]
@@ -1472,7 +1472,7 @@ def association_join
1472 1472 aliased_table_name, "#{source_reflection.options[:as]}_id",
1473 1473 aliased_join_table_name, options[:foreign_key] || primary_key,
1474 1474 aliased_table_name, "#{source_reflection.options[:as]}_type",
1475   - klass.quote(source_reflection.active_record.base_class.name)
  1475 + klass.quote_value(source_reflection.active_record.base_class.name)
1476 1476 ]
1477 1477 else
1478 1478 case source_reflection.macro
@@ -1501,7 +1501,7 @@ def association_join
1501 1501 aliased_table_name, "#{reflection.options[:as]}_id",
1502 1502 parent.aliased_table_name, parent.primary_key,
1503 1503 aliased_table_name, "#{reflection.options[:as]}_type",
1504   - klass.quote(parent.active_record.base_class.name)
  1504 + klass.quote_value(parent.active_record.base_class.name)
1505 1505 ]
1506 1506 when reflection.macro == :has_one && reflection.options[:as]
1507 1507 " LEFT OUTER JOIN %s ON %s.%s = %s.%s AND %s.%s = %s " % [
@@ -1509,7 +1509,7 @@ def association_join
1509 1509 aliased_table_name, "#{reflection.options[:as]}_id",
1510 1510 parent.aliased_table_name, parent.primary_key,
1511 1511 aliased_table_name, "#{reflection.options[:as]}_type",
1512   - klass.quote(reflection.active_record.base_class.name)
  1512 + klass.quote_value(reflection.active_record.base_class.name)
1513 1513 ]
1514 1514 else
1515 1515 foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key
@@ -1530,7 +1530,7 @@ def association_join
1530 1530 join << %(AND %s.%s = %s ) % [
1531 1531 aliased_table_name,
1532 1532 reflection.active_record.connection.quote_column_name(reflection.active_record.inheritance_column),
1533   - klass.quote(klass.name.demodulize)] unless klass.descends_from_active_record?
  1533 + klass.quote_value(klass.name.demodulize)] unless klass.descends_from_active_record?
1534 1534 join << "AND #{interpolate_sql(sanitize_sql(reflection.options[:conditions]))} " if reflection.options[:conditions]
1535 1535 join
1536 1536 end
2  activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -118,7 +118,7 @@ def insert_record(record)
118 118 attributes[column.name] = record.quoted_id
119 119 else
120 120 if record.attributes.has_key?(column.name)
121   - value = @owner.send(:quote, record[column.name], column)
  121 + value = @owner.send(:quote_value, record[column.name], column)
122 122 attributes[column.name] = value unless value.nil?
123 123 end
124 124 end
2  activerecord/lib/active_record/associations/has_many_association.rb
@@ -184,7 +184,7 @@ def construct_sql
184 184 when @reflection.options[:as]
185 185 @finder_sql =
186 186 "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " +
187   - "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}"
  187 + "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
188 188 @finder_sql << " AND (#{conditions})" if conditions
189 189
190 190 else
4 activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -127,7 +127,7 @@ def construct_join_attributes(associate)
127 127 def construct_quoted_owner_attributes(reflection)
128 128 if as = reflection.options[:as]
129 129 { "#{as}_id" => @owner.quoted_id,
130   - "#{as}_type" => reflection.klass.quote(
  130 + "#{as}_type" => reflection.klass.quote_value(
131 131 @owner.class.base_class.name.to_s,
132 132 reflection.klass.columns_hash["#{as}_type"]) }
133 133 else
@@ -164,7 +164,7 @@ def construct_joins(custom_joins = nil)
164 164 if @reflection.source_reflection.options[:as]
165 165 polymorphic_join = "AND %s.%s = %s" % [
166 166 @reflection.table_name, "#{@reflection.source_reflection.options[:as]}_type",
167   - @owner.class.quote(@reflection.through_reflection.klass.name)
  167 + @owner.class.quote_value(@reflection.through_reflection.klass.name)
168 168 ]
169 169 end
170 170 end
2  activerecord/lib/active_record/associations/has_one_association.rb
@@ -69,7 +69,7 @@ def construct_sql
69 69 when @reflection.options[:as]
70 70 @finder_sql =
71 71 "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " +
72   - "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}"
  72 + "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
73 73 else
74 74 @finder_sql = "#{@reflection.table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}"
75 75 end
33 activerecord/lib/active_record/base.rb
@@ -523,12 +523,12 @@ def count_by_sql(sql)
523 523 # for looping over a collection where each element require a number of aggregate values. Like the DiscussionBoard
524 524 # that needs to list both the number of posts and comments.
525 525 def increment_counter(counter_name, id)
526   - update_all "#{counter_name} = #{counter_name} + 1", "#{primary_key} = #{quote(id)}"
  526 + update_all "#{counter_name} = #{counter_name} + 1", "#{primary_key} = #{quote_value(id)}"
527 527 end
528 528
529 529 # Works like increment_counter, but decrements instead.
530 530 def decrement_counter(counter_name, id)
531   - update_all "#{counter_name} = #{counter_name} - 1", "#{primary_key} = #{quote(id)}"
  531 + update_all "#{counter_name} = #{counter_name} - 1", "#{primary_key} = #{quote_value(id)}"
532 532 end
533 533
534 534
@@ -818,10 +818,16 @@ def descends_from_active_record? # :nodoc:
818 818 superclass == Base || !columns_hash.include?(inheritance_column)
819 819 end
820 820
821   - def quote(value, column = nil) #:nodoc:
  821 +
  822 + def quote_value(value, column = nil) #:nodoc:
822 823 connection.quote(value,column)
823 824 end
824 825
  826 + def quote(value, column = nil) #:nodoc:
  827 + connection.quote(value, column)
  828 + end
  829 + deprecate :quote
  830 +
825 831 # Used to sanitize objects before they're used in an SELECT SQL-statement. Delegates to <tt>connection.quote</tt>.
826 832 def sanitize(object) #:nodoc:
827 833 connection.quote(object)
@@ -1010,7 +1016,7 @@ def find_from_ids(ids, options)
1010 1016
1011 1017 def find_one(id, options)
1012 1018 conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions]
1013   - options.update :conditions => "#{table_name}.#{primary_key} = #{quote(id,columns_hash[primary_key])}#{conditions}"
  1019 + options.update :conditions => "#{table_name}.#{primary_key} = #{quote_value(id,columns_hash[primary_key])}#{conditions}"
1014 1020
1015 1021 # Use find_every(options).first since the primary key condition
1016 1022 # already ensures we have a single record. Using find_initial adds
@@ -1024,7 +1030,7 @@ def find_one(id, options)
1024 1030
1025 1031 def find_some(ids, options)
1026 1032 conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions]
1027   - ids_list = ids.map { |id| quote(id,columns_hash[primary_key]) }.join(',')
  1033 + ids_list = ids.map { |id| quote_value(id,columns_hash[primary_key]) }.join(',')
1028 1034 options.update :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}"
1029 1035
1030 1036 result = find_every(options)
@@ -1385,7 +1391,7 @@ def sanitize_sql(condition)
1385 1391 # { :name => "foo'bar", :group_id => 4 } returns "name='foo''bar' and group_id= 4"
1386 1392 def sanitize_sql_hash(hash)
1387 1393 hash.collect { |attrib, value|
1388   - "#{table_name}.#{connection.quote_column_name(attrib)} = #{quote(value)}"
  1394 + "#{table_name}.#{connection.quote_column_name(attrib)} = #{quote_value(value)}"
1389 1395 }.join(" AND ")
1390 1396 end
1391 1397
@@ -1503,7 +1509,7 @@ def id_before_type_cast #:nodoc:
1503 1509 end
1504 1510
1505 1511 def quoted_id #:nodoc:
1506   - quote(id, column_for_attribute(self.class.primary_key))
  1512 + quote_value(id, column_for_attribute(self.class.primary_key))
1507 1513 end
1508 1514
1509 1515 # Sets the primary ID.
@@ -1767,7 +1773,7 @@ def update
1767 1773 connection.update(
1768 1774 "UPDATE #{self.class.table_name} " +
1769 1775 "SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} " +
1770   - "WHERE #{self.class.primary_key} = #{quote(id)}",
  1776 + "WHERE #{self.class.primary_key} = #{quote_value(id)}",
1771 1777 "#{self.class.name} Update"
1772 1778 )
1773 1779 end
@@ -1983,17 +1989,24 @@ def attributes_protected_by_default
1983 1989 def attributes_with_quotes(include_primary_key = true)
1984 1990 attributes.inject({}) do |quoted, (name, value)|
1985 1991 if column = column_for_attribute(name)
1986   - quoted[name] = quote(value, column) unless !include_primary_key && column.primary
  1992 + quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary
1987 1993 end
1988 1994 quoted
1989 1995 end
1990 1996 end
1991 1997
1992 1998 # Quote strings appropriately for SQL statements.
1993   - def quote(value, column = nil)
  1999 + def quote_value(value, column = nil)
1994 2000 self.class.connection.quote(value, column)
1995 2001 end
1996 2002
  2003 + # Deprecated, use quote_value
  2004 + def quote(value, column = nil)
  2005 + self.class.connection.quote(value, column)
  2006 + end
  2007 + deprecate :quote
  2008 +
  2009 +
1997 2010 # Interpolate custom sql string in instance context.
1998 2011 # Optional record argument is meant for custom insert_sql.
1999 2012 def interpolate_sql(sql, record = nil)
4 activerecord/lib/active_record/locking/optimistic.rb
@@ -66,8 +66,8 @@ def update_with_lock #:nodoc:
66 66 affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking")
67 67 UPDATE #{self.class.table_name}
68 68 SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))}
69   - WHERE #{self.class.primary_key} = #{quote(id)}
70   - AND #{self.class.quoted_locking_column} = #{quote(previous_value)}
  69 + WHERE #{self.class.primary_key} = #{quote_value(id)}
  70 + AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}
71 71 end_sql
72 72
73 73 unless affected_rows == 1

0 comments on commit b445ab9

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