11 #include "SQLamarr/BaseSqlInterface.h"
12 #include "SQLamarr/custom_sql_functions.h"
13 #include "SQLamarr/SQLiteError.h"
25 , m_cached_raw_ptr (nullptr)
27 sqlamarr_create_sql_functions(db.get());
43 for (
auto q = m_queries.begin(); q != m_queries.end(); ++q)
44 sqlite3_finalize(q->second);
53 const std::string& name,
54 const std::string& query
63 if (m_queries.find(name) == m_queries.end())
66 sqlite3_reset(m_queries[name]);
67 return m_queries[name];
74 const std::string& name,
76 void (*xFunc)(sqlite3_context*,
int, sqlite3_value**)
79 sqlite3_create_function(
82 SQLITE_UTF8,
nullptr, xFunc,
nullptr,
nullptr
91 switch (sqlite3_step(stmt))
93 case SQLITE_DONE:
return false;
94 case SQLITE_ROW:
return true;
96 std::cerr << sqlite3_errmsg(
m_database.get()) << std::endl;
sqlite3_stmt * get_statement(const std::string &name, const std::string &query)
Creates or retrieve from cache a statement.
BaseSqlInterface(SQLite3DB &db)
Constructor, acquiring the database without ownership.
virtual ~BaseSqlInterface()
void invalidate_cache(void)
Invalidate the cache of the queries.
bool exec_stmt(sqlite3_stmt *)
Execute a statement, possibly throwing an exception on failure.
void using_sql_function(const std::string &name, int argc, void(*xFunc)(sqlite3_context *, int, sqlite3_value **))
Register a static function in DB, enabling usage from SQL.
SQLite3DB & m_database
Reference to the SQLite database (not owned).
A database connection handler easying sharing the DB between C++ and Python.
sqlite3_stmt * prepare_statement(SQLite3DB &db, const std::string &query)
Prpare a statement.