Botan 3.0.0
Crypto and TLS for C&
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
17namespace Botan {
18
20 {
21 public:
22
24 {
25 public:
26 explicit SQL_DB_Error(std::string_view what) :
27 Exception("SQL database", what),
28 m_rc(0)
29 {}
30
31 SQL_DB_Error(std::string_view what, int rc) :
32 Exception("SQL database", what),
33 m_rc(rc)
34 {}
35
36 ErrorType error_type() const noexcept override { return ErrorType::DatabaseError; }
37
38 int error_code() const noexcept override { return m_rc; }
39 private:
40 int m_rc;
41 };
42
44 {
45 public:
46 /* Bind statement parameters */
47 virtual void bind(int column, std::string_view 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(std::string_view base_sql) const = 0;
78
79 virtual size_t row_count(std::string_view table_name) = 0;
80
81 virtual void create_table(std::string_view table_schema) = 0;
82
83 virtual size_t rows_changed_by_last_statement() = 0;
84
85 virtual size_t exec(std::string_view sql) { return new_statement(sql)->spin(); }
86
87 virtual bool is_threadsafe() const { return false; }
88
89 virtual ~SQL_Database() = default;
90};
91
92}
93
94#endif
SQL_DB_Error(std::string_view what, int rc)
Definition: database.h:31
ErrorType error_type() const noexcept override
Definition: database.h:36
int error_code() const noexcept override
Definition: database.h:38
SQL_DB_Error(std::string_view what)
Definition: database.h:26
virtual ~Statement()=default
virtual std::pair< const uint8_t *, size_t > get_blob(int column)=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 uint8_t *data, size_t len)=0
virtual void bind(int column, const std::vector< uint8_t > &blob)=0
virtual void bind(int column, std::string_view str)=0
virtual std::string get_str(int column)=0
virtual size_t get_size_t(int column)=0
virtual std::shared_ptr< Statement > new_statement(std::string_view base_sql) const =0
virtual bool is_threadsafe() const
Definition: database.h:87
virtual size_t exec(std::string_view sql)
Definition: database.h:85
virtual size_t rows_changed_by_last_statement()=0
virtual void create_table(std::string_view table_schema)=0
virtual size_t row_count(std::string_view table_name)=0
virtual ~SQL_Database()=default
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
ErrorType
Definition: exceptn.h:20