Skip to content

Commit

Permalink
Updated #sanitize_sql method signatures to supported passing in a tab…
Browse files Browse the repository at this point in the history
…le_name. This satisfies the change to the ActiveRecord API in Rails commit 489abfd3b23f3c4b3de86aeb3bde3970771c001b on April 20th.
  • Loading branch information
zdennis committed May 13, 2009
1 parent e66b2e7 commit 870bd35
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions ar-extensions/lib/ar-extensions/finders.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'active_record/version'




module ActiveRecord::ConnectionAdapters::Quoting

alias :quote_before_arext :quote
def quote( value, column=nil ) # :nodoc:
if value.is_a?( Regexp )
Expand All @@ -23,26 +19,26 @@ class << self
private

alias :sanitize_sql_orig :sanitize_sql
def sanitize_sql( arg ) # :nodoc:
def sanitize_sql(arg, table_name = quoted_table_name) # :nodoc:
return if arg.blank? # don't process arguments like [], {}, "" or nil
if arg.respond_to?( :to_sql )
arg = sanitize_sql_by_way_of_duck_typing( arg )
elsif arg.is_a?( Hash )
arg = sanitize_sql_from_hash( arg )
arg = sanitize_sql_by_way_of_duck_typing(arg)
elsif arg.is_a?(Hash)
arg = sanitize_sql_from_hash(arg, table_name)
elsif arg.is_a?( Array ) and arg.size == 2 and arg.first.is_a?( String ) and arg.last.is_a?( Hash )
arg = sanitize_sql_from_string_and_hash( arg )
arg = sanitize_sql_from_string_and_hash(arg, table_name)
end
sanitize_sql_orig( arg )
sanitize_sql_orig(arg)
end

def sanitize_sql_by_way_of_duck_typing( arg ) #: nodoc:
def sanitize_sql_by_way_of_duck_typing(arg) #: nodoc:
arg.to_sql( caller )
end

def sanitize_sql_from_string_and_hash( arr ) # :nodoc:
def sanitize_sql_from_string_and_hash(arr, table_name = quoted_table_name) # :nodoc:
return arr if arr.first =~ /\:[\w]+/
return arr if arr.last.empty? # skip empty hash conditions, ie: :conditions => ["", {}]
arr2 = sanitize_sql_from_hash( arr.last )
arr2 = sanitize_sql_from_hash( arr.last, table_name )
if arr2.empty?
conditions = arr.first
else
Expand All @@ -52,7 +48,7 @@ def sanitize_sql_from_string_and_hash( arr ) # :nodoc:
conditions
end

def sanitize_sql_from_hash( hsh ) #:nodoc:
def sanitize_sql_from_hash(hsh, table_name = quoted_table_name) #:nodoc:
conditions, values = [], []
hsh = expand_hash_conditions_for_aggregates(hsh) # introduced in Rails 2.0.2

Expand All @@ -61,7 +57,7 @@ def sanitize_sql_from_hash( hsh ) #:nodoc:
conditions << sanitize_sql_by_way_of_duck_typing( val )
next
elsif val.is_a?(Hash) # don't mess with ActiveRecord hash nested hash functionality
conditions << sanitize_sql_hash_for_conditions(key => val)
conditions << sanitize_sql_hash_for_conditions({key => val}, table_name)
else
sql = nil
result = ActiveRecord::Extensions.process( key, val, self )
Expand All @@ -74,8 +70,6 @@ def sanitize_sql_from_hash( hsh ) #:nodoc:
if attr.include?('.')
table_name, attr = attr.split('.', 2)
table_name = connection.quote_table_name(table_name)
else
table_name = quoted_table_name
end
# ActiveRecord in 2.3.1 changed the method signature for
# the method attribute_condition
Expand Down

0 comments on commit 870bd35

Please sign in to comment.