Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
138934fc
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,发现更多精彩内容 >>
提交
138934fc
编写于
6月 29, 2012
作者:
K
kennyj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support collate and ctype on the PostgreSQL.
上级
2596aeba
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
1 deletion
+40
-1
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+20
-1
activerecord/test/cases/adapters/postgresql/active_schema_test.rb
...cord/test/cases/adapters/postgresql/active_schema_test.rb
+4
-0
activerecord/test/cases/adapters/postgresql/connection_test.rb
...erecord/test/cases/adapters/postgresql/connection_test.rb
+8
-0
activerecord/test/cases/tasks/postgresql_rake_test.rb
activerecord/test/cases/tasks/postgresql_rake_test.rb
+8
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
138934fc
...
...
@@ -916,7 +916,8 @@ def recreate_database(name, options = {}) #:nodoc:
end
# Create a new PostgreSQL database. Options include <tt>:owner</tt>, <tt>:template</tt>,
# <tt>:encoding</tt>, <tt>:tablespace</tt>, and <tt>:connection_limit</tt> (note that MySQL uses
# <tt>:encoding</tt>, <tt>:collate</tt>, <tt>:ctype</tt>,
# <tt>:tablespace</tt>, and <tt>:connection_limit</tt> (note that MySQL uses
# <tt>:charset</tt> while PostgreSQL uses <tt>:encoding</tt>).
#
# Example:
...
...
@@ -933,6 +934,10 @@ def create_database(name, options = {})
" TEMPLATE =
\"
#{
value
}
\"
"
when
:encoding
" ENCODING = '
#{
value
}
'"
when
:collate
" LC_COLLATE = '
#{
value
}
'"
when
:ctype
" LC_CTYPE = '
#{
value
}
'"
when
:tablespace
" TABLESPACE =
\"
#{
value
}
\"
"
when
:connection_limit
...
...
@@ -1059,6 +1064,20 @@ def encoding
end_sql
end
# Returns the current database collate.
def
collate
query
(
<<-
end_sql
,
'SCHEMA'
)[
0
][
0
]
SELECT pg_database.datcollate FROM pg_database WHERE pg_database.datname LIKE '
#{
current_database
}
'
end_sql
end
# Returns the current database ctype.
def
ctype
query
(
<<-
end_sql
,
'SCHEMA'
)[
0
][
0
]
SELECT pg_database.datctype FROM pg_database WHERE pg_database.datname LIKE '
#{
current_database
}
'
end_sql
end
# Returns an array of schema names.
def
schema_names
query
(
<<-
SQL
,
'SCHEMA'
).
flatten
...
...
activerecord/test/cases/adapters/postgresql/active_schema_test.rb
浏览文件 @
138934fc
...
...
@@ -21,6 +21,10 @@ def test_create_database_with_encoding
assert_equal
%(CREATE DATABASE "aimonetti" ENCODING = 'latin1')
,
create_database
(
:aimonetti
,
:encoding
=>
:latin1
)
end
def
test_create_database_with_collate_and_ctype
assert_equal
%(CREATE DATABASE "aimonetti" ENCODING = 'UTF8' LC_COLLATE = 'ja_JP.UTF8' LC_CTYPE = 'ja_JP.UTF8')
,
create_database
(
:aimonetti
,
:encoding
=>
:"UTF8"
,
:collate
=>
:"ja_JP.UTF8"
,
:ctype
=>
:"ja_JP.UTF8"
)
end
def
test_add_index
# add_index calls index_name_exists? which can't work since execute is stubbed
ActiveRecord
::
ConnectionAdapters
::
PostgreSQLAdapter
.
send
(
:define_method
,
:index_name_exists?
)
do
|*|
...
...
activerecord/test/cases/adapters/postgresql/connection_test.rb
浏览文件 @
138934fc
...
...
@@ -21,6 +21,14 @@ def test_encoding
assert_not_nil
@connection
.
encoding
end
def
test_collate
assert_not_nil
@connection
.
collate
end
def
test_ctype
assert_not_nil
@connection
.
ctype
end
def
test_default_client_min_messages
assert_equal
"warning"
,
@connection
.
client_min_messages
end
...
...
activerecord/test/cases/tasks/postgresql_rake_test.rb
浏览文件 @
138934fc
...
...
@@ -38,6 +38,14 @@ def test_creates_database_with_given_encoding
merge
(
'encoding'
=>
'latin'
)
end
def
test_creates_database_with_given_collate_and_ctype
@connection
.
expects
(
:create_database
).
with
(
'my-app-db'
,
@configuration
.
merge
(
'encoding'
=>
'utf8'
,
'collate'
=>
'ja_JP.UTF8'
,
'ctype'
=>
'ja_JP.UTF8'
))
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
.
merge
(
'collate'
=>
'ja_JP.UTF8'
,
'ctype'
=>
'ja_JP.UTF8'
)
end
def
test_establishes_connection_to_new_database
ActiveRecord
::
Base
.
expects
(
:establish_connection
).
with
(
@configuration
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录