Skip to content

Commit

Permalink
Allow integer place-holder condition to be a query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Apr 20, 2024
1 parent 8b030ac commit 8c5e9b2
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,26 @@ def sp_executesql_types_and_parameters(binds)
end

def sp_executesql_sql_type(attr)
return "nvarchar(max)".freeze if attr.is_a?(Symbol) || attr.is_a?(String)
return attr.type.sqlserver_type if attr.type.respond_to?(:sqlserver_type)
return attr.type.sqlserver_type if attr.respond_to?(:type) && attr.type.respond_to?(:sqlserver_type)

case value = attr.value_for_database
when Numeric
value = if attr.is_a?(Symbol) || attr.is_a?(String) || attr.is_a?(Numeric)
attr
else
attr.value_for_database
end

if value.is_a?(Numeric)
value > 2_147_483_647 ? "bigint".freeze : "int".freeze
else
"nvarchar(max)".freeze
end
end

def sp_executesql_sql_param(attr)
return quote(attr) if attr.is_a?(Symbol) || attr.is_a?(String)
return quote(attr) if attr.is_a?(Symbol) || attr.is_a?(String) || attr.is_a?(Numeric)

case value = attr.value_for_database
when Type::Binary::Data,
ActiveRecord::Type::SQLServer::Data
when Type::Binary::Data, ActiveRecord::Type::SQLServer::Data
quote(value)
else
quote(type_cast(value))
Expand Down

0 comments on commit 8c5e9b2

Please sign in to comment.