16 sqlite3* db =
nullptr;
41 sqlite3_finalize(this->stmt);
46 sqlite3_finalize(stmt);
51 sqlite3_stmt* stmt =
nullptr;
61 template<
typename... Args>
64 void bind(Args... args) {
73 if (
sizeof...(Args) > this->params) {
74 throw ValueError(
"Too many arguments to bind() " +
75 std::to_string(this->params) +
" expected " + std::to_string(
sizeof...(Args)) +
" specified");
79 _bind_many(i, args...);
84 void bind(
const size_t i,
const T value) {
85 static_assert(
false,
"Cannot call bind() on values of this type. Supported types are:" 86 " char *, string, int, long int, and double.");
90 inline void bind(
const size_t i,
const char* value) {
100 inline void bind(
const size_t i,
const std::string value) {
115 inline void bind(
const size_t i,
const int value) {
117 sqlite3_bind_int(this->get_ptr(), i + 1, value);
121 inline void bind(
const size_t i,
const long int value) {
123 sqlite3_bind_int64(this->get_ptr(), i + 1, value);
127 void bind(
const size_t i,
double value) {
129 sqlite3_bind_double(this->get_ptr(), i + 1, value);
133 sqlite3_stmt* get_ptr();
136 void close() noexcept;
141 std::shared_ptr<stmt_base> base = std::make_shared<stmt_base>();
148 void _bind_many(
size_t i, T value) {
153 template<
typename T,
typename... Args>
154 void _bind_many(
size_t i, T value, Args... args) {
157 _bind_many(i, args...);
165 std::vector<std::string> get_col_names();
166 std::vector<std::string> get_row();
169 using PreparedStatement::close;
170 using PreparedStatement::PreparedStatement;
174 Conn(
const char * db_name);
175 Conn(
const std::string db_name);
176 void exec(
const std::string query);
179 void close() noexcept;
182 std::shared_ptr<conn_base> base =
183 std::make_shared<conn_base>();
186 std::queue<PreparedStatement*>
stmts;
197 DatabaseClosed() :runtime_error(
"Attempted operation on a closed database.") {};
203 StatementClosed() :runtime_error(
"Attempted operation on a closed statement.") {};
209 ValueError() :runtime_error(
"[Value Error] Invalid value or value(s).") {};
210 ValueError(
const std::string& msg) :runtime_error(
"[Value Error] " + msg) {};
216 SQLiteError(
const std::string& msg) :runtime_error(
"[SQLite Error] " + msg) {};
221 { 1,
"SQLITE_ERROR: Generic SQLite Error" },
222 { 19,
"SQLITE_CONSTRAINT: SQL constrainted violated" }
225 const std::map<int, std::string> SQLITE_EXT_ERROR_MSG = {
226 { 787,
"SQLITE_CONSTRAINT_FOREIGNKEY: Foreign key constraint failed" },
227 { 1555,
"SQLITE_CONSTRAINT_PRIMARYKEY: Primary key constraint failed" }
230 void throw_sqlite_error(
const int& error_code,
231 const int& ext_error_code=-1);
Definition: sqlite_cpp.h:163
void bind(const size_t i, const long int value)
Definition: sqlite_cpp.h:121
const std::map< int, std::string > SQLITE_ERROR_MSG
Definition: sqlite_cpp.h:220
Definition: sqlite_cpp.h:214
Definition: sqlite_cpp.h:36
Definition: sqlite_cpp.h:55
Definition: sqlite_cpp.h:58
void bind(const size_t i, double value)
Definition: sqlite_cpp.h:127
Definition: sqlite_cpp.h:207
void bind(const size_t i, const int value)
Definition: sqlite_cpp.h:115
Definition: sqlite_cpp.h:201
Definition: sqlite_cpp.h:14
sqlite3 ** get_ref()
Definition: sqlite_cpp.h:19
char * error_message
Definition: sqlite_cpp.h:184
Definition: sqlite_cpp.cpp:3
std::queue< PreparedStatement * > stmts
Definition: sqlite_cpp.h:186
Definition: sqlite_cpp.h:195
void bind(const size_t i, const std::string value)
Definition: sqlite_cpp.h:100