Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Member Functions | List of all members
Botan::Sqlite3_Database Class Reference

`#include <sqlite3.h>`

Inheritance diagram for Botan::Sqlite3_Database:

## 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 ()

## Detailed Description

Definition at line 18 of file sqlite3.h.

## Constructor & Destructor Documentation

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

Definition at line 14 of file sqlite3.cpp.

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

Botan::Sqlite3_Database::~Sqlite3_Database | ( |  | ) |

Definition at line 27 of file sqlite3.cpp.

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

## Member Function Documentation

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.

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

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().

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

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().

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

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

- src/lib/utils/sqlite3/sqlite3.h
- src/lib/utils/sqlite3/sqlite3.cpp