Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
89653eda
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,体验更适合开发者的 AI 搜索 >>
提交
89653eda
编写于
1月 15, 2016
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
`sql_for_insert` returns values for passing to `exec_insert`
上级
b2874aec
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
24 deletion
+16
-24
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
...ecord/connection_adapters/abstract/database_statements.rb
+6
-10
activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
...ord/connection_adapters/postgresql/database_statements.rb
+8
-12
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
...test/cases/adapters/postgresql/postgresql_adapter_test.rb
+2
-2
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
浏览文件 @
89653eda
...
...
@@ -106,7 +106,7 @@ def exec_update(sql, name, binds)
exec_query
(
sql
,
name
,
binds
)
end
#
Returns the last auto-generated ID from the affected table.
#
Executes an INSERT query and returns the new record's ID
#
# +id_value+ will be returned unless the value is nil, in
# which case the database will attempt to calculate the last inserted
...
...
@@ -115,9 +115,12 @@ def exec_update(sql, name, binds)
# If the next id was calculated in advance (as in Oracle), it should be
# passed in as +id_value+.
def
insert
(
arel
,
name
=
nil
,
pk
=
nil
,
id_value
=
nil
,
sequence_name
=
nil
,
binds
=
[])
insert_sql
(
to_sql
(
arel
,
binds
),
name
,
pk
,
id_value
,
sequence_name
,
binds
)
sql
,
binds
,
pk
,
sequence_name
=
sql_for_insert
(
to_sql
(
arel
,
binds
),
pk
,
id_value
,
sequence_name
,
binds
)
value
=
exec_insert
(
sql
,
name
,
binds
,
pk
,
sequence_name
)
id_value
||
last_inserted_id
(
value
)
end
alias
create
insert
alias
insert_sql
insert
# Executes the update statement and returns the number of rows affected.
def
update
(
arel
,
name
=
nil
,
binds
=
[])
...
...
@@ -353,13 +356,6 @@ def join_to_update(update, select, key) # :nodoc:
end
alias
join_to_delete
join_to_update
# Executes an INSERT query and returns the new record's ID
def
insert_sql
(
sql
,
name
=
nil
,
pk
=
nil
,
id_value
=
nil
,
sequence_name
=
nil
,
binds
=
[])
sql
,
binds
=
sql_for_insert
(
sql
,
pk
,
id_value
,
sequence_name
,
binds
)
value
=
exec_insert
(
sql
,
name
,
binds
,
pk
,
sequence_name
)
id_value
||
last_inserted_id
(
value
)
end
protected
# Returns a subquery for the given key using the join information.
...
...
@@ -379,7 +375,7 @@ def select_prepared(sql, name = nil, binds = [])
end
def
sql_for_insert
(
sql
,
pk
,
id_value
,
sequence_name
,
binds
)
[
sql
,
binds
]
[
sql
,
binds
,
pk
,
sequence_name
]
end
def
last_inserted_id
(
result
)
...
...
activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
浏览文件 @
89653eda
...
...
@@ -72,16 +72,6 @@ def select_rows(sql, name = nil, binds = [])
end
end
# Executes an INSERT query and returns the new record's ID
def
insert_sql
(
sql
,
name
=
nil
,
pk
=
nil
,
id_value
=
nil
,
sequence_name
=
nil
,
binds
=
[])
# :nodoc:
unless
pk
# Extract the table from the insert sql. Yuck.
table_ref
=
extract_table_ref_from_insert_sql
(
sql
)
pk
=
primary_key
(
table_ref
)
if
table_ref
end
super
end
# The internal PostgreSQL identifier of the money data type.
MONEY_COLUMN_TYPE_OID
=
790
#:nodoc:
# The internal PostgreSQL identifier of the BYTEA data type.
...
...
@@ -162,12 +152,18 @@ def exec_delete(sql, name = 'SQL', binds = [])
end
alias
:exec_update
:exec_delete
def
sql_for_insert
(
sql
,
pk
,
id_value
,
sequence_name
,
binds
)
def
sql_for_insert
(
sql
,
pk
,
id_value
,
sequence_name
,
binds
)
# :nodoc:
unless
pk
# Extract the table from the insert sql. Yuck.
table_ref
=
extract_table_ref_from_insert_sql
(
sql
)
pk
=
primary_key
(
table_ref
)
if
table_ref
end
if
pk
&&
use_insert_returning?
sql
=
"
#{
sql
}
RETURNING
#{
quote_column_name
(
pk
)
}
"
end
[
sql
,
binds
]
super
end
def
exec_insert
(
sql
,
name
,
binds
,
pk
=
nil
,
sequence_name
=
nil
)
...
...
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
浏览文件 @
89653eda
...
...
@@ -139,8 +139,8 @@ def test_exec_insert_default_values_quoted_schema_with_returning_disabled_and_no
def
test_sql_for_insert_with_returning_disabled
connection
=
connection_without_insert_returning
result
=
connection
.
sql_for_insert
(
'sql'
,
nil
,
nil
,
nil
,
'binds'
)
assert_equal
[
'sql'
,
'binds'
],
result
sql
,
binds
=
connection
.
sql_for_insert
(
'sql'
,
nil
,
nil
,
nil
,
'binds'
)
assert_equal
[
'sql'
,
'binds'
],
[
sql
,
binds
]
end
def
test_serial_sequence
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录