Module: JdbcSpec::MsSQL::Column
- Defined in:
- lib/jdbc_adapter/jdbc_mssql.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_datetime(value) ⇒ Object
- #cast_to_time(value) ⇒ Object
- #is_utf8? ⇒ Boolean
- #simplified_type(field_type) ⇒ Object
- #type_cast(value) ⇒ Object
- #unquote(value) ⇒ Object
-
#unquote_string(value) ⇒ Object
JRUBY-2011: Match balanced quotes and parenthesis - ‘text’,(‘text’) or (text).
Instance Attribute Details
#identity ⇒ Object
Returns the value of attribute identity.
39 40 41 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 39 def identity @identity end |
#is_special ⇒ Object
Returns the value of attribute is_special.
39 40 41 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 39 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.
110 111 112 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 110 def self.string_to_binary(value) '' end |
Instance Method Details
#cast_to_datetime(value) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 96 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 return cast_to_time(value) if value.is_a?(Date) or value.is_a?(String) rescue nil value end |
#cast_to_time(value) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 87 def cast_to_time(value) return value if value.is_a?(Time) time_array = ParseDate.parsedate(value) time_array[0] ||= 2000 time_array[1] ||= 1 time_array[2] ||= 1 Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil end |
#is_utf8? ⇒ Boolean
74 75 76 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 74 def is_utf8? sql_type =~ /nvarchar|ntext|nchar/i end |
#simplified_type(field_type) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 41 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 /text|ntext/i then :text when /binary|image|varbinary/i then :binary when /char|nchar|nvarchar|string|varchar/i then :string when /bit/i then :boolean when /uniqueidentifier/i then :string end end |
#type_cast(value) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 57 def type_cast(value) return nil if value.nil? || value == "(null)" || value == "(NULL)" case type when :string then unquote_string value when :integer then 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_datetime(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
83 84 85 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 83 def unquote(value) value.to_s.sub(/\A\([\(\']?/, "").sub(/[\'\)]?\)\Z/, "") end |
#unquote_string(value) ⇒ Object
JRUBY-2011: Match balanced quotes and parenthesis - ‘text’,(‘text’) or (text)
79 80 81 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 79 def unquote_string(value) value.to_s.sub(/^\((.*)\)$/,'\1').sub(/^'(.*)'$/,'\1') end |