Skip to content

Commit

Permalink
Should quote lock_name to pass to get_advisory_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
kamipo committed May 10, 2016
1 parent 164125c commit 5477266
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Expand Up @@ -146,11 +146,11 @@ def supports_advisory_locks?
end

def get_advisory_lock(lock_name, timeout = 0) # :nodoc:
select_value("SELECT GET_LOCK('#{lock_name}', #{timeout});").to_s == '1'
select_value("SELECT GET_LOCK(#{quote(lock_name)}, #{timeout})") == 1
end

def release_advisory_lock(lock_name) # :nodoc:
select_value("SELECT RELEASE_LOCK('#{lock_name}')").to_s == '1'
select_value("SELECT RELEASE_LOCK(#{quote(lock_name)})") == 1
end

def native_database_types
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/adapters/mysql2/connection_test.rb
Expand Up @@ -144,7 +144,7 @@ def test_logs_name_rename_column_sql
end

def test_get_and_release_advisory_lock
lock_name = "test_lock_name"
lock_name = "test lock'n'name"

got_lock = @connection.get_advisory_lock(lock_name)
assert got_lock, "get_advisory_lock should have returned true but it didn't"
Expand All @@ -159,7 +159,7 @@ def test_get_and_release_advisory_lock
end

def test_release_non_existent_advisory_lock
lock_name = "fake_lock_name"
lock_name = "fake lock'n'name"
released_non_existent_lock = @connection.release_advisory_lock(lock_name)
assert_equal released_non_existent_lock, false,
'expected release_advisory_lock to return false when there was no lock to release'
Expand All @@ -168,6 +168,6 @@ def test_release_non_existent_advisory_lock
protected

def test_lock_free(lock_name)
@connection.select_value("SELECT IS_FREE_LOCK('#{lock_name}');") == 1
@connection.select_value("SELECT IS_FREE_LOCK(#{@connection.quote(lock_name)})") == 1
end
end

0 comments on commit 5477266

Please sign in to comment.