Botan 2.19.1
Crypto and TLS for C&
Classes | Public Member Functions | List of all members
Botan::Sqlite3_Database Class Referencefinal

#include <sqlite3.h>

Inheritance diagram for Botan::Sqlite3_Database:
Botan::SQL_Database

Public Member Functions

void create_table (const std::string &table_schema) override
 
std::shared_ptr< Statementnew_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 ()
 

Detailed Description

Definition at line 18 of file sqlite3.h.

Constructor & Destructor Documentation

◆ Sqlite3_Database()

Botan::Sqlite3_Database::Sqlite3_Database ( const std::string &  file)

Definition at line 15 of file sqlite3.cpp.

16 {
17 int rc = ::sqlite3_open(db_filename.c_str(), &m_db);
18
19 if(rc)
20 {
21 const std::string err_msg = ::sqlite3_errmsg(m_db);
22 ::sqlite3_close(m_db);
23 m_db = nullptr;
24 throw SQL_DB_Error("sqlite3_open failed - " + err_msg);
25 }
26 }

◆ ~Sqlite3_Database()

Botan::Sqlite3_Database::~Sqlite3_Database ( )

Definition at line 28 of file sqlite3.cpp.

29 {
30 if(m_db)
31 ::sqlite3_close(m_db);
32 m_db = nullptr;
33 }

Member Function Documentation

◆ create_table()

void Botan::Sqlite3_Database::create_table ( const std::string &  table_schema)
overridevirtual

Implements Botan::SQL_Database.

Definition at line 50 of file sqlite3.cpp.

51 {
52 char* errmsg = nullptr;
53 int rc = ::sqlite3_exec(m_db, table_schema.c_str(), nullptr, nullptr, &errmsg);
54
55 if(rc != SQLITE_OK)
56 {
57 const std::string err_msg = errmsg;
58 ::sqlite3_free(errmsg);
59 ::sqlite3_close(m_db);
60 m_db = nullptr;
61 throw SQL_DB_Error("sqlite3_exec for table failed - " + err_msg);
62 }
63 }

◆ new_statement()

std::shared_ptr< SQL_Database::Statement > Botan::Sqlite3_Database::new_statement ( const std::string &  sql) const
overridevirtual

Implements Botan::SQL_Database.

Definition at line 35 of file sqlite3.cpp.

36 {
37 return std::make_shared<Sqlite3_Statement>(m_db, base_sql);
38 }

Referenced by row_count().

◆ row_count()

size_t Botan::Sqlite3_Database::row_count ( const std::string &  table_name)
overridevirtual

Implements Botan::SQL_Database.

Definition at line 40 of file sqlite3.cpp.

41 {
42 auto stmt = new_statement("select count(*) from " + table_name);
43
44 if(stmt->step())
45 return stmt->get_size_t(0);
46 else
47 throw SQL_DB_Error("Querying size of table " + table_name + " failed");
48 }
std::shared_ptr< Statement > new_statement(const std::string &sql) const override
Definition: sqlite3.cpp:35

References new_statement().


The documentation for this class was generated from the following files: