Files

Class/Module Index [+]

Quicksearch

ArJdbc::MSSQL::Column

Attributes

identity[RW]
is_special[RW]

Public Class Methods

string_to_binary(value) click to toggle source

These methods will only allow the adapter to insert binary data with a length of 7K or less because of a SQL Server statement length policy.

# File lib/arjdbc/mssql/adapter.rb, line 197
def self.string_to_binary(value)
  ''
end

Public Instance Methods

cast_to_date(value) click to toggle source
# File lib/arjdbc/mssql/adapter.rb, line 168
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
# File lib/arjdbc/mssql/adapter.rb, line 173
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
# File lib/arjdbc/mssql/adapter.rb, line 163
def cast_to_time(value)
  return value if value.is_a?(Time)
  DateTime.parse(value).to_time rescue nil
end
default_value(value) click to toggle source
# File lib/arjdbc/mssql/adapter.rb, line 125
def default_value(value)
  return $1 if value =~ /^\(N?'(.*)'\)$/
  value
end
extract_limit(sql_type) click to toggle source
# File lib/arjdbc/mssql/adapter.rb, line 146
def extract_limit(sql_type)
  case sql_type
  when /text|ntext|xml|binary|image|varbinary|bit/
    nil
  else
    super
  end
end
is_utf8?() click to toggle source
# File lib/arjdbc/mssql/adapter.rb, line 155
def is_utf8?
  sql_type =~ /nvarchar|ntext|nchar/
end
simplified_type(field_type) click to toggle source
# File lib/arjdbc/mssql/adapter.rb, line 106
def simplified_type(field_type)
  case field_type
  when /int|bigint|smallint|tinyint/           then :integer
  when /numeric/                               then (@scale.nil? || @scale == 0) ? :integer : :decimal
  when /float|double|money|real|smallmoney/    then :decimal
  when /datetime|smalldatetime/                then :datetime
  when /timestamp/                             then :timestamp
  when /time/                                  then :time
  when /date/                                  then :date
  when /text|ntext|xml/                        then :text
  when /binary|image|varbinary/                then :binary
  when /char|nchar|nvarchar|string|varchar/    then (@limit == 1073741823 ? (@limit = nil; :text) : :string)
  when /bit/                                   then :boolean
  when /uniqueidentifier/                      then :string
  else
    super
  end
end
type_cast(value) click to toggle source
# File lib/arjdbc/mssql/adapter.rb, line 130
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 :decimal   then self.class.value_to_decimal(unquote(value))
  when :datetime  then cast_to_datetime(value)
  when :timestamp then cast_to_time(value)
  when :time      then cast_to_time(value)
  when :date      then cast_to_date(value)
  when :boolean   then value == true or (value =~ /^t(rue)?$/) == 0 or unquote(value)=="1"
  when :binary    then unquote value
  else value
  end
end
unquote(value) click to toggle source
# File lib/arjdbc/mssql/adapter.rb, line 159
def unquote(value)
  value.to_s.sub(/\A\([\(\']?/, "").sub(/[\'\)]?\)\Z/, "")
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.