Class: ActiveRecord::ConnectionAdapters::SQLite3Column

Inherits:
JdbcColumn
  • Object
show all
Defined in:
lib/arjdbc/sqlite3/column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from JdbcColumn

column_types

Constructor Details

#initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, auto_increment: nil, rowid: false) ⇒ SQLite3Column

Returns a new instance of SQLite3Column.



8
9
10
11
12
13
# File 'lib/arjdbc/sqlite3/column.rb', line 8

def initialize(name, default,  = nil, null = true, default_function = nil, collation: nil, comment: nil, auto_increment: nil, rowid: false, **)
  super
  @auto_increment = auto_increment
  @default = nil if default =~ /NULL/
  @rowid = rowid
end

Instance Attribute Details

#rowidObject (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



19
20
21
22
23
24
# File 'lib/arjdbc/sqlite3/column.rb', line 19

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



15
16
17
# File 'lib/arjdbc/sqlite3/column.rb', line 15

def self.string_to_binary(value)
  value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



52
53
54
55
56
# File 'lib/arjdbc/sqlite3/column.rb', line 52

def ==(other)
  other.is_a?(Column) &&
    super &&
    auto_increment? == other.auto_increment?
end

#auto_increment?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/arjdbc/sqlite3/column.rb', line 34

def auto_increment?
  @auto_increment
end

#auto_incremented_by_db?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/arjdbc/sqlite3/column.rb', line 38

def auto_incremented_by_db?
  auto_increment? || rowid
end

#default_value(value) ⇒ Object



27
28
29
30
31
32
# File 'lib/arjdbc/sqlite3/column.rb', line 27

def default_value(value)
  # JDBC returns column default strings with actual single quotes :
  return $1 if value =~ /^'(.*)'$/

  value
end

#encode_with(coder) ⇒ Object



47
48
49
50
# File 'lib/arjdbc/sqlite3/column.rb', line 47

def encode_with(coder)
  coder["auto_increment"] = @auto_increment
  super
end

#hashObject



59
60
61
62
63
64
# File 'lib/arjdbc/sqlite3/column.rb', line 59

def hash
  Column.hash ^
    super.hash ^
    auto_increment?.hash ^
    rowid.hash
end

#init_with(coder) ⇒ Object



42
43
44
45
# File 'lib/arjdbc/sqlite3/column.rb', line 42

def init_with(coder)
  @auto_increment = coder["auto_increment"]
  super
end

#type_cast(value) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/arjdbc/sqlite3/column.rb', line 67

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