Botan  2.1.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 
19 class BOTAN_DLL SQL_Database
20  {
21  public:
22 
23  class BOTAN_DLL SQL_DB_Error : public Exception
24  {
25  public:
26  explicit SQL_DB_Error(const std::string& what) : Exception("SQL database", what) {}
27  };
28 
29  class BOTAN_DLL Statement
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 size_t get_size_t(int column) = 0;
47 
48  /* Run to completion */
49  virtual size_t spin() = 0;
50 
51  /* Maybe update */
52  virtual bool step() = 0;
53 
54  virtual ~Statement() {}
55  };
56 
57  /*
58  * Create a new statement for execution.
59  * Use ?1, ?2, ?3, etc for parameters to set later with bind
60  */
61  virtual std::shared_ptr<Statement> new_statement(const std::string& base_sql) const = 0;
62 
63  virtual size_t row_count(const std::string& table_name) = 0;
64 
65  virtual void create_table(const std::string& table_schema) = 0;
66 
67  virtual ~SQL_Database() {}
68 };
69 
70 }
71 
72 #endif
virtual ~SQL_Database()
Definition: database.h:67
SQL_DB_Error(const std::string &what)
Definition: database.h:26
Definition: alg_id.cpp:13