AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
placeholders.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-sql-export.hpp"
23
24#include <cstddef>
25#include <optional>
26#include <span>
27#include <string>
28#include <string_view>
29#include <vector>
30
31namespace anch::sql {
32
42 struct ANCH_SQL_EXPORT SqlSyntax {
43
45 bool backslashEscape = false;
46
48 bool doubleQuoteString = false;
49
51 bool backquoteIdentifier = false;
52
54 bool bracketIdentifier = false;
55
57 bool escapeString = false;
58
60 bool dollarQuote = false;
61
63 bool nestedComment = false;
64
66 bool hashComment = false;
67
70
73
75 bool arraySlice = false;
76
78 bool dollarParameters = false;
79
81 bool prefixedParameters = false;
82
84 static const SqlSyntax STANDARD;
85
87 static const SqlSyntax POSTGRESQL;
88
90 static const SqlSyntax MYSQL;
91
93 static const SqlSyntax SQLITE;
94
95 };
96
110
130 class ANCH_SQL_EXPORT NamedQuery {
131
132 public:
134 static constexpr std::size_t SCALAR = static_cast<std::size_t>(-1);
135
139 struct Binding {
141 std::size_t slot;
142
144 std::size_t element;
145
147 bool operator==(const Binding&) const = default;
148 };
149
153 struct Rendered {
155 std::string query;
156
158 std::vector<Binding> bindings;
159 };
160
161 private:
163 struct Occurrence {
165 std::size_t begin;
166
168 std::size_t end;
169
171 std::size_t slot;
172
174 bool in;
175
177 bool negated;
178
180 std::size_t inBegin;
181
183 std::size_t open;
184
186 std::size_t close;
187 };
188
189 // Attributes +
191 std::string _query;
192
194 std::vector<std::string> _names;
195
197 std::vector<Occurrence> _occurrences;
198 // Attributes -
199
200 // Constructors +
201 public:
210 NamedQuery(std::string_view query, const anch::sql::SqlSyntax& syntax);
211 // Constructors -
212
213 // Methods +
214 public:
220 const std::string& query() const noexcept;
221
227 const std::vector<std::string>& names() const noexcept;
228
236 std::optional<std::size_t> slot(std::string_view name) const noexcept;
237
250 Rendered render(anch::sql::ParameterStyle style, std::span<const std::size_t> sizes = {}) const;
251
261 std::string rename(std::span<const std::string> names) const;
262 // Methods -
263
264 };
265
266} // anch::sql
Rendered render(anch::sql::ParameterStyle style, std::span< const std::size_t > sizes={}) const
const std::string & query() const noexcept
std::string rename(std::span< const std::string > names) const
static constexpr std::size_t SCALAR
Definition placeholders.hpp:134
const std::vector< std::string > & names() const noexcept
std::optional< std::size_t > slot(std::string_view name) const noexcept
NamedQuery(std::string_view query, const anch::sql::SqlSyntax &syntax)
SQL namespace.
Definition clauses.hpp:28
std::string in(const std::string &column, std::span< const std::string > names)
ParameterStyle
Parameters style of a database driver ( NamedQuery::render ).
Definition placeholders.hpp:102
@ POSITIONAL
Definition placeholders.hpp:108
@ NUMBERED
Definition placeholders.hpp:106
@ DOLLAR
Definition placeholders.hpp:104
AnCH framework base namespace.
Definition app.hpp:30
Value bound to a parameter of the rendered query.
Definition placeholders.hpp:139
std::size_t element
Definition placeholders.hpp:144
bool operator==(const Binding &) const =default
std::size_t slot
Definition placeholders.hpp:141
Query rendered for a driver.
Definition placeholders.hpp:153
std::vector< Binding > bindings
Definition placeholders.hpp:158
std::string query
Definition placeholders.hpp:155
Lexical rules of an SQL dialect.
Definition placeholders.hpp:42
bool backquoteIdentifier
Definition placeholders.hpp:51
static const SqlSyntax MYSQL
Definition placeholders.hpp:90
bool dollarParameters
Definition placeholders.hpp:78
static const SqlSyntax SQLITE
Definition placeholders.hpp:93
bool dashCommentNeedsSpace
Definition placeholders.hpp:69
bool prefixedParameters
Definition placeholders.hpp:81
bool bracketIdentifier
Definition placeholders.hpp:54
bool dollarQuote
Definition placeholders.hpp:60
bool arraySlice
Definition placeholders.hpp:75
bool escapeString
Definition placeholders.hpp:57
bool questionMarkOperator
Definition placeholders.hpp:72
bool backslashEscape
Definition placeholders.hpp:45
bool hashComment
Definition placeholders.hpp:66
bool nestedComment
Definition placeholders.hpp:63
bool doubleQuoteString
Definition placeholders.hpp:48
static const SqlSyntax STANDARD
Definition placeholders.hpp:84
static const SqlSyntax POSTGRESQL
Definition placeholders.hpp:87