Botan 3.13.0
Crypto and TLS for C&
database.cpp
Go to the documentation of this file.
1/*
2* (C) 2026 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/database.h>
8
9#include <botan/internal/charset.h>
10#include <string>
11
12namespace Botan {
13
14bool SQL_Database::is_valid_table_name(std::string_view table) const {
15 if(table.empty()) {
16 return false;
17 }
18
19 constexpr auto valid_table_name_char = CharacterValidityTable::alpha_numeric_plus("_");
20 for(const char c : table) {
21 if(!valid_table_name_char(c)) {
22 return false;
23 }
24 }
25 return true;
26}
27
28std::shared_ptr<SQL_Database::Statement> SQL_Database::select(std::string_view columns,
29 std::string_view table,
30 std::string_view where,
31 std::optional<size_t> limit) const {
32 std::string sql = "SELECT ";
33 sql += columns;
34 sql += " FROM ";
35 sql += table;
36 if(!where.empty()) {
37 sql += " WHERE ";
38 sql += where;
39 }
40 if(limit.has_value()) {
41 sql += " LIMIT ";
42 sql += std::to_string(*limit);
43 }
44 return new_statement(sql);
45}
46
47} // namespace Botan
static constexpr CharacterValidityTable alpha_numeric_plus(std::string_view extras)
Definition charset.h:114
virtual std::shared_ptr< Statement > new_statement(std::string_view base_sql) const =0
virtual bool is_valid_table_name(std::string_view table) const
Definition database.cpp:14
virtual std::shared_ptr< Statement > select(std::string_view columns, std::string_view table, std::string_view where={}, std::optional< size_t > limit=std::nullopt) const
Definition database.cpp:28