mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #11528 from Empact/optimistic_lock_improvement
Rebase and make fixes to #6763 "Specified column type for quote_value"
This commit is contained in:
commit
ecd70039ba
5 changed files with 33 additions and 4 deletions
|
@ -1,3 +1,20 @@
|
|||
* Don't allow `quote_value` to be called without a column.
|
||||
|
||||
Some adapters require column information to do their job properly.
|
||||
By enforcing the provision of the column for this internal method
|
||||
we ensure that those using adapters that require column information
|
||||
will always get the proper behavior.
|
||||
|
||||
*Ben Woosley*
|
||||
|
||||
* When using optimistic locking, `update` was not passing the column to `quote_value`
|
||||
to allow the connection adapter to properly determine how to quote the value. This was
|
||||
affecting certain databases that use specific colmn types.
|
||||
|
||||
Fixes: #6763
|
||||
|
||||
*Alfred Wong*
|
||||
|
||||
* rescue from all exceptions in `ConnectionManagement#call`
|
||||
|
||||
Fixes #11497
|
||||
|
|
|
@ -82,7 +82,7 @@ module ActiveRecord
|
|||
|
||||
stmt = relation.where(
|
||||
relation.table[self.class.primary_key].eq(id).and(
|
||||
relation.table[lock_col].eq(self.class.quote_value(previous_lock_value))
|
||||
relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col)))
|
||||
)
|
||||
).arel.compile_update(arel_attributes_with_values_for_update(attribute_names))
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ module ActiveRecord
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def quote_value(value, column = nil) #:nodoc:
|
||||
connection.quote(value,column)
|
||||
def quote_value(value, column) #:nodoc:
|
||||
connection.quote(value, column)
|
||||
end
|
||||
|
||||
# Used to sanitize objects before they're used in an SQL SELECT statement. Delegates to <tt>connection.quote</tt>.
|
||||
|
|
|
@ -613,7 +613,7 @@ class FinderTest < ActiveRecord::TestCase
|
|||
def test_named_bind_with_postgresql_type_casts
|
||||
l = Proc.new { bind(":a::integer '2009-01-01'::date", :a => '10') }
|
||||
assert_nothing_raised(&l)
|
||||
assert_equal "#{ActiveRecord::Base.quote_value('10')}::integer '2009-01-01'::date", l.call
|
||||
assert_equal "#{ActiveRecord::Base.connection.quote('10')}::integer '2009-01-01'::date", l.call
|
||||
end
|
||||
|
||||
def test_string_sanitation
|
||||
|
|
|
@ -28,6 +28,18 @@ end
|
|||
class OptimisticLockingTest < ActiveRecord::TestCase
|
||||
fixtures :people, :legacy_things, :references, :string_key_objects, :peoples_treasures
|
||||
|
||||
def test_quote_value_passed_lock_col
|
||||
p1 = Person.find(1)
|
||||
assert_equal 0, p1.lock_version
|
||||
|
||||
Person.expects(:quote_value).with(0, Person.columns_hash[Person.locking_column]).returns('0').once
|
||||
|
||||
p1.first_name = 'anika2'
|
||||
p1.save!
|
||||
|
||||
assert_equal 1, p1.lock_version
|
||||
end
|
||||
|
||||
def test_non_integer_lock_existing
|
||||
s1 = StringKeyObject.find("record1")
|
||||
s2 = StringKeyObject.find("record1")
|
||||
|
|
Loading…
Reference in a new issue