libnick 2025.9.1
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
sqlitefunctioncontext.h
Go to the documentation of this file.
1
22
23#ifndef SQLITEFUNCTIONCONTEXT_H
24#define SQLITEFUNCTIONCONTEXT_H
25
26#include <vector>
27#include "sqlite.h"
28#include "sqlitevalue.h"
29
31{
36 {
37 public:
44 SqliteFunctionContext(sqlite3_context* ctx, int argc, sqlite3_value** argv) noexcept;
55 void* getUserData() const noexcept;
60 const std::vector<SqliteValue>& getArgs() const noexcept;
64 void result() noexcept;
70 template<SupportedSqliteValue T>
71 void result(const T& value) noexcept
72 {
73 if(!m_context)
74 {
75 return;
76 }
77 if constexpr (std::is_same_v<T, int>)
78 {
79 sqlite3_result_int(m_context, value);
80 }
81 else if constexpr (std::is_same_v<T, sqlite3_int64>)
82 {
83 sqlite3_result_int64(m_context, value);
84 }
85 else if constexpr (std::is_same_v<T, double>)
86 {
87 sqlite3_result_double(m_context, value);
88 }
89 else if constexpr (std::is_same_v<T, bool>)
90 {
91 sqlite3_result_int(m_context, value ? 1 : 0);
92 }
93 else if constexpr (std::is_same_v<T, std::string>)
94 {
95 sqlite3_result_text(m_context, value.c_str(), value.size(), SQLITE_TRANSIENT);
96 }
97 }
98
102 void error(const std::string& err) noexcept;
107 void error(int err) noexcept;
115
116 private:
117 sqlite3_context* m_context;
118 std::vector<SqliteValue> m_values;
119 };
120}
121
122#endif //SQLITEFUNCTIONCONTEXT_H
void * getUserData() const noexcept
Gets the pointer to the user data for the context.
void error(int err) noexcept
Returns an error from the sql function.
SqliteFunctionContext & operator=(const SqliteFunctionContext &)=delete
void result() noexcept
Returns a NULL value from the sql function.
void error(const std::string &err) noexcept
Returns an error from the sql function.
const std::vector< SqliteValue > & getArgs() const noexcept
Gets the list of SqliteValue arguments passed to the function.
SqliteFunctionContext(sqlite3_context *ctx, int argc, sqlite3_value **argv) noexcept
Constructs an SqliteFunctionContext.
SqliteFunctionContext & operator=(SqliteFunctionContext &&other) noexcept
Assigns a SqliteFunctionContext via move.
SqliteFunctionContext(const SqliteFunctionContext &)=delete
SqliteFunctionContext(SqliteFunctionContext &&other) noexcept
Constructs a SqliteFunctionContext via move.
A sqlite value.
Definition sqlitevalue.h:34
Definition sqlite.h:40