Module: ArJdbc::MSSQL::Column
- Includes:
- LockMethods
- Included in:
- ActiveRecord::ConnectionAdapters::MSSQLColumn
- Defined in:
- lib/arjdbc/mssql/column.rb
Overview
Defined Under Namespace
Modules: Cast
Instance Attribute Summary collapse
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#special ⇒ Object
(also: #is_special)
Returns the value of attribute special.
Instance Method Summary collapse
- #default_value(value) ⇒ Object
- #extract_limit(sql_type) ⇒ Object
- #simplified_type(field_type) ⇒ Object
- #type_cast(value) ⇒ Object
Methods included from LockMethods
Instance Attribute Details
#identity ⇒ Object
Returns the value of attribute identity.
19 20 21 |
# File 'lib/arjdbc/mssql/column.rb', line 19 def identity @identity end |
#special ⇒ Object Also known as: is_special
Returns the value of attribute special.
19 20 21 |
# File 'lib/arjdbc/mssql/column.rb', line 19 def special @special end |
Instance Method Details
#default_value(value) ⇒ Object
44 45 46 47 |
# File 'lib/arjdbc/mssql/column.rb', line 44 def default_value(value) return $1 if value =~ /^\(N?'(.*)'\)$/ value end |
#extract_limit(sql_type) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/arjdbc/mssql/column.rb', line 67 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 |
#simplified_type(field_type) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/arjdbc/mssql/column.rb', line 24 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 |
#type_cast(value) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/arjdbc/mssql/column.rb', line 50 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 :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 |