value.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require 'sqlite3/constants'
  2. module SQLite3
  3. class Value
  4. attr_reader :handle
  5. def initialize( db, handle )
  6. @driver = db.driver
  7. @handle = handle
  8. end
  9. def null?
  10. type == :null
  11. end
  12. def to_blob
  13. @driver.value_blob( @handle )
  14. end
  15. def length( utf16=false )
  16. if utf16
  17. @driver.value_bytes16( @handle )
  18. else
  19. @driver.value_bytes( @handle )
  20. end
  21. end
  22. def to_f
  23. @driver.value_double( @handle )
  24. end
  25. def to_i
  26. @driver.value_int( @handle )
  27. end
  28. def to_int64
  29. @driver.value_int64( @handle )
  30. end
  31. def to_s( utf16=false )
  32. @driver.value_text( @handle, utf16 )
  33. end
  34. def type
  35. case @driver.value_type( @handle )
  36. when Constants::ColumnType::INTEGER then :int
  37. when Constants::ColumnType::FLOAT then :float
  38. when Constants::ColumnType::TEXT then :text
  39. when Constants::ColumnType::BLOB then :blob
  40. when Constants::ColumnType::NULL then :null
  41. end
  42. end
  43. end
  44. end