提交 d39b6f77 编写于 作者: R Ryuta Kamizono

Add stored procedure test in mysql2

上级 d9e74ace
......@@ -126,7 +126,9 @@ def disconnect!
# Returns an array of arrays containing the field values.
# Order is the same as that returned by +columns+.
def select_rows(sql, name = nil, binds = [])
execute(sql, name).to_a
result = execute(sql, name)
@connection.next_result while @connection.more_results?
result.to_a
end
# Executes the SQL statement in the context of this connection.
......@@ -142,6 +144,7 @@ def execute(sql, name = nil)
def exec_query(sql, name = 'SQL', binds = [])
result = execute(sql, name)
@connection.next_result while @connection.more_results?
ActiveRecord::Result.new(result.fields, result.to_a)
end
......
......@@ -118,15 +118,6 @@ def test_exec_typecasts_bind_vals
end
end
# Test that MySQL allows multiple results for stored procedures
if defined?(Mysql) && Mysql.const_defined?(:CLIENT_MULTI_RESULTS)
def test_multi_results
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 @connection.active?, "Bad connection use by 'MysqlAdapter.select_rows'"
end
end
def test_mysql_connection_collation_is_configured
assert_equal 'utf8_unicode_ci', @connection.show_variable('collation_connection')
assert_equal 'utf8_general_ci', ARUnit2Model.connection.show_variable('collation_connection')
......
require "cases/helper"
require 'models/topic'
require 'models/reply'
class StoredProcedureTest < ActiveRecord::MysqlTestCase
class MysqlStoredProcedureTest < ActiveRecord::MysqlTestCase
fixtures :topics
def setup
@connection = ActiveRecord::Base.connection
end
# Test that MySQL allows multiple results for stored procedures
if defined?(Mysql) && Mysql.const_defined?(:CLIENT_MULTI_RESULTS)
#
# In MySQL 5.6, CLIENT_MULTI_RESULTS is enabled by default.
# http://dev.mysql.com/doc/refman/5.6/en/call.html
if ActiveRecord::Base.connection.version >= '5.6.0' || Mysql.const_defined?(:CLIENT_MULTI_RESULTS)
def test_multi_results
rows = @connection.select_rows('CALL ten();')
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
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'"
topics = Topic.find_by_sql 'CALL topics(3);'
assert_equal 3, topics.size
assert @connection.active?, "Bad connection use by 'MysqlAdapter.select'"
end
end
end
require "cases/helper"
require 'models/topic'
require 'models/reply'
class Mysql2StoredProcedureTest < ActiveRecord::Mysql2TestCase
fixtures :topics
def setup
@connection = ActiveRecord::Base.connection
end
# Test that MySQL allows multiple results for stored procedures
#
# In MySQL 5.6, CLIENT_MULTI_RESULTS is enabled by default.
# http://dev.mysql.com/doc/refman/5.6/en/call.html
if ActiveRecord::Base.connection.version >= '5.6.0'
def test_multi_results
rows = @connection.select_rows('CALL ten();')
assert_equal 10, rows[0][0].to_i, "ten() did not return 10 as expected: #{rows.inspect}"
assert @connection.active?, "Bad connection use by 'Mysql2Adapter.select_rows'"
end
def test_multi_results_from_find_by_sql
topics = Topic.find_by_sql 'CALL topics(3);'
assert_equal 3, topics.size
assert @connection.active?, "Bad connection use by 'Mysql2Adapter.select'"
end
end
end
......@@ -38,6 +38,17 @@
BEGIN
select 10;
END
SQL
ActiveRecord::Base.connection.execute <<-SQL
DROP PROCEDURE IF EXISTS topics;
SQL
ActiveRecord::Base.connection.execute <<-SQL
CREATE PROCEDURE topics(IN num INT) SQL SECURITY INVOKER
BEGIN
select * from topics limit num;
END
SQL
ActiveRecord::Base.connection.drop_table "enum_tests", if_exists: true
......
......@@ -45,9 +45,9 @@
SQL
ActiveRecord::Base.connection.execute <<-SQL
CREATE PROCEDURE topics() SQL SECURITY INVOKER
CREATE PROCEDURE topics(IN num INT) SQL SECURITY INVOKER
BEGIN
select * from topics limit 1;
select * from topics limit num;
END
SQL
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册