]> source.dussan.org Git - sonarqube.git/blob
b91185eab29c13c26e4e1bd6827fa3445d1f611d
[sonarqube.git] /
1 module ArJdbc
2   module QuotedPrimaryKeyExtension
3     def self.extended(base)
4       #       Rails 3 method           Rails 2 method
5       meth = [:arel_attributes_values, :attributes_with_quotes].detect do |m|
6         base.private_instance_methods.include?(m.to_s)
7       end
8       pk_hash_key = "self.class.primary_key"
9       pk_hash_value = '"?"'
10       if meth == :arel_attributes_values
11         pk_hash_key = "self.class.arel_table[#{pk_hash_key}]"
12         pk_hash_value = "Arel::SqlLiteral.new(#{pk_hash_value})"
13       end
14       if meth
15         base.module_eval <<-PK, __FILE__, __LINE__
16           alias :#{meth}_pre_pk :#{meth}
17           def #{meth}(include_primary_key = true, *args) #:nodoc:
18             aq = #{meth}_pre_pk(include_primary_key, *args)
19             if connection.is_a?(ArJdbc::Oracle) || connection.is_a?(ArJdbc::Mimer)
20               aq[#{pk_hash_key}] = #{pk_hash_value} if include_primary_key && aq[#{pk_hash_key}].nil?
21             end
22             aq
23           end
24         PK
25       end
26     end
27   end
28 end