module ArJdbc::MSSQL::Column::Cast
Constants
- ISO_TIME
Public Instance Methods
binary_to_string(value)
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 189 def binary_to_string(value) if value.respond_to?(:force_encoding) && value.encoding != Encoding::ASCII_8BIT value = value.force_encoding(Encoding::ASCII_8BIT) end value =~ /[^[:xdigit:]]/ ? value : [value].pack('H*') end
string_to_binary(value)
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 183 def string_to_binary(value) # this will only allow the adapter to insert binary data with a length # of 7K or less because of a SQL Server statement length policy ... "0x#{value.unpack("H*")}" # "0x#{value.unpack("H*")[0]}" end
string_to_date(value)
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 154 def string_to_date(value) return value unless value.is_a?(String) return nil if value.empty? date = fast_string_to_date(value) date ? date : Date.parse(value) rescue nil end
string_to_dummy_time(value)
click to toggle source
Calls superclass method
# File lib/arjdbc/mssql/column.rb, line 171 def string_to_dummy_time(value) return value unless value.is_a?(String) return nil if value.empty? if value =~ ISO_TIME # "12:34:56.1234560" microsec = ($4.to_f * 1_000_000).round.to_i new_time 2000, 1, 1, $1.to_i, $2.to_i, $3.to_i, microsec else super(value) end end
string_to_time(value)
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 162 def string_to_time(value) return value unless value.is_a?(String) return nil if value.empty? fast_string_to_time(value) || DateTime.parse(value).to_time rescue nil end