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.



8
9
10
# File 'lib/sqlite3/value.rb', line 8

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

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



6
7
8
# File 'lib/sqlite3/value.rb', line 6

def handle
  @handle
end

Instance Method Details

#length(utf16 = false) ⇒ Object Also known as: size



21
22
23
24
25
26
27
# File 'lib/sqlite3/value.rb', line 21

def length(utf16=false)
  if utf16
    Driver.sqlite3_value_bytes16(@handle)
  else
    Driver.sqlite3_value_bytes(@handle)
  end
end

#nativeObject



61
62
63
64
65
66
67
68
69
# File 'lib/sqlite3/value.rb', line 61

def native
  case Driver.sqlite3_value_type(@handle)
  when SQLITE_INTEGER then to_int64
  when SQLITE_FLOAT   then to_f
  when SQLITE_TEXT    then to_s
  when SQLITE_BLOB    then to_blob
  when SQLITE_NULL    then nil
  end
end

#null?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/sqlite3/value.rb', line 12

def null?
  type == :null
end

#to_blobObject



16
17
18
19
# File 'lib/sqlite3/value.rb', line 16

def to_blob
  bytes = size
  Blob.new(Driver.sqlite3_value_blob(@handle).to_s(bytes))
end

#to_fObject



31
32
33
# File 'lib/sqlite3/value.rb', line 31

def to_f
  Driver.sqlite3_value_double(@handle)
end

#to_iObject



35
36
37
# File 'lib/sqlite3/value.rb', line 35

def to_i
  Driver.sqlite3_value_int(@handle)
end

#to_int64Object



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

def to_int64
  Driver.sqlite3_value_int64(@handle)
end

#to_s(utf16 = false) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/sqlite3/value.rb', line 43

def to_s(utf16=false)
  if utf16
    Driver.sqlite3_result_text16(@handle).to_s
  else
    Driver.sqlite3_value_text(@handle).to_s
  end
end

#typeObject



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

def type
  case Driver.sqlite3_value_type(@handle)
    when SQLITE_INTEGER then :int
    when SQLITE_FLOAT   then :float
    when SQLITE_TEXT    then :text
    when SQLITE_BLOB    then :blob
    when SQLITE_NULL    then :null
  end
end