Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

database.h
Go to the documentation of this file.
1 /*
2 * SQL database interface
3 * (C) 2014 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_SQL_DATABASE_H_
9 #define BOTAN_SQL_DATABASE_H_
10
11 #include <botan/types.h>
12 #include <botan/exceptn.h>
13 #include <string>
14 #include <chrono>
15 #include <vector>
16
17 namespace Botan {
18
19 class BOTAN_PUBLIC_API(2,0) SQL_Database
20 {
21 public:
22
23 class BOTAN_PUBLIC_API(2,0) SQL_DB_Error final : public Exception
24 {
25 public:
26 explicit SQL_DB_Error(const std::string& what) :
27 Exception("SQL database", what),
28 m_rc(0)
29 {}
30
31 SQL_DB_Error(const std::string& what, int rc) :
32 Exception("SQL database", what),
33 m_rc(rc)
34 {}
35
36 ErrorType error_type() const noexcept override { return Botan::ErrorType::DatabaseError; }
37
38 int error_code() const noexcept override { return m_rc; }
39 private:
40 int m_rc;
41 };
42
43 class BOTAN_PUBLIC_API(2,0) Statement
44 {
45 public:
46 /* Bind statement parameters */
47 virtual void bind(int column, const std::string& str) = 0;
48
49 virtual void bind(int column, size_t i) = 0;
50
51 virtual void bind(int column, std::chrono::system_clock::time_point time) = 0;
52
53 virtual void bind(int column, const std::vector<uint8_t>& blob) = 0;
54
55 virtual void bind(int column, const uint8_t* data, size_t len) = 0;
56
57 /* Get output */
58 virtual std::pair<const uint8_t*, size_t> get_blob(int column) = 0;
59
60 virtual std::string get_str(int column) = 0;
61
62 virtual size_t get_size_t(int column) = 0;
63
64 /* Run to completion */
65 virtual size_t spin() = 0;
66
67 /* Maybe update */
68 virtual bool step() = 0;
69
70 virtual ~Statement() = default;
71 };
72
73 /*
74 * Create a new statement for execution.
75 * Use ?1, ?2, ?3, etc for parameters to set later with bind
76 */
77 virtual std::shared_ptr<Statement> new_statement(const std::string& base_sql) const = 0;
78
79 virtual size_t row_count(const std::string& table_name) = 0;
80
81 virtual void create_table(const std::string& table_schema) = 0;
82
83 virtual ~SQL_Database() = default;
84 };
85
86 }
87
88 #endif
Botan::Exception
Definition: exceptn.h:85
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::SQL_Database::Statement
Definition: database.h:43
Botan::SQL_Database::SQL_DB_Error::error_code
int error_code() const noexceptoverride
Definition: database.h:38
Botan::SQL_Database::SQL_DB_Error
Definition: database.h:23
Botan::SQL_Database::SQL_DB_Error::SQL_DB_Error
SQL_DB_Error(const std::string &what)
Definition: database.h:26
Botan::ErrorType
ErrorType
Definition: exceptn.h:20
Botan
Definition: alg_id.cpp:13
Botan::ErrorType::DatabaseError
Botan::SQL_Database
Definition: database.h:19
Botan::SQL_Database::SQL_DB_Error::error_type
ErrorType error_type() const noexceptoverride
Definition: database.h:36
Botan::SQL_Database::SQL_DB_Error::SQL_DB_Error
SQL_DB_Error(const std::string &what, int rc)
Definition: database.h:31