Class: ActiveRecord::ConnectionAdapters::SQLite3Column
- Inherits:
-
JdbcColumn
- Object
- Column
- JdbcColumn
- ActiveRecord::ConnectionAdapters::SQLite3Column
- Defined in:
- lib/arjdbc/sqlite3/column.rb
Instance Attribute Summary collapse
-
#rowid ⇒ Object
readonly
Returns the value of attribute rowid.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #auto_increment? ⇒ Boolean
- #auto_incremented_by_db? ⇒ Boolean
- #default_value(value) ⇒ Object
- #encode_with(coder) ⇒ Object
- #has_default? ⇒ Boolean
- #hash ⇒ Object
- #init_with(coder) ⇒ Object
-
#initialize(auto_increment: nil, rowid: false, generated_type: nil) ⇒ SQLite3Column
constructor
A new instance of SQLite3Column.
- #type_cast(value) ⇒ Object
- #virtual? ⇒ Boolean
- #virtual_stored? ⇒ Boolean
Methods inherited from JdbcColumn
Constructor Details
#initialize(auto_increment: nil, rowid: false, generated_type: nil) ⇒ SQLite3Column
Returns a new instance of SQLite3Column.
8 9 10 11 12 13 14 15 |
# File 'lib/arjdbc/sqlite3/column.rb', line 8 def initialize(*, auto_increment: nil, rowid: false, generated_type: nil, **) super @auto_increment = auto_increment @default = nil if default =~ /NULL/ @rowid = rowid @generated_type = generated_type end |
Instance Attribute Details
#rowid ⇒ Object (readonly)
Returns the value of attribute rowid.
6 7 8 |
# File 'lib/arjdbc/sqlite3/column.rb', line 6 def rowid @rowid end |
Class Method Details
.binary_to_string(value) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/arjdbc/sqlite3/column.rb', line 21 def self.binary_to_string(value) if value.respond_to?(:encoding) && value.encoding != Encoding::ASCII_8BIT value = value.force_encoding(Encoding::ASCII_8BIT) end value end |
.string_to_binary(value) ⇒ Object
17 18 19 |
# File 'lib/arjdbc/sqlite3/column.rb', line 17 def self.string_to_binary(value) value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
66 67 68 69 70 |
# File 'lib/arjdbc/sqlite3/column.rb', line 66 def ==(other) other.is_a?(Column) && super && auto_increment? == other.auto_increment? end |
#auto_increment? ⇒ Boolean
36 37 38 |
# File 'lib/arjdbc/sqlite3/column.rb', line 36 def auto_increment? @auto_increment end |
#auto_incremented_by_db? ⇒ Boolean
40 41 42 |
# File 'lib/arjdbc/sqlite3/column.rb', line 40 def auto_incremented_by_db? auto_increment? || rowid end |
#default_value(value) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/arjdbc/sqlite3/column.rb', line 29 def default_value(value) # JDBC returns column default strings with actual single quotes : return $1 if value =~ /^'(.*)'$/ value end |
#encode_with(coder) ⇒ Object
61 62 63 64 |
# File 'lib/arjdbc/sqlite3/column.rb', line 61 def encode_with(coder) coder["auto_increment"] = @auto_increment super end |
#has_default? ⇒ Boolean
52 53 54 |
# File 'lib/arjdbc/sqlite3/column.rb', line 52 def has_default? super && !virtual? end |
#hash ⇒ Object
73 74 75 76 77 78 |
# File 'lib/arjdbc/sqlite3/column.rb', line 73 def hash Column.hash ^ super.hash ^ auto_increment?.hash ^ rowid.hash end |
#init_with(coder) ⇒ Object
56 57 58 59 |
# File 'lib/arjdbc/sqlite3/column.rb', line 56 def init_with(coder) @auto_increment = coder["auto_increment"] super end |
#type_cast(value) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/arjdbc/sqlite3/column.rb', line 81 def type_cast(value) return nil if value.nil? case type when :string then value when :primary_key value.respond_to?(:to_i) ? value.to_i : ( value ? 1 : 0 ) when :float then value.to_f when :decimal then self.class.value_to_decimal(value) when :boolean then self.class.value_to_boolean(value) else super end end |
#virtual? ⇒ Boolean
44 45 46 |
# File 'lib/arjdbc/sqlite3/column.rb', line 44 def virtual? !@generated_type.nil? end |
#virtual_stored? ⇒ Boolean
48 49 50 |
# File 'lib/arjdbc/sqlite3/column.rb', line 48 def virtual_stored? virtual? && @generated_type == :stored end |