Skip to content

Fix the quoting of further place-holder conditions #1166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,7 @@ def sp_executesql_types_and_parameters(binds)
def sp_executesql_sql_type(attr)
return attr.type.sqlserver_type if attr.respond_to?(:type) && attr.type.respond_to?(:sqlserver_type)

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

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

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

case value = attr.value_for_database
when Type::Binary::Data, ActiveRecord::Type::SQLServer::Data
Expand All @@ -355,6 +351,16 @@ def sp_executesql_sql_param(attr)
end
end

def basic_attribute_type?(type)
type.is_a?(Symbol) ||
type.is_a?(String) ||
type.is_a?(Numeric) ||
type.is_a?(Time) ||
type.is_a?(TrueClass) ||
type.is_a?(FalseClass) ||
type.is_a?(NilClass)
end

def sp_executesql_sql(sql, types, params, name)
if name == "EXPLAIN"
params.each.with_index do |param, index|
Expand Down
Loading