#include <sqlite3.h>
Definition at line 21 of file sqlite3.h.
◆ Sqlite3_Database() [1/3]
| Botan::Sqlite3_Database::Sqlite3_Database |
( |
std::string_view | file, |
|
|
std::optional< int > | sqlite_open_flags = std::nullopt ) |
Create a new SQLite database handle from a file.
- Parameters
-
| file | path to the database file be opened and/or created |
| sqlite_open_flags | flags that will be passed to sqlite3_open_v2() (default: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX) |
Definition at line 18 of file sqlite3.cpp.
18 {
19
20
21 const int open_flags =
22 sqlite_open_flags.value_or(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
23 int rc = ::sqlite3_open_v2(std::string(db_filename).c_str(), &m_db, open_flags, nullptr);
24
25 if(rc != 0) [[unlikely]] {
26 const std::string err_msg = ::sqlite3_errmsg(m_db);
27 ::sqlite3_close(m_db);
28 m_db = nullptr;
29 throw SQL_DB_Error("sqlite3_open failed - " + err_msg);
30 }
31}
◆ ~Sqlite3_Database()
| Botan::Sqlite3_Database::~Sqlite3_Database |
( |
| ) |
|
|
override |
Definition at line 33 of file sqlite3.cpp.
33 {
34 if(m_db != nullptr) [[likely]] {
35 ::sqlite3_close(m_db);
36 }
37 m_db = nullptr;
38}
◆ Sqlite3_Database() [2/3]
◆ Sqlite3_Database() [3/3]
◆ create_table()
| void Botan::Sqlite3_Database::create_table |
( |
std::string_view | table_schema | ) |
|
|
overridevirtual |
Implements Botan::SQL_Database.
Definition at line 54 of file sqlite3.cpp.
54 {
55 char* errmsg = nullptr;
56 int rc = ::sqlite3_exec(m_db, std::string(table_schema).c_str(), nullptr, nullptr, &errmsg);
57
58 if(rc != SQLITE_OK) {
59 const std::string err_msg = errmsg;
60 ::sqlite3_free(errmsg);
61 ::sqlite3_close(m_db);
62 m_db = nullptr;
63 throw SQL_DB_Error("sqlite3_exec for table failed - " + err_msg);
64 }
65}
◆ exec()
| virtual size_t Botan::SQL_Database::exec |
( |
std::string_view | sql | ) |
|
|
inlinevirtualinherited |
Definition at line 77 of file database.h.
virtual std::shared_ptr< Statement > new_statement(std::string_view base_sql) const =0
◆ is_threadsafe()
| bool Botan::Sqlite3_Database::is_threadsafe |
( |
| ) |
const |
|
overridevirtual |
Reimplemented from Botan::SQL_Database.
Definition at line 73 of file sqlite3.cpp.
73 {
74 const int flag = sqlite3_threadsafe();
75
76
77
78
79
80
81
82
83
84
85
86
87
88 return flag >= 1;
89}
◆ new_statement()
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ row_count()
| size_t Botan::Sqlite3_Database::row_count |
( |
std::string_view | table_name | ) |
|
|
overridevirtual |
Implements Botan::SQL_Database.
Definition at line 44 of file sqlite3.cpp.
44 {
46
47 if(stmt->step()) {
48 return stmt->get_size_t(0);
49 } else {
50 throw SQL_DB_Error(
fmt(
"Querying size of table '{}' failed", table_name));
51 }
52}
std::shared_ptr< Statement > new_statement(std::string_view sql) const override
std::string fmt(std::string_view format, const T &... args)
References Botan::fmt(), and new_statement().
◆ rows_changed_by_last_statement()
| size_t Botan::Sqlite3_Database::rows_changed_by_last_statement |
( |
| ) |
|
|
overridevirtual |
The documentation for this class was generated from the following files: