Skip to content

Commit e7c4f6d

Browse files
authored
Allow basic attribute types to be query parameters (#1166)
1 parent b6f48af commit e7c4f6d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: lib/active_record/connection_adapters/sqlserver/database_statements.rb

+12-6
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,7 @@ def sp_executesql_types_and_parameters(binds)
331331
def sp_executesql_sql_type(attr)
332332
return attr.type.sqlserver_type if attr.respond_to?(:type) && attr.type.respond_to?(:sqlserver_type)
333333

334-
value = if attr.is_a?(Symbol) || attr.is_a?(String) || attr.is_a?(Numeric)
335-
attr
336-
else
337-
attr.value_for_database
338-
end
334+
value = basic_attribute_type?(attr) ? attr : attr.value_for_database
339335

340336
if value.is_a?(Numeric)
341337
value > 2_147_483_647 ? "bigint".freeze : "int".freeze
@@ -345,7 +341,7 @@ def sp_executesql_sql_type(attr)
345341
end
346342

347343
def sp_executesql_sql_param(attr)
348-
return quote(attr) if attr.is_a?(Symbol) || attr.is_a?(String) || attr.is_a?(Numeric)
344+
return quote(attr) if basic_attribute_type?(attr)
349345

350346
case value = attr.value_for_database
351347
when Type::Binary::Data, ActiveRecord::Type::SQLServer::Data
@@ -355,6 +351,16 @@ def sp_executesql_sql_param(attr)
355351
end
356352
end
357353

354+
def basic_attribute_type?(type)
355+
type.is_a?(Symbol) ||
356+
type.is_a?(String) ||
357+
type.is_a?(Numeric) ||
358+
type.is_a?(Time) ||
359+
type.is_a?(TrueClass) ||
360+
type.is_a?(FalseClass) ||
361+
type.is_a?(NilClass)
362+
end
363+
358364
def sp_executesql_sql(sql, types, params, name)
359365
if name == "EXPLAIN"
360366
params.each.with_index do |param, index|

0 commit comments

Comments
 (0)