Botan 3.9.0
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 BOTAN_FUTURE_EXPLICIT Sqlite3_Database(std::string_view file,
31 std::optional<int> sqlite_open_flags = std::nullopt);
32
33 ~Sqlite3_Database() override;
34
35 Sqlite3_Database(const Sqlite3_Database& other) = delete;
39
40 size_t row_count(std::string_view table_name) override;
41
42 void create_table(std::string_view table_schema) override;
43
44 size_t rows_changed_by_last_statement() override;
45
46 std::shared_ptr<Statement> new_statement(std::string_view sql) const override;
47
48 bool is_threadsafe() const override;
49
50 private:
51 class Sqlite3_Statement final : public Statement {
52 public:
53 void bind(int column, std::string_view val) override;
54 void bind(int column, size_t val) override;
55 void bind(int column, std::chrono::system_clock::time_point time) override;
56 void bind(int column, const std::vector<uint8_t>& val) override;
57 void bind(int column, const uint8_t* data, size_t len) override;
58
59 std::pair<const uint8_t*, size_t> get_blob(int column) override;
60 std::string get_str(int column) override;
61 size_t get_size_t(int column) override;
62
63 size_t spin() override;
64 bool step() override;
65
66 Sqlite3_Statement(sqlite3* db, std::string_view base_sql);
67 ~Sqlite3_Statement() override;
68
69 Sqlite3_Statement(const Sqlite3_Statement& other) = delete;
70 Sqlite3_Statement(Sqlite3_Statement&& other) = delete;
71 Sqlite3_Statement& operator=(const Sqlite3_Statement& other) = delete;
72 Sqlite3_Statement& operator=(Sqlite3_Statement&& other) = delete;
73
74 private:
75 sqlite3_stmt* m_stmt;
76 };
77
78 sqlite3* m_db;
79};
80
81} // namespace Botan
82
83#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
Sqlite3_Database & operator=(const Sqlite3_Database &other)=delete
Sqlite3_Database & operator=(Sqlite3_Database &&other)=delete
Sqlite3_Database(Sqlite3_Database &&other)=delete
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
Sqlite3_Database(const Sqlite3_Database &other)=delete
void create_table(std::string_view table_schema) override
Definition sqlite3.cpp:53
BOTAN_FUTURE_EXPLICIT 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