Skip to content
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

MSSQL: Throwing exceptions in the hot path results in slow code #557

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 9 additions & 3 deletions lib/arjdbc/mssql/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ def default_value(value)
def type_cast(value)
return nil if value.nil?
case type
when :integer then value.delete('()').to_i rescue unquote(value).to_i rescue value ? 1 : 0
when :primary_key then value == true || value == false ? value == true ? 1 : 0 : value.to_i
when :integer
case value
when String
unquote value
else
value || 0
end.to_i
when :primary_key then value.respond_to?(:to_i) ? value.to_i : ((value && 1) || 0)
when :decimal then self.class.value_to_decimal(unquote(value))
when :date then self.class.string_to_date(value)
when :datetime then self.class.string_to_time(value)
when :timestamp then self.class.string_to_time(value)
when :time then self.class.string_to_dummy_time(value)
when :boolean then value == true || (value =~ /^t(rue)?$/i) == 0 || unquote(value) == '1'
when :boolean then !!(value ? value =~ /^t(?:rue)?$/i || unquote(value) == '1' : value)
when :binary then unquote value
else value
end
Expand Down