Botan 3.6.1
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/exceptn.h>
12#include <botan/types.h>
13#include <chrono>
14#include <string>
15#include <vector>
16
17namespace Botan {
18
20 public:
22 public:
23 explicit SQL_DB_Error(std::string_view what) : Exception("SQL database", what), m_rc(0) {}
24
25 SQL_DB_Error(std::string_view what, int rc) : Exception("SQL database", what), m_rc(rc) {}
26
27 ErrorType error_type() const noexcept override { return ErrorType::DatabaseError; }
28
29 int error_code() const noexcept override { return m_rc; }
30
31 private:
32 int m_rc;
33 };
34
36 public:
37 /* Bind statement parameters */
38 virtual void bind(int column, std::string_view str) = 0;
39
40 virtual void bind(int column, size_t i) = 0;
41
42 virtual void bind(int column, std::chrono::system_clock::time_point time) = 0;
43
44 virtual void bind(int column, const std::vector<uint8_t>& blob) = 0;
45
46 virtual void bind(int column, const uint8_t* data, size_t len) = 0;
47
48 /* Get output */
49 virtual std::pair<const uint8_t*, size_t> get_blob(int column) = 0;
50
51 virtual std::string get_str(int column) = 0;
52
53 virtual size_t get_size_t(int column) = 0;
54
55 /* Run to completion */
56 virtual size_t spin() = 0;
57
58 /* Maybe update */
59 virtual bool step() = 0;
60
61 virtual ~Statement() = default;
62 };
63
64 /*
65 * Create a new statement for execution.
66 * Use ?1, ?2, ?3, etc for parameters to set later with bind
67 */
68 virtual std::shared_ptr<Statement> new_statement(std::string_view base_sql) const = 0;
69
70 virtual size_t row_count(std::string_view table_name) = 0;
71
72 virtual void create_table(std::string_view table_schema) = 0;
73
74 virtual size_t rows_changed_by_last_statement() = 0;
75
76 virtual size_t exec(std::string_view sql) { return new_statement(sql)->spin(); }
77
78 virtual bool is_threadsafe() const { return false; }
79
80 virtual ~SQL_Database() = default;
81};
82
83} // namespace Botan
84
85#endif
SQL_DB_Error(std::string_view what, int rc)
Definition database.h:25
ErrorType error_type() const noexcept override
Definition database.h:27
int error_code() const noexcept override
Definition database.h:29
SQL_DB_Error(std::string_view what)
Definition database.h:23
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:78
virtual size_t exec(std::string_view sql)
Definition database.h:76
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
ErrorType
Definition exceptn.h:20