Class: SQLite3::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/sqlite3/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, handle) ⇒ Value

Returns a new instance of Value.



40
41
42
43
# File 'lib/sqlite3/value.rb', line 40

def initialize( db, handle )
  @driver = db.driver
  @handle = handle
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



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

def handle
  @handle
end

Instance Method Details

#length(utf16 = false) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/sqlite3/value.rb', line 53

def length( utf16=false )
  if utf16
    @driver.value_bytes16( @handle )
  else
    @driver.value_bytes( @handle )
  end
end

#null?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/sqlite3/value.rb', line 45

def null?
  type == :null
end

#to_blobObject



49
50
51
# File 'lib/sqlite3/value.rb', line 49

def to_blob
  @driver.value_blob( @handle )
end

#to_fObject



61
62
63
# File 'lib/sqlite3/value.rb', line 61

def to_f
  @driver.value_double( @handle )
end

#to_iObject



65
66
67
# File 'lib/sqlite3/value.rb', line 65

def to_i
  @driver.value_int( @handle )
end

#to_int64Object



69
70
71
# File 'lib/sqlite3/value.rb', line 69

def to_int64
  @driver.value_int64( @handle )
end

#to_s(utf16 = false) ⇒ Object



73
74
75
# File 'lib/sqlite3/value.rb', line 73

def to_s( utf16=false )
  @driver.value_text( @handle, utf16 )
end

#typeObject



77
78
79
80
81
82
83
84
85
# File 'lib/sqlite3/value.rb', line 77

def type
  case @driver.value_type( @handle )
    when Constants::ColumnType::INTEGER then :int
    when Constants::ColumnType::FLOAT   then :float
    when Constants::ColumnType::TEXT    then :text
    when Constants::ColumnType::BLOB    then :blob
    when Constants::ColumnType::NULL    then :null
  end
end