Module: ArJdbc::SybaseSQLAnywhere::Column
- Defined in:
- lib/arjdbc/sqlanywhere/adapter.rb
Instance Method Summary collapse
-
#default_value(value) ⇒ Object
Post process default value from JDBC into a Rails-friendly format (columns-internal).
- #init_column(name, default, *args) ⇒ Object
- #simplified_type(field_type) ⇒ Object
- #type_cast(value) ⇒ Object
Instance Method Details
#default_value(value) ⇒ Object
Post process default value from JDBC into a Rails-friendly format (columns-internal)
22 23 24 25 26 27 28 |
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 22 def default_value(value) return nil if value =~ /^autoincrement$/i # jdbc returns column default strings with actual single quotes around the value. return $1 if value =~ /^'(.*)'$/ value end |
#init_column(name, default, *args) ⇒ Object
17 18 19 |
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 17 def init_column(name, default, *args) @name = name.downcase end |
#simplified_type(field_type) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 30 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
47 48 49 50 51 52 53 54 55 |
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 47 def type_cast(value) return nil if value.nil? || value == "(null)" || value == "(NULL)" case type when :primary_key then value == true || value == false ? value == true ? 1 : 0 : value.to_i when :boolean then value == true or (value =~ /^t(rue)?$/i) == 0 or value=="1" else super end end |