Class: ActiveRecord::ConnectionAdapters::SQLServerColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sqlserver_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type = nil, null = true, sqlserver_options = {}) ⇒ SQLServerColumn

Returns a new instance of SQLServerColumn.



59
60
61
62
63
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 59

def initialize(name, default, sql_type = nil, null = true, sqlserver_options = {})
  @sqlserver_options = sqlserver_options.symbolize_keys
  super(name, default, sql_type, null)
  @primary = @sqlserver_options[:is_identity] || @sqlserver_options[:is_primary]
end

Class Method Details

.binary_to_string(value) ⇒ Object



71
72
73
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 71

def binary_to_string(value)
  value =~ /[^[:xdigit:]]/ ? value : [value].pack('H*')
end

.string_to_binary(value) ⇒ Object



67
68
69
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 67

def string_to_binary(value)
 "0x#{value.unpack("H*")[0]}"
end

Instance Method Details

#database_yearObject



122
123
124
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 122

def database_year
  @sqlserver_options[:database_year]
end

#default_functionObject



105
106
107
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 105

def default_function
  @sqlserver_options[:default_function]
end

#is_identity?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 77

def is_identity?
  @sqlserver_options[:is_identity]
end

#is_integer?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 89

def is_integer?
  !!(@sql_type =~ /int/i)
end

#is_primary?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 81

def is_primary?
  @sqlserver_options[:is_primary]
end

#is_real?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 93

def is_real?
  !!(@sql_type =~ /real/i)
end

#is_utf8?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 85

def is_utf8?
  !!(@sql_type =~ /nvarchar|ntext|nchar/i)
end

#sql_type_for_statementObject



97
98
99
100
101
102
103
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 97

def sql_type_for_statement
  if is_integer? || is_real?
    sql_type.sub(/\((\d+)?\)/,'')
  else
    sql_type
  end
end

#table_klassObject



113
114
115
116
117
118
119
120
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 113

def table_klass
  @table_klass ||= begin
    table_name.classify.constantize
  rescue StandardError, NameError, LoadError
    nil
  end
  (@table_klass && @table_klass < ActiveRecord::Base) ? @table_klass : nil
end

#table_nameObject



109
110
111
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 109

def table_name
  @sqlserver_options[:table_name]
end