SQLiteXX  0.1.0
 All Classes Namespaces Files Functions Enumerations Enumerator
Value.cpp
1 #include "Value.h"
2 
3 
4 namespace sqlite
5 {
6  value::value(const sqlite3_value* const value) :
7  m_handle(sqlite3_value_dup(value), sqlite3_value_free)
8  {}
9 
10  value::value(const value& other) :
11  m_handle(sqlite3_value_dup(other.m_handle.get()), sqlite3_value_free)
12  {}
13 
14  value::value(value&& other) :
15  m_handle(std::move(other.m_handle))
16  {}
17 
18  sqlite3_value* value::handle() const noexcept {
19  return m_handle.get();
20  }
21 
22  value& value::operator=(const value& other) {
23  if (this != &other) {
24  m_handle.reset(sqlite3_value_dup(other.m_handle.get()));
25  }
26 
27  return *this;
28  }
29 
31  assert(this != &other);
32  m_handle = std::move(other.m_handle);
33  return *this;
34  }
35 
36  int value::as_int() const noexcept
37  {
38  return sqlite3_value_int(handle());
39  }
40 
41  int64_t value::as_int64() const noexcept
42  {
43  return sqlite3_value_int64(handle());
44  }
45 
46  unsigned int value::as_uint() const noexcept
47  {
48  return static_cast<unsigned int>(as_int64());
49  }
50 
51  double value::as_double() const noexcept
52  {
53  return sqlite3_value_double(handle());
54  }
55 
56  const blob value::as_blob() const noexcept
57  {
58  const void *blob = sqlite3_value_blob(handle());
59  return sqlite::blob(blob, bytes());
60  }
61 
62  const std::string value::as_string() const noexcept
63  {
64  const char *txt = as_text();
65  return std::string(txt, text_length());
66  }
67 
68  const std::u16string value::as_u16string() const noexcept
69  {
70  const char16_t *txt = as_text16();
71  return std::u16string(txt, text16_length());
72  }
73 
74  int value::bytes() const noexcept
75  {
76  return sqlite3_value_bytes(handle());
77  }
78 
79  datatype value::type() const noexcept
80  {
81  return static_cast<datatype>(sqlite3_value_type(handle()));
82  }
83 
84  const char* value::as_text() const noexcept
85  {
86  return reinterpret_cast<const char *>(sqlite3_value_text(handle()));
87  }
88 
94  const char16_t* value::as_text16() const noexcept
95  {
96  return reinterpret_cast<const char16_t *>(sqlite3_value_text16(handle()));
97  }
98 
99  int value::text_length() const noexcept
100  {
101  // Make sure to only call this function after as_text or as_blob was called
102  // otherwise will not return correct value.
103  return sqlite3_value_bytes(handle());
104  }
105 
106  int value::text16_length() const noexcept
107  {
108  return sqlite3_value_bytes16(handle()) / sizeof(char16_t);
109  }
110 }
datatype type() const noexcept
Returns the datatype for the initial datatype of the value.
Definition: Value.cpp:79
A SQLite dynamically typed value object, aka "sqlite3_value".
Definition: Value.h:27
int64_t as_int64() const noexcept
Represents the value as a 64-bit integer.
Definition: Value.cpp:41
value & operator=(const value &other)
Copy assignment operator.
Definition: Value.cpp:22
a group and bits
const blob as_blob() const noexcept
Represents the value as a blob object.
Definition: Value.cpp:56
const std::string as_string() const noexcept
Represents the value as a string.
Definition: Value.cpp:62
const std::u16string as_u16string() const noexcept
Represents the value as a UTF-16 string.
Definition: Value.cpp:68
unsigned int as_uint() const noexcept
Represents the value as an unsigned integer.
Definition: Value.cpp:46
datatype
Every value in SQLite has one of the following fundamental datatypes.
Definition: SQLiteEnums.h:13
double as_double() const noexcept
Represents the value as a double.
Definition: Value.cpp:51
int bytes() const noexcept
Returns the size in bytes of the value.
Definition: Value.cpp:74
sqlite3_value * handle() const noexcept
Returns pointer to the underlying "sqlite3_value" object.
Definition: Value.cpp:18
value(const sqlite3_value *const value)
Constructs a value object from a sqlite3_value object.
Definition: Value.cpp:6
int as_int() const noexcept
Represents the value as an integer.
Definition: Value.cpp:36
A "Binary Large OBject".
Definition: Blob.h:20