Class: ActiveRecord::ConnectionAdapters::SQLServerColumn
- Inherits:
-
Column
- Object
- Column
- ActiveRecord::ConnectionAdapters::SQLServerColumn
- Defined in:
- lib/active_record/connection_adapters/sqlserver_adapter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #database_year ⇒ Object
- #default_function ⇒ Object
-
#initialize(name, default, sql_type = nil, null = true, sqlserver_options = {}) ⇒ SQLServerColumn
constructor
A new instance of SQLServerColumn.
- #is_identity? ⇒ Boolean
- #is_integer? ⇒ Boolean
- #is_primary? ⇒ Boolean
- #is_real? ⇒ Boolean
- #is_utf8? ⇒ Boolean
- #sql_type_for_statement ⇒ Object
- #table_klass ⇒ Object
- #table_name ⇒ Object
Constructor Details
#initialize(name, default, sql_type = nil, null = true, sqlserver_options = {}) ⇒ SQLServerColumn
Returns a new instance of SQLServerColumn.
55 56 57 58 59 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 55 def initialize(name, default, sql_type = nil, null = true, = {}) @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
67 68 69 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 67 def binary_to_string(value) value =~ /[^[:xdigit:]]/ ? value : [value].pack('H*') end |
.string_to_binary(value) ⇒ Object
63 64 65 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 63 def string_to_binary(value) "0x#{value.unpack("H*")[0]}" end |
Instance Method Details
#database_year ⇒ Object
118 119 120 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 118 def database_year @sqlserver_options[:database_year] end |
#default_function ⇒ Object
101 102 103 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 101 def default_function @sqlserver_options[:default_function] end |
#is_identity? ⇒ Boolean
73 74 75 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 73 def is_identity? @sqlserver_options[:is_identity] end |
#is_integer? ⇒ Boolean
85 86 87 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 85 def is_integer? !!(@sql_type =~ /int/i) end |
#is_primary? ⇒ Boolean
77 78 79 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 77 def is_primary? @sqlserver_options[:is_primary] end |
#is_real? ⇒ Boolean
89 90 91 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 89 def is_real? !!(@sql_type =~ /real/i) end |
#is_utf8? ⇒ Boolean
81 82 83 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 81 def is_utf8? !!(@sql_type =~ /nvarchar|ntext|nchar/i) end |
#sql_type_for_statement ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 93 def sql_type_for_statement if is_integer? || is_real? sql_type.sub(/\(\d+\)/,'') else sql_type end end |
#table_klass ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 109 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_name ⇒ Object
105 106 107 |
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 105 def table_name @sqlserver_options[:table_name] end |