# File lib/arjdbc/mssql/column.rb, line 82 def primary?; @primary end
module ArJdbc::MSSQL::Column
Public Class Methods
included(base)
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 12 def self.included(base) # NOTE: assumes a standalone MSSQLColumn class class << base; include Cast; end end
Public Instance Methods
default_value(value)
click to toggle source
@override
# File lib/arjdbc/mssql/column.rb, line 40 def default_value(value) return $1 if value =~ /^\(N?'(.*)'\)$/ || value =~ /^\(\(?(.*?)\)?\)$/ value end
extract_limit(sql_type)
click to toggle source
@override
Calls superclass method
# File lib/arjdbc/mssql/column.rb, line 63 def extract_limit(sql_type) case sql_type when /^smallint/i 2 when /^int/i 4 when /^bigint/i 8 when /\(max\)/, /decimal/, /numeric/ nil when /text|ntext|xml|binary|image|varbinary|bit/ nil else super end end
identity?()
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 85 def identity? !! sql_type.downcase.index('identity') end
Also aliased as: identity, is_identity
is_utf8?()
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 107 def is_utf8? !!( sql_type =~ /nvarchar|ntext|nchar/i ) end
primary?()
click to toggle source
primary replacement that works on 4.2 as well columns will set @primary even when on AR 4.2
Also aliased as: is_primary
simplified_type(field_type)
click to toggle source
@override
Calls superclass method
# File lib/arjdbc/mssql/column.rb, line 20 def simplified_type(field_type) case field_type when /int|bigint|smallint|tinyint/i then :integer when /numeric/i then (@scale.nil? || @scale == 0) ? :integer : :decimal when /float|double|money|real|smallmoney/i then :decimal when /datetime|smalldatetime/i then :datetime when /timestamp/i then :timestamp when /time/i then :time when /date/i then :date when /text|ntext|xml/i then :text when /binary|image|varbinary/i then :binary when /char|nchar|nvarchar|string|varchar/i then (@limit == 1073741823 ? (@limit = nil; :text) : :string) when /bit/i then :boolean when /uniqueidentifier/i then :string else super end end
special?()
click to toggle source
NOTE: these do not handle = equality as expected see {#repair_special_columns} (TEXT, NTEXT, and IMAGE data types are deprecated) @private
# File lib/arjdbc/mssql/column.rb, line 96 def special? unless defined? @special # /text|ntext|image|xml/i sql_type = @sql_type.downcase @special = !! ( sql_type.index('text') || sql_type.index('image') || sql_type.index('xml') ) end @special end
Also aliased as: special, is_special
type_cast(value)
click to toggle source
@override
# File lib/arjdbc/mssql/column.rb, line 46 def type_cast(value) return nil if value.nil? case type when :integer then ( value.is_a?(String) ? unquote(value) : (value || 0) ).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 :binary then unquote(value) else value end end
Private Instance Methods
cast_to_date(value)
click to toggle source
@deprecated no longer used
# File lib/arjdbc/mssql/column.rb, line 124 def cast_to_date(value) return value if value.is_a?(Date) return Date.parse(value) rescue nil end
cast_to_datetime(value)
click to toggle source
@deprecated no longer used
# File lib/arjdbc/mssql/column.rb, line 130 def cast_to_datetime(value) if value.is_a?(Time) if value.year != 0 and value.month != 0 and value.day != 0 return value else return Time.mktime(2000, 1, 1, value.hour, value.min, value.sec) rescue nil end end if value.is_a?(DateTime) begin # Attempt to convert back to a Time, but it could fail for dates significantly in the past/future. return Time.mktime(value.year, value.mon, value.day, value.hour, value.min, value.sec) rescue ArgumentError return value end end return cast_to_time(value) if value.is_a?(Date) or value.is_a?(String) rescue nil return value.is_a?(Date) ? value : nil end
cast_to_time(value)
click to toggle source
@deprecated no longer used
# File lib/arjdbc/mssql/column.rb, line 118 def cast_to_time(value) return value if value.is_a?(Time) DateTime.parse(value).to_time rescue nil end
unquote(value)
click to toggle source
# File lib/arjdbc/mssql/column.rb, line 113 def unquote(value) value.to_s.sub(/\A\([\(\]?/, "").sub(/[\\)]?\)\Z/, "") end