Botan  2.6.0
Crypto and TLS for C++11
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 
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) : Exception("SQL database", what) {}
27  };
28 
30  {
31  public:
32  /* Bind statement parameters */
33  virtual void bind(int column, const std::string& str) = 0;
34 
35  virtual void bind(int column, size_t i) = 0;
36 
37  virtual void bind(int column, std::chrono::system_clock::time_point time) = 0;
38 
39  virtual void bind(int column, const std::vector<uint8_t>& blob) = 0;
40 
41  virtual void bind(int column, const uint8_t* data, size_t len) = 0;
42 
43  /* Get output */
44  virtual std::pair<const uint8_t*, size_t> get_blob(int column) = 0;
45 
46  virtual std::string get_str(int column) = 0;
47 
48  virtual size_t get_size_t(int column) = 0;
49 
50  /* Run to completion */
51  virtual size_t spin() = 0;
52 
53  /* Maybe update */
54  virtual bool step() = 0;
55 
56  virtual ~Statement() = default;
57  };
58 
59  /*
60  * Create a new statement for execution.
61  * Use ?1, ?2, ?3, etc for parameters to set later with bind
62  */
63  virtual std::shared_ptr<Statement> new_statement(const std::string& base_sql) const = 0;
64 
65  virtual size_t row_count(const std::string& table_name) = 0;
66 
67  virtual void create_table(const std::string& table_schema) = 0;
68 
69  virtual ~SQL_Database() = default;
70 };
71 
72 }
73 
74 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
SQL_DB_Error(const std::string &what)
Definition: database.h:26
Definition: alg_id.cpp:13