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/database.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/database.h')
-rw-r--r-- | src/lib/utils/database.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/utils/database.h b/src/lib/utils/database.h new file mode 100644 index 000000000..742c52c7c --- /dev/null +++ b/src/lib/utils/database.h @@ -0,0 +1,62 @@ +/* +* SQL database interface +* (C) 2014 Jack Lloyd +* +* Released under the terms of the Botan license +*/ + +#ifndef BOTAN_SQL_DATABASE_H__ +#define BOTAN_SQL_DATABASE_H__ + +#include <botan/types.h> +#include <string> +#include <chrono> +#include <vector> + +namespace Botan { + +class BOTAN_DLL SQL_Database + { + public: + class BOTAN_DLL Statement + { + public: + /* Bind statement parameters */ + virtual void bind(int column, const std::string& str) = 0; + + virtual void bind(int column, size_t i) = 0; + + virtual void bind(int column, std::chrono::system_clock::time_point time) = 0; + + virtual void bind(int column, const std::vector<byte>& blob) = 0; + + /* Get output */ + virtual std::pair<const byte*, size_t> get_blob(int column) = 0; + + virtual size_t get_size_t(int column) = 0; + + /* Run to completion */ + virtual void spin() = 0; + + /* Maybe update */ + virtual bool step() = 0; + + virtual ~Statement() {} + }; + + /* + * Create a new statement for execution. + * Use ?1, ?2, ?3, etc for parameters to set later with bind + */ + virtual std::shared_ptr<Statement> new_statement(const std::string& base_sql) const = 0; + + virtual size_t row_count(const std::string& table_name) = 0; + + virtual void create_table(const std::string& table_schema) = 0; + + virtual ~SQL_Database() {} +}; + +} + +#endif |