libnick 2025.9.1
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
sqlitevalue.h
Go to the documentation of this file.
1
22
23#ifndef SQLITEVALUE_H
24#define SQLITEVALUE_H
25
26#include "sqlite.h"
27
29{
34 {
35 public:
40 SqliteValue(sqlite3_value* value) noexcept;
45 SqliteValue(const SqliteValue& other) noexcept;
50 SqliteValue(SqliteValue&& other) noexcept;
54 ~SqliteValue() noexcept;
61 template<SupportedSqliteValue T>
62 T as() const noexcept
63 {
64 if constexpr (std::is_same_v<T, int>)
65 {
66 if(!m_value || m_type != SQLITE_INTEGER)
67 {
68 return 0;
69 }
70 return sqlite3_value_int(m_value);
71 }
72 else if constexpr (std::is_same_v<T, std::int64_t>)
73 {
74 if(!m_value || m_type != SQLITE_INTEGER)
75 {
76 return 0;
77 }
78 return sqlite3_value_int64(m_value);
79 }
80 else if constexpr (std::is_same_v<T, double>)
81 {
82 if(!m_value || m_type != SQLITE_FLOAT)
83 {
84 return 0.0;
85 }
86 return sqlite3_value_double(m_value);
87 }
88 else if constexpr (std::is_same_v<T, bool>)
89 {
90 if(!m_value || m_type != SQLITE_INTEGER)
91 {
92 return false;
93 }
94 return static_cast<bool>(sqlite3_value_int(m_value));
95 }
96 else if constexpr (std::is_same_v<T, std::string>)
97 {
98 if(!m_value || m_type != SQLITE3_TEXT)
99 {
100 return "";
101 }
102 return { reinterpret_cast<const char*>(sqlite3_value_text(m_value)), static_cast<size_t>(sqlite3_value_bytes(m_value)) };
103 }
104 }
105
109 SqliteValue& operator=(const SqliteValue& other) noexcept;
115
116 private:
117 sqlite3_value* m_value;
118 int m_type;
119 };
120}
121
122#endif //SQLITEVALUE_H
123
SqliteValue(SqliteValue &&other) noexcept
Constructs a SqliteValue via move.
SqliteValue & operator=(const SqliteValue &other) noexcept
Assigns a SqliteValue via copy.
T as() const noexcept
Gets the sqlite value as a specific type.
Definition sqlitevalue.h:62
SqliteValue & operator=(SqliteValue &&other) noexcept
Assigns a SqliteValue via move.
~SqliteValue() noexcept
Destructs the SqliteValue.
SqliteValue(const SqliteValue &other) noexcept
Constructs a SqliteValue via copy.
SqliteValue(sqlite3_value *value) noexcept
Constructs an SqliteValue.
Definition sqlite.h:40