From 98165fd31e7be605ef37e096e8423ce8953ef4ed Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 9 Mar 2007 03:23:37 +0000 Subject: Consistently quote primary key column names. Closes #7763. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6364 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3a9783bac5..f3d4cf856a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -482,7 +482,7 @@ module ActiveRecord #:nodoc: # Deletes the record with the given +id+ without instantiating an object first. If an array of ids is provided, all of them # are deleted. def delete(id) - delete_all([ "#{primary_key} IN (?)", id ]) + delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ]) end # Destroys the record with the given +id+ by instantiating the object and calling #destroy (all the callbacks are the triggered). @@ -537,9 +537,9 @@ module ActiveRecord #:nodoc: def update_counters(id, counters) updates = counters.inject([]) { |list, (counter_name, increment)| sign = increment < 0 ? "-" : "+" - list << "#{counter_name} = #{counter_name} #{sign} #{increment.abs}" + list << "#{connection.quote_column_name(counter_name)} = #{connection.quote_column_name(counter_name)} #{sign} #{increment.abs}" }.join(", ") - update_all(updates, "#{primary_key} = #{quote_value(id)}") + update_all(updates, "#{connection.quote_column_name(primary_key)} = #{quote_value(id)}") end # Increments the specified counter by one. So DiscussionBoard.increment_counter("post_count", @@ -1047,7 +1047,7 @@ module ActiveRecord #:nodoc: def find_one(id, options) conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions] - options.update :conditions => "#{table_name}.#{primary_key} = #{quote_value(id,columns_hash[primary_key])}#{conditions}" + options.update :conditions => "#{table_name}.#{connection.quote_column_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 @@ -1062,7 +1062,7 @@ module ActiveRecord #:nodoc: def find_some(ids, options) conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions] ids_list = ids.map { |id| quote_value(id,columns_hash[primary_key]) }.join(',') - options.update :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}" + options.update :conditions => "#{table_name}.#{connection.quote_column_name(primary_key)} IN (#{ids_list})#{conditions}" result = find_every(options) @@ -1608,7 +1608,7 @@ module ActiveRecord #:nodoc: unless new_record? connection.delete <<-end_sql, "#{self.class.name} Destroy" DELETE FROM #{self.class.table_name} - WHERE #{self.class.primary_key} = #{quoted_id} + WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id} end_sql end @@ -1847,7 +1847,7 @@ module ActiveRecord #:nodoc: connection.update( "UPDATE #{self.class.table_name} " + "SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} " + - "WHERE #{self.class.primary_key} = #{quote_value(id)}", + "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}", "#{self.class.name} Update" ) end -- cgit v1.2.3