Skip to content

Commit d7d82bf

Browse files
authored
Allow integer place-holder condition to be a query parameter (#1161)
1 parent 8b030ac commit d7d82bf

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,26 @@ def sp_executesql_types_and_parameters(binds)
325325
end
326326

327327
def sp_executesql_sql_type(attr)
328-
return "nvarchar(max)".freeze if attr.is_a?(Symbol) || attr.is_a?(String)
329-
return attr.type.sqlserver_type if attr.type.respond_to?(:sqlserver_type)
328+
return attr.type.sqlserver_type if attr.respond_to?(:type) && attr.type.respond_to?(:sqlserver_type)
330329

331-
case value = attr.value_for_database
332-
when Numeric
330+
value = if attr.is_a?(Symbol) || attr.is_a?(String) || attr.is_a?(Numeric)
331+
attr
332+
else
333+
attr.value_for_database
334+
end
335+
336+
if value.is_a?(Numeric)
333337
value > 2_147_483_647 ? "bigint".freeze : "int".freeze
334338
else
335339
"nvarchar(max)".freeze
336340
end
337341
end
338342

339343
def sp_executesql_sql_param(attr)
340-
return quote(attr) if attr.is_a?(Symbol) || attr.is_a?(String)
344+
return quote(attr) if attr.is_a?(Symbol) || attr.is_a?(String) || attr.is_a?(Numeric)
341345

342346
case value = attr.value_for_database
343-
when Type::Binary::Data,
344-
ActiveRecord::Type::SQLServer::Data
347+
when Type::Binary::Data, ActiveRecord::Type::SQLServer::Data
345348
quote(value)
346349
else
347350
quote(type_cast(value))

0 commit comments

Comments
 (0)