Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
72fba7db
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
72fba7db
编写于
10月 20, 2015
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21932 from kamipo/add_stored_procedure_test_in_mysql2
Add stored procedure test in mysql2
上级
ee865eb2
d39b6f77
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
70 addition
and
22 deletion
+70
-22
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+4
-4
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
...d/lib/active_record/connection_adapters/mysql2_adapter.rb
+4
-1
activerecord/test/cases/adapters/mysql/connection_test.rb
activerecord/test/cases/adapters/mysql/connection_test.rb
+0
-9
activerecord/test/cases/adapters/mysql/sp_test.rb
activerecord/test/cases/adapters/mysql/sp_test.rb
+19
-5
activerecord/test/cases/adapters/mysql2/sp_test.rb
activerecord/test/cases/adapters/mysql2/sp_test.rb
+29
-0
activerecord/test/cases/helper.rb
activerecord/test/cases/helper.rb
+1
-1
activerecord/test/schema/mysql2_specific_schema.rb
activerecord/test/schema/mysql2_specific_schema.rb
+11
-0
activerecord/test/schema/mysql_specific_schema.rb
activerecord/test/schema/mysql_specific_schema.rb
+2
-2
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
72fba7db
...
...
@@ -168,6 +168,10 @@ def initialize_schema_migrations_table
end
end
def
version
@version
||=
Version
.
new
(
full_version
.
match
(
/^\d+\.\d+\.\d+/
)[
0
])
end
# Returns true, since this connection adapter supports migrations.
def
supports_migrations?
true
...
...
@@ -931,10 +935,6 @@ def subquery_for(key, select)
subselect
.
from
subsubselect
.
distinct
.
as
(
'__active_record_temp'
)
end
def
version
@version
||=
Version
.
new
(
full_version
.
match
(
/^\d+\.\d+\.\d+/
)[
0
])
end
def
mariadb?
full_version
=~
/mariadb/i
end
...
...
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
浏览文件 @
72fba7db
...
...
@@ -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
...
...
activerecord/test/cases/adapters/mysql/connection_test.rb
浏览文件 @
72fba7db
...
...
@@ -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'
)
...
...
activerecord/test/cases/adapters/mysql/sp_test.rb
浏览文件 @
72fba7db
require
"cases/helper"
require
'models/topic'
require
'models/reply'
class
StoredProcedureTest
<
ActiveRecord
::
MysqlTestCase
class
Mysql
StoredProcedureTest
<
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
activerecord/test/cases/adapters/mysql2/sp_test.rb
0 → 100644
浏览文件 @
72fba7db
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
activerecord/test/cases/helper.rb
浏览文件 @
72fba7db
...
...
@@ -47,7 +47,7 @@ def in_memory_db?
end
def
subsecond_precision_supported?
!
current_adapter?
(
:MysqlAdapter
,
:Mysql2Adapter
)
||
ActiveRecord
::
Base
.
connection
.
send
(
:version
)
>=
'5.6.4'
!
current_adapter?
(
:MysqlAdapter
,
:Mysql2Adapter
)
||
ActiveRecord
::
Base
.
connection
.
version
>=
'5.6.4'
end
def
mysql_enforcing_gtid_consistency?
...
...
activerecord/test/schema/mysql2_specific_schema.rb
浏览文件 @
72fba7db
...
...
@@ -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
...
...
activerecord/test/schema/mysql_specific_schema.rb
浏览文件 @
72fba7db
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录