Class: SQLite3::Value
- Inherits:
-
Object
- Object
- SQLite3::Value
- Defined in:
- lib/sqlite3/value.rb
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Instance Method Summary collapse
-
#initialize(db, handle) ⇒ Value
constructor
A new instance of Value.
- #length(utf16 = false) ⇒ Object (also: #size)
- #native ⇒ Object
- #null? ⇒ Boolean
- #to_blob ⇒ Object
- #to_f ⇒ Object
- #to_i ⇒ Object
- #to_int64 ⇒ Object
- #to_s(utf16 = false) ⇒ Object
- #type ⇒ Object
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
#handle ⇒ Object (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 |
#native ⇒ Object
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
12 13 14 |
# File 'lib/sqlite3/value.rb', line 12 def null? type == :null end |
#to_blob ⇒ Object
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_f ⇒ Object
31 32 33 |
# File 'lib/sqlite3/value.rb', line 31 def to_f Driver.sqlite3_value_double(@handle) end |
#to_i ⇒ Object
35 36 37 |
# File 'lib/sqlite3/value.rb', line 35 def to_i Driver.sqlite3_value_int(@handle) end |
#to_int64 ⇒ Object
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 |
#type ⇒ Object
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 |