mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Bug Fix -- clean up connection after stored procedure [#3151 state:resolved]
This commit is contained in:
parent
137e4e759a
commit
7ce1539934
4 changed files with 29 additions and 0 deletions
|
@ -275,6 +275,7 @@ module ActiveRecord
|
||||||
rows = []
|
rows = []
|
||||||
result.each { |row| rows << row }
|
result.each { |row| rows << row }
|
||||||
result.free
|
result.free
|
||||||
|
@connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
|
||||||
rows
|
rows
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -617,6 +618,7 @@ module ActiveRecord
|
||||||
result = execute(sql, name)
|
result = execute(sql, name)
|
||||||
rows = []
|
rows = []
|
||||||
result.each_hash { |row| rows << row }
|
result.each_hash { |row| rows << row }
|
||||||
|
@connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
|
||||||
result.free
|
result.free
|
||||||
rows
|
rows
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,6 +48,7 @@ class MysqlConnectionTest < ActiveRecord::TestCase
|
||||||
def test_multi_results
|
def test_multi_results
|
||||||
rows = ActiveRecord::Base.connection.select_rows('CALL ten();')
|
rows = ActiveRecord::Base.connection.select_rows('CALL ten();')
|
||||||
assert_equal 10, rows[0][0].to_i, "ten() did not return 10 as expected: #{rows.inspect}"
|
assert_equal 10, rows[0][0].to_i, "ten() did not return 10 as expected: #{rows.inspect}"
|
||||||
|
assert @connection.active?, "Bad connection use by 'MysqlAdapter.select_rows'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
15
activerecord/test/cases/adapters/mysql/sp_test.rb
Normal file
15
activerecord/test/cases/adapters/mysql/sp_test.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
require "cases/helper"
|
||||||
|
require 'models/topic'
|
||||||
|
|
||||||
|
class StoredProcedureTest < ActiveRecord::TestCase
|
||||||
|
fixtures :topics
|
||||||
|
|
||||||
|
# Test that MySQL allows multiple results for stored procedures
|
||||||
|
if Mysql.const_defined?(:CLIENT_MULTI_RESULTS)
|
||||||
|
def test_multi_results_from_find_by_sql
|
||||||
|
topics = Topic.find_by_sql 'CALL topics();'
|
||||||
|
assert_equal 1, topics.size
|
||||||
|
assert ActiveRecord::Base.connection.active?, "Bad connection use by 'MysqlAdapter.select'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -19,6 +19,17 @@ CREATE PROCEDURE ten() SQL SECURITY INVOKER
|
||||||
BEGIN
|
BEGIN
|
||||||
select 10;
|
select 10;
|
||||||
END
|
END
|
||||||
|
SQL
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.execute <<-SQL
|
||||||
|
DROP PROCEDURE IF EXISTS topics;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.execute <<-SQL
|
||||||
|
CREATE PROCEDURE topics() SQL SECURITY INVOKER
|
||||||
|
BEGIN
|
||||||
|
select * from topics limit 1;
|
||||||
|
END
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue