Botan
1.11.15
|
#include <sqlite3.h>
Classes | |
class | Sqlite3_Statement |
Public Member Functions | |
void | create_table (const std::string &table_schema) override |
std::shared_ptr< Statement > | new_statement (const std::string &sql) const override |
size_t | row_count (const std::string &table_name) override |
Sqlite3_Database (const std::string &file) | |
~Sqlite3_Database () |
Botan::Sqlite3_Database::Sqlite3_Database | ( | const std::string & | file | ) |
Definition at line 14 of file sqlite3.cpp.
{ int rc = ::sqlite3_open(db_filename.c_str(), &m_db); if(rc) { const std::string err_msg = ::sqlite3_errmsg(m_db); ::sqlite3_close(m_db); m_db = nullptr; throw std::runtime_error("sqlite3_open failed - " + err_msg); } }
Definition at line 27 of file sqlite3.cpp.
{ if(m_db) ::sqlite3_close(m_db); m_db = nullptr; }
void Botan::Sqlite3_Database::create_table | ( | const std::string & | table_schema | ) | [override, virtual] |
Implements Botan::SQL_Database.
Definition at line 49 of file sqlite3.cpp.
{ char* errmsg = nullptr; int rc = ::sqlite3_exec(m_db, table_schema.c_str(), nullptr, nullptr, &errmsg); if(rc != SQLITE_OK) { const std::string err_msg = errmsg; ::sqlite3_free(errmsg); ::sqlite3_close(m_db); m_db = nullptr; throw std::runtime_error("sqlite3_exec for table failed - " + err_msg); } }
std::shared_ptr< SQL_Database::Statement > Botan::Sqlite3_Database::new_statement | ( | const std::string & | sql | ) | const [override, virtual] |
Implements Botan::SQL_Database.
Definition at line 34 of file sqlite3.cpp.
Referenced by row_count().
{
return std::make_shared<Sqlite3_Statement>(m_db, base_sql);
}
size_t Botan::Sqlite3_Database::row_count | ( | const std::string & | table_name | ) | [override, virtual] |
Implements Botan::SQL_Database.
Definition at line 39 of file sqlite3.cpp.
References new_statement().
{ auto stmt = new_statement("select count(*) from " + table_name); if(stmt->step()) return stmt->get_size_t(0); else throw std::runtime_error("Querying size of table " + table_name + " failed"); }