Botan 3.8.1
Crypto and TLS for C&
sqlite3.h
Go to the documentation of this file.
1/*
2* SQLite3 wrapper
3* (C) 2012,2014 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_UTILS_SQLITE3_H_
9#define BOTAN_UTILS_SQLITE3_H_
10
11#include <botan/database.h>
12
13#include <memory>
14#include <optional>
15
16struct sqlite3;
17struct sqlite3_stmt;
18
19namespace Botan {
20
22 public:
23 /**
24 * Create a new SQLite database handle from a file.
25 *
26 * @param file path to the database file be opened and/or created
27 * @param sqlite_open_flags flags that will be passed to sqlite3_open_v2()
28 * (default: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX)
29 */
30 Sqlite3_Database(std::string_view file, std::optional<int> sqlite_open_flags = std::nullopt);
31
32 ~Sqlite3_Database() override;
33
34 size_t row_count(std::string_view table_name) override;
35
36 void create_table(std::string_view table_schema) override;
37
38 size_t rows_changed_by_last_statement() override;
39
40 std::shared_ptr<Statement> new_statement(std::string_view sql) const override;
41
42 bool is_threadsafe() const override;
43
44 private:
45 class Sqlite3_Statement final : public Statement {
46 public:
47 void bind(int column, std::string_view val) override;
48 void bind(int column, size_t val) override;
49 void bind(int column, std::chrono::system_clock::time_point time) override;
50 void bind(int column, const std::vector<uint8_t>& val) override;
51 void bind(int column, const uint8_t* data, size_t len) override;
52
53 std::pair<const uint8_t*, size_t> get_blob(int column) override;
54 std::string get_str(int column) override;
55 size_t get_size_t(int column) override;
56
57 size_t spin() override;
58 bool step() override;
59
60 Sqlite3_Statement(sqlite3* db, std::string_view base_sql);
61 ~Sqlite3_Statement() override;
62
63 private:
64 sqlite3_stmt* m_stmt;
65 };
66
67 sqlite3* m_db;
68};
69
70} // namespace Botan
71
72#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
std::shared_ptr< Statement > new_statement(std::string_view sql) const override
Definition sqlite3.cpp:39
size_t rows_changed_by_last_statement() override
Definition sqlite3.cpp:66
bool is_threadsafe() const override
Definition sqlite3.cpp:72
void create_table(std::string_view table_schema) override
Definition sqlite3.cpp:53
Sqlite3_Database(std::string_view file, std::optional< int > sqlite_open_flags=std::nullopt)
Definition sqlite3.cpp:17
size_t row_count(std::string_view table_name) override
Definition sqlite3.cpp:43