Module: ArJdbc::MsSQL::Column
- Defined in:
- lib/arjdbc/mssql/adapter.rb
Instance Attribute Summary collapse
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#is_special ⇒ Object
Returns the value of attribute is_special.
Class Method Summary collapse
-
.string_to_binary(value) ⇒ Object
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.
Instance Method Summary collapse
- #cast_to_date(value) ⇒ Object
- #cast_to_datetime(value) ⇒ Object
- #cast_to_time(value) ⇒ Object
- #default_value(value) ⇒ Object
- #extract_limit(sql_type) ⇒ Object
- #is_utf8? ⇒ Boolean
- #simplified_type(field_type) ⇒ Object
- #type_cast(value) ⇒ Object
- #unquote(value) ⇒ Object
Instance Attribute Details
#identity ⇒ Object
Returns the value of attribute identity.
78 79 80 |
# File 'lib/arjdbc/mssql/adapter.rb', line 78 def identity @identity end |
#is_special ⇒ Object
Returns the value of attribute is_special.
78 79 80 |
# File 'lib/arjdbc/mssql/adapter.rb', line 78 def is_special @is_special end |
Class Method Details
.string_to_binary(value) ⇒ Object
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.
177 178 179 |
# File 'lib/arjdbc/mssql/adapter.rb', line 177 def self.string_to_binary(value) '' end |
Instance Method Details
#cast_to_date(value) ⇒ Object
148 149 150 151 |
# File 'lib/arjdbc/mssql/adapter.rb', line 148 def cast_to_date(value) return value if value.is_a?(Date) return Date.parse(value) rescue nil end |
#cast_to_datetime(value) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/arjdbc/mssql/adapter.rb', line 153 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) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/arjdbc/mssql/adapter.rb', line 135 def cast_to_time(value) return value if value.is_a?(Time) time_array = ParseDate.parsedate(value) return nil if !time_array.any? time_array[0] ||= 2000 time_array[1] ||= 1 time_array[2] ||= 1 return Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil # Try DateTime instead - the date may be outside the time period support by Time. DateTime.new(*time_array[0..5]) rescue nil end |
#default_value(value) ⇒ Object
97 98 99 100 |
# File 'lib/arjdbc/mssql/adapter.rb', line 97 def default_value(value) return $1 if value =~ /^\(N?'(.*)'\)$/ value end |
#extract_limit(sql_type) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/arjdbc/mssql/adapter.rb', line 118 def extract_limit(sql_type) case sql_type when /text|ntext|xml|binary|image|varbinary|bit/ nil else super end end |
#is_utf8? ⇒ Boolean
127 128 129 |
# File 'lib/arjdbc/mssql/adapter.rb', line 127 def is_utf8? sql_type =~ /nvarchar|ntext|nchar/i end |
#simplified_type(field_type) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/arjdbc/mssql/adapter.rb', line 80 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|decimal|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 end end |
#type_cast(value) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/arjdbc/mssql/adapter.rb', line 102 def type_cast(value) return nil if value.nil? || value == "(null)" || value == "(NULL)" case type when :integer then value.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)?$/i) == 0 or unquote(value)=="1" when :binary then unquote value else value end end |
#unquote(value) ⇒ Object
131 132 133 |
# File 'lib/arjdbc/mssql/adapter.rb', line 131 def unquote(value) value.to_s.sub(/\A\([\(\']?/, "").sub(/[\'\)]?\)\Z/, "") end |