Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c1c886a0
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,发现更多精彩内容 >>
提交
c1c886a0
编写于
7月 08, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2012 from dasch/refactor_postgres_adapter
Refactor PostgreSQLAdapter a bit
上级
4f7ca00b
9991f0f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
18 deletion
+20
-18
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+18
-16
activerecord/test/cases/adapters/postgresql/schema_test.rb
activerecord/test/cases/adapters/postgresql/schema_test.rb
+2
-2
未找到文件。
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
c1c886a0
...
...
@@ -670,7 +670,7 @@ def tables(name = nil)
# If the schema is not specified as part of +name+ then it will only find tables within
# the current schema search path (regardless of permissions to access tables in other schemas)
def
table_exists?
(
name
)
schema
,
table
=
extract_schema_and_table
(
name
.
to_s
)
schema
,
table
=
Utils
.
extract_schema_and_table
(
name
.
to_s
)
return
false
unless
table
binds
=
[[
nil
,
table
]]
...
...
@@ -947,6 +947,23 @@ def distinct(columns, orders) #:nodoc:
"DISTINCT
#{
columns
}
,
#{
order_columns
*
', '
}
"
end
module
Utils
# Returns an array of <tt>[schema_name, table_name]</tt> extracted from +name+.
# +schema_name+ is nil if not specified in +name+.
# +schema_name+ and +table_name+ exclude surrounding quotes (regardless of whether provided in +name+)
# +name+ supports the range of schema/table references understood by PostgreSQL, for example:
#
# * <tt>table_name</tt>
# * <tt>"table.name"</tt>
# * <tt>schema_name.table_name</tt>
# * <tt>schema_name."table.name"</tt>
# * <tt>"schema.name"."table name"</tt>
def
self
.
extract_schema_and_table
(
name
)
table
,
schema
=
name
.
scan
(
/[^".\s]+|"[^"]*"/
)[
0
..
1
].
collect
{
|
m
|
m
.
gsub
(
/(^"|"$)/
,
''
)
}.
reverse
[
schema
,
table
]
end
end
protected
# Returns the version of the connected PostgreSQL server.
def
postgresql_version
...
...
@@ -1085,21 +1102,6 @@ def extract_pg_identifier_from_name(name)
end
end
# Returns an array of <tt>[schema_name, table_name]</tt> extracted from +name+.
# +schema_name+ is nil if not specified in +name+.
# +schema_name+ and +table_name+ exclude surrounding quotes (regardless of whether provided in +name+)
# +name+ supports the range of schema/table references understood by PostgreSQL, for example:
#
# * <tt>table_name</tt>
# * <tt>"table.name"</tt>
# * <tt>schema_name.table_name</tt>
# * <tt>schema_name."table.name"</tt>
# * <tt>"schema.name"."table name"</tt>
def
extract_schema_and_table
(
name
)
table
,
schema
=
name
.
scan
(
/[^".\s]+|"[^"]*"/
)[
0
..
1
].
collect
{
|
m
|
m
.
gsub
(
/(^"|"$)/
,
''
)
}.
reverse
[
schema
,
table
]
end
def
extract_table_ref_from_insert_sql
(
sql
)
sql
[
/into\s+([^\(]*).*values\s*\(/i
]
$1
.
strip
if
$1
...
...
activerecord/test/cases/adapters/postgresql/schema_test.rb
浏览文件 @
c1c886a0
...
...
@@ -229,8 +229,8 @@ def test_extract_schema_and_table
%("schema"."table_name")
=>
%w{schema table_name}
,
%("even spaces".table)
=>
[
'even spaces'
,
'table'
],
%(schema."table.name")
=>
[
'schema'
,
'table.name'
]
}.
each
do
|
given
,
expect
|
assert_equal
expect
,
@connection
.
send
(
:extract_schema_and_table
,
given
)
}.
each
do
|
given
,
expect
|
assert_equal
expect
,
ActiveRecord
::
ConnectionAdapters
::
PostgreSQLAdapter
::
Utils
.
extract_schema_and_table
(
given
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录