diff options
author | lloyd <[email protected]> | 2014-12-20 13:45:23 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-12-20 13:45:23 +0000 |
commit | 4083193089f91ec11584ae729ecc3b4cc3b4b86a (patch) | |
tree | d6edc4e416f3eb34aeb91b00d2bee6386962f316 /src/lib/utils/sqlite3/sqlite3.h | |
parent | 4562cd4366c81c905dc8957837c6128b193a28bd (diff) |
Add abstract database interface so applications can easily store info
in places other than sqlite3, though sqlite3 remains the only
implementation. The interface is currently limited to precisely the
functionality the TLS session manager needs and will likely expand.
Diffstat (limited to 'src/lib/utils/sqlite3/sqlite3.h')
-rw-r--r-- | src/lib/utils/sqlite3/sqlite3.h | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/src/lib/utils/sqlite3/sqlite3.h b/src/lib/utils/sqlite3/sqlite3.h index 3085ff0e3..7853a012f 100644 --- a/src/lib/utils/sqlite3/sqlite3.h +++ b/src/lib/utils/sqlite3/sqlite3.h @@ -1,66 +1,56 @@ /* -* SQLite wrapper -* (C) 2012 Jack Lloyd +* SQLite3 wrapper +* (C) 2012,2014 Jack Lloyd * * Released under the terms of the Botan license */ -#ifndef BOTAN_UTILS_SQLITE_WRAPPER_H__ -#define BOTAN_UTILS_SQLITE_WRAPPER_H__ +#ifndef BOTAN_UTILS_SQLITE3_H__ +#define BOTAN_UTILS_SQLIT3_H__ -#include <botan/types.h> -#include <string> -#include <chrono> -#include <vector> +#include <botan/database.h> class sqlite3; class sqlite3_stmt; namespace Botan { -class sqlite3_database +class BOTAN_DLL Sqlite3_Database : public SQL_Database { public: - sqlite3_database(const std::string& file); + Sqlite3_Database(const std::string& file); - ~sqlite3_database(); + ~Sqlite3_Database(); - size_t row_count(const std::string& table_name); + size_t row_count(const std::string& table_name) override; - void create_table(const std::string& table_schema); + void create_table(const std::string& table_schema) override; + + std::shared_ptr<Statement> new_statement(const std::string& sql) const override; private: - friend class sqlite3_statement; + class Sqlite3_Statement : public Statement + { + public: + void bind(int column, const std::string& val) override; + void bind(int column, size_t val) override; + void bind(int column, std::chrono::system_clock::time_point time) override; + void bind(int column, const std::vector<byte>& val) override; + + std::pair<const byte*, size_t> get_blob(int column) override; + size_t get_size_t(int column) override; + + void spin() override; + bool step() override; + + Sqlite3_Statement(sqlite3* db, const std::string& base_sql); + ~Sqlite3_Statement(); + private: + sqlite3_stmt* m_stmt; + }; sqlite3* m_db; }; -class sqlite3_statement - { - public: - sqlite3_statement(sqlite3_database* db, - const std::string& base_sql); - - void bind(int column, const std::string& val); - - void bind(int column, int val); - - void bind(int column, std::chrono::system_clock::time_point time); - - void bind(int column, const std::vector<byte>& val); - - std::pair<const byte*, size_t> get_blob(int column); - - size_t get_size_t(int column); - - void spin(); - - bool step(); - - ~sqlite3_statement(); - private: - sqlite3_stmt* m_stmt; - }; - } #endif |