Skip to content

Commit d2a3b4f

Browse files
committed
Use quoted PK in sql_for_insert with OUTPUT INSERTED.
1 parent 1e1c0a8 commit d2a3b4f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ def select(sql, name = nil, binds = [])
258258
end
259259

260260
def sql_for_insert(sql, pk, id_value, sequence_name, binds)
261-
sql =
262-
if pk
263-
sql.insert(sql.index(/ (DEFAULT )?VALUES/), " OUTPUT inserted.#{pk}")
264-
else
265-
"#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
266-
end
261+
sql = if pk
262+
quoted_pk = SQLServer::Utils.extract_identifiers(pk).quoted
263+
sql.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk}"
264+
else
265+
"#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
266+
end
267267
super
268268
end
269269

0 commit comments

Comments
 (0)