• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 13215274653

08 Feb 2025 11:38AM UTC coverage: 91.655% (-0.009%) from 91.664%
13215274653

Pull #4650

github

web-flow
Merge 107f31833 into bc555cd3c
Pull Request #4650: Reorganize code and reduce header dependencies

94836 of 103471 relevant lines covered (91.65%)

11230958.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/src/lib/utils/database.h
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 <memory>
15
#include <string>
16
#include <vector>
17

18
namespace Botan {
19

20
class BOTAN_PUBLIC_API(2, 0) SQL_Database {
34✔
21
   public:
22
      class BOTAN_PUBLIC_API(2, 0) SQL_DB_Error final : public Exception {
23
         public:
24
            explicit SQL_DB_Error(std::string_view what) : Exception("SQL database", what), m_rc(0) {}
×
25

26
            SQL_DB_Error(std::string_view what, int rc) : Exception("SQL database", what), m_rc(rc) {}
22✔
27

28
            ErrorType error_type() const noexcept override { return ErrorType::DatabaseError; }
×
29

30
            int error_code() const noexcept override { return m_rc; }
×
31

32
         private:
33
            int m_rc;
34
      };
35

36
      class BOTAN_PUBLIC_API(2, 0) Statement {
824✔
37
         public:
38
            /* Bind statement parameters */
39
            virtual void bind(int column, std::string_view str) = 0;
40

41
            virtual void bind(int column, size_t i) = 0;
42

43
            virtual void bind(int column, std::chrono::system_clock::time_point time) = 0;
44

45
            virtual void bind(int column, const std::vector<uint8_t>& blob) = 0;
46

47
            virtual void bind(int column, const uint8_t* data, size_t len) = 0;
48

49
            /* Get output */
50
            virtual std::pair<const uint8_t*, size_t> get_blob(int column) = 0;
51

52
            virtual std::string get_str(int column) = 0;
53

54
            virtual size_t get_size_t(int column) = 0;
55

56
            /* Run to completion */
57
            virtual size_t spin() = 0;
58

59
            /* Maybe update */
60
            virtual bool step() = 0;
61

62
            virtual ~Statement() = default;
802✔
63
      };
64

65
      /*
66
      * Create a new statement for execution.
67
      * Use ?1, ?2, ?3, etc for parameters to set later with bind
68
      */
69
      virtual std::shared_ptr<Statement> new_statement(std::string_view base_sql) const = 0;
70

71
      virtual size_t row_count(std::string_view table_name) = 0;
72

73
      virtual void create_table(std::string_view table_schema) = 0;
74

75
      virtual size_t rows_changed_by_last_statement() = 0;
76

77
      virtual size_t exec(std::string_view sql) { return new_statement(sql)->spin(); }
114✔
78

79
      virtual bool is_threadsafe() const { return false; }
×
80

81
      virtual ~SQL_Database() = default;
34✔
82
};
83

84
}  // namespace Botan
85

86
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc