SQL namespace. More...
Classes | |
| struct | BoundValue |
| Value bound to a parameter: value, or list of values. More... | |
| class | ClausesBuilder |
| SQL clauses builder. More... | |
| class | Connection |
| SQL connection virtual class. More... | |
| class | FieldsBuilder |
| Field builder. More... | |
| class | FieldsMapper |
Parameters of a described type: the common description of objects ( anch::Mapping<T> , anch-utils) registered for SQL. More... | |
| class | FieldsOf |
| Fields of an object, bound to the parameters of a query with the same names ( fieldsOf ). More... | |
| class | FromBuilder |
| class | MySQLConnection |
| MySQL connection. More... | |
| class | MySQLPreparedStatement |
| MySQL prepared statement implementation. More... | |
| class | MySQLPreparedStatementResultSet |
| MySQL result set implementation for prepared statement ... shitty API. More... | |
| class | MySQLResultSet |
| MySQL result set implementation. More... | |
| class | NamedQuery |
SQL query with named parameters ( :name ). More... | |
| struct | Parameter |
| Named parameter value ( Parameters item). More... | |
| class | Parameters |
Named parameters of a query ( :name ), bound by Connection. More... | |
| class | PostgreSQLConnection |
| PostgreSQL connection. More... | |
| class | PostgreSQLPreparedStatement |
| PostgreSQL prepared statement implementation. More... | |
| class | PostgreSQLResultSet |
| PostgreSQL result set implementation. More... | |
| class | PreparedStatement |
| SQL prepared statement. More... | |
| class | ResultSet |
| SQL result representation. More... | |
| class | RowMapper |
Result columns of a described type: the common description of objects ( anch::Mapping<T> , anch-utils) registered to read result rows. More... | |
| class | RowReader |
| Reader of the rows of a result set: columns are associated with fields once, when it is built. More... | |
| class | SelectBuilder |
| Dynamic SQL select request builder. More... | |
| class | SelectBuilderPart |
| SQL select query part builder. More... | |
| struct | SqlConnectionConfiguration |
| SQL database connection configuration. More... | |
| class | SqlConnectionFactory |
| SQL connection factory. More... | |
| class | SqlException |
| SQL exception. More... | |
| class | SQLite3Connection |
| SQLite3 connection. More... | |
| class | SQLite3PreparedStatement |
| SQLite3 prepared statement implementation. More... | |
| class | SQLite3ResultSet |
| SQLite3 result set implementation. More... | |
| class | SQLQuery |
| SQL query. More... | |
| class | SQLSharedLibraries |
| SQL shared libraries manager. More... | |
| struct | SQLSharedLibrary |
| SQL shared library data. More... | |
| struct | SqlSyntax |
| Lexical rules of an SQL dialect. More... | |
Concepts | |
| concept | Bindable |
| concept | BindableList |
| concept | BindableScalar |
| concept | Readable |
| concept | ReadableScalar |
| concept | Row |
| concept | SystemTimePoint |
Typedefs | |
| using | ClauseMaker = std::function<std::string(const std::string&, std::span<const std::string>)> |
| template<typename T> | |
| using | ValueChecker = std::function<std::optional<std::string>(const T&)> |
| using | ClausesProvider = std::function<const anch::sql::ClausesBuilder&()> |
| using | ParameterValue = std::optional<std::string> |
| using | ParameterList = std::vector<anch::sql::ParameterValue> |
| using | SqlConnectionPool = anch::ResourcePool<Connection, SqlConnectionConfiguration, make_shared_connection> |
Enumerations | |
| enum class | ParameterStyle { DOLLAR , NUMBERED , POSITIONAL } |
| Parameters style of a database driver ( NamedQuery::render ). More... | |
Functions | |
| std::string | notEquals (const std::string &column, std::span< const std::string > names) |
| std::string | equals (const std::string &column, std::span< const std::string > names) |
| std::string | greater (const std::string &column, std::span< const std::string > names) |
| std::string | greaterEquals (const std::string &column, std::span< const std::string > names) |
| std::string | lesser (const std::string &column, std::span< const std::string > names) |
| std::string | lesserEquals (const std::string &column, std::span< const std::string > names) |
| std::string | like (const std::string &column, std::span< const std::string > names) |
| std::string | notLike (const std::string &column, std::span< const std::string > names) |
| std::string | between (const std::string &column, std::span< const std::string > names) |
| std::string | notBetween (const std::string &column, std::span< const std::string > names) |
| std::string | in (const std::string &column, std::span< const std::string > names) |
| std::string | notIn (const std::string &column, std::span< const std::string > names) |
| ClausesBuilder | clauses () |
| template<anch::sql::Bindable T> | |
| std::optional< std::string > | isValidValue (const T &value) |
| template<> | |
| std::optional< std::string > | isValidValue< std::string > (const std::string &value) |
| SelectBuilder | select () |
| std::ostream & | operator<< (std::ostream &stream, const SelectBuilder &builder) |
| template<typename T> | |
| anch::sql::ClausesBuilder | clauses (anch::sql::ClauseMaker clause, T &value, anch::sql::ValueChecker< T > checker=anch::sql::isValidValue< T >) |
| template<typename T> | |
| anch::sql::ClausesBuilder | clauses (const std::string &column, anch::sql::ClauseMaker clause, T &value, anch::sql::ValueChecker< T > checker=anch::sql::isValidValue< T >) |
| template<anch::Described T> | |
| anch::sql::FieldsOf< T > | fieldsOf (const T &object) noexcept |
| anch::sql::ParameterValue | toParameter (int16_t value) |
| anch::sql::ParameterValue | toParameter (uint16_t value) |
| anch::sql::ParameterValue | toParameter (int32_t value) |
| anch::sql::ParameterValue | toParameter (uint32_t value) |
| anch::sql::ParameterValue | toParameter (int64_t value) |
| anch::sql::ParameterValue | toParameter (uint64_t value) |
| template<std::same_as< bool > B> | |
| anch::sql::ParameterValue | toParameter (B value) |
| anch::sql::ParameterValue | toParameter (double value) |
| anch::sql::ParameterValue | toParameter (const std::string &value) |
| anch::sql::ParameterValue | toParameter (const char *value) |
| anch::sql::ParameterValue | toParameter (const anch::date::Date &value) |
| anch::sql::ParameterValue | toParameter (const anch::date::Time &value) |
| anch::sql::ParameterValue | toParameter (const anch::date::DateTime &value) |
| anch::sql::ParameterValue | toParameter (const anch::UUID &value) |
| template<typename Duration> | |
| anch::sql::ParameterValue | toParameter (const std::chrono::sys_time< Duration > &value) |
| anch::sql::ParameterValue | toParameter (std::nullopt_t) |
| template<typename T> | |
| anch::sql::ParameterValue | toParameter (const std::optional< T > &value) |
| std::string | arrayLiteral (const anch::sql::ParameterList &elements) |
| template<anch::sql::Bindable T> | |
| anch::sql::BoundValue | toBound (const T &value) |
| template<> | |
| bool | ResultSet::get< std::string > (std::size_t idx, std::string &out) |
| template<> | |
| bool | ResultSet::get< anch::date::Date > (std::size_t idx, anch::date::Date &out) |
| template<> | |
| bool | ResultSet::get< anch::date::Time > (std::size_t idx, anch::date::Time &out) |
| template<> | |
| bool | ResultSet::get< anch::date::DateTime > (std::size_t idx, anch::date::DateTime &out) |
| template<> | |
| bool | ResultSet::get< anch::UUID > (std::size_t idx, anch::UUID &out) |
| template<> | |
| std::optional< std::string > | ResultSet::get< std::string > (std::size_t idx) |
| template<> | |
| std::optional< anch::date::Date > | ResultSet::get< anch::date::Date > (std::size_t idx) |
| template<> | |
| std::optional< anch::date::Time > | ResultSet::get< anch::date::Time > (std::size_t idx) |
| template<> | |
| std::optional< anch::date::DateTime > | ResultSet::get< anch::date::DateTime > (std::size_t idx) |
| template<> | |
| std::optional< anch::UUID > | ResultSet::get< anch::UUID > (std::size_t idx) |
| template<anch::sql::Row T> | |
| void | readRow (ResultSet &result, T &row) |
| template<anch::sql::Row T> | |
| T | rowAs (ResultSet &result) |
| std::shared_ptr< Connection > | make_shared_connection (const SqlConnectionConfiguration &config) |
Variables | |
| constexpr std::size_t | DEFAULT_STATEMENT_CACHE_SIZE = 256 |
SQL namespace.
Provides abstraction layer for several SQL clients.
Supported SQL database are (for now):
| using anch::sql::ClauseMaker = std::function<std::string(const std::string&, std::span<const std::string>)> |
Clause maker function ( equals , between , ...).
The first parameter is the column (and the first operand), the second one the names of the clause parameters (generated from the column by ClausesBuilder : one name for each value). It returns the clause.
| using anch::sql::ClausesProvider = std::function<const anch::sql::ClausesBuilder&()> |
Clauses provider
| using anch::sql::ParameterList = std::vector<anch::sql::ParameterValue> |
Values of a list parameter
| using anch::sql::ParameterValue = std::optional<std::string> |
Parameter value bound to a prepared statement: values are sent as text, std::nullopt is SQL NULL
| using anch::sql::SqlConnectionPool = anch::ResourcePool<Connection, SqlConnectionConfiguration, make_shared_connection> |
SQL connections pool definition
| using anch::sql::ValueChecker = std::function<std::optional<std::string>(const T&)> |
Check if value is valid to add a clause
|
strong |
Parameters style of a database driver ( NamedQuery::render ).
| std::string anch::sql::arrayLiteral | ( | const anch::sql::ParameterList & | elements | ) |
PostgreSQL array literal of a list ( {"1","2",NULL} : elements are quoted, '\' and '"' are escaped)
| elements | the list values |
| std::string anch::sql::between | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'between' clause with BETWEEN operator: column BETWEEN :min AND :max
| column | the column |
| names | the parameters names (lower and upper bounds, generated by ClausesBuilder from the column) |
|
extern |
Initialize a new ClausesBuilder
| anch::sql::ClausesBuilder anch::sql::clauses | ( | anch::sql::ClauseMaker | clause, |
| T & | value, | ||
| anch::sql::ValueChecker< T > | checker = anch::sql::isValidValue<T> ) |
Initialize a new ClausesBuilder
| anch::sql::ClausesBuilder anch::sql::clauses | ( | const std::string & | column, |
| anch::sql::ClauseMaker | clause, | ||
| T & | value, | ||
| anch::sql::ValueChecker< T > | checker = anch::sql::isValidValue<T> ) |
Initialize a new ClausesBuilder
| std::string anch::sql::equals | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'equals' clause with = operator: column = :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
|
noexcept |
Fields of an object as query parameters: each parameter of the query is bound to the field of the same name ( FieldsMapper ), the other fields are ignored ; a parameter which is not a field is not bound (error before execution):
| T | the described type |
| object | the object (it has to live while the fields are bound) |
| std::string anch::sql::greater | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'greater' clause with > operator: column > :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::string anch::sql::greaterEquals | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'greater or equals' clause with >= operator: column >= :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::string anch::sql::in | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'in' clause with IN operator: column IN (:name)
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::optional< std::string > anch::sql::isValidValue | ( | const T & | value | ) |
Default value checker: the clause is added when the value is set (an empty std::optional or list skips the clause)
| value | the value to check |
std::nullopt to skip the clause | std::optional< std::string > anch::sql::isValidValue< std::string > | ( | const std::string & | value | ) |
Default value checker of strings: an empty string skips the clause
| value | the value to check |
std::nullopt to skip the clause | std::string anch::sql::lesser | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'lesser' clause with < operator: column < :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::string anch::sql::lesserEquals | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'lesser or equals' clause with <= operator: column <= :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::string anch::sql::like | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'like' clause with LIKE operator: column LIKE :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
|
extern |
Create a new shared pointer on SQL connection.
| config | the SQL database configuration |
| SqlException | any error |
| std::string anch::sql::notBetween | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'not between' clause with NOT BETWEEN operator: column NOT BETWEEN :min AND :max
| column | the column |
| names | the parameters names (lower and upper bounds, generated by ClausesBuilder from the column) |
| std::string anch::sql::notEquals | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'not equals' clause with <> operator: column <> :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::string anch::sql::notIn | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'not in' clause with NOT IN operator: column NOT IN (:name)
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::string anch::sql::notLike | ( | const std::string & | column, |
| std::span< const std::string > | names ) |
Provides 'not like' clause with NOT LIKE operator: column NOT LIKE :name
| column | the column |
| names | the parameter name (generated by ClausesBuilder from the column) |
| std::ostream & anch::sql::operator<< | ( | std::ostream & | stream, |
| const SelectBuilder & | builder ) |
SelectBuilder stream insertion operator (declared at namespace level to be exported)
| stream | the output stream |
| builder | the SelectBuilder |
| void anch::sql::readRow | ( | ResultSet & | result, |
| T & | row ) |
Read current row of a result set in an object (or value): columns are associated with fields by name (see RowMapper ). Use a RowReader to read several rows.
| T | the row type |
| result | the result set (on the row to read) |
| row | the row to fill |
| SqlException | invalid value, NULL value of a field which is not optional (non fatal), database error |
| std::optional< anch::date::Date > anch::sql::ResultSet::get< anch::date::Date > | ( | std::size_t | idx | ) |
Get field value by index as calendar day ( YYYY-MM-DD ).
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or invalid date (non fatal), database error |
| bool anch::sql::ResultSet::get< anch::date::Date > | ( | std::size_t | idx, |
| anch::date::Date & | out ) |
Get field value by index as calendar day ( YYYY-MM-DD ).
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or invalid date (non fatal), database error |
| std::optional< anch::date::DateTime > anch::sql::ResultSet::get< anch::date::DateTime > | ( | std::size_t | idx | ) |
Get field value by index as point in time ( YYYY-MM-DD HH:MM:SS.mmm , local time).
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or invalid timestamp (non fatal), database error |
| bool anch::sql::ResultSet::get< anch::date::DateTime > | ( | std::size_t | idx, |
| anch::date::DateTime & | out ) |
Get field value by index as point in time ( YYYY-MM-DD HH:MM:SS.mmm , local time).
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or invalid timestamp (non fatal), database error |
| std::optional< anch::date::Time > anch::sql::ResultSet::get< anch::date::Time > | ( | std::size_t | idx | ) |
Get field value by index as time of day ( HH:MM:SS[.fraction] ).
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or invalid time (non fatal), database error |
| bool anch::sql::ResultSet::get< anch::date::Time > | ( | std::size_t | idx, |
| anch::date::Time & | out ) |
Get field value by index as time of day ( HH:MM:SS[.fraction] ).
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or invalid time (non fatal), database error |
| std::optional< anch::UUID > anch::sql::ResultSet::get< anch::UUID > | ( | std::size_t | idx | ) |
Get field value by index as UUID (canonical form).
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or invalid UUID (non fatal), database error |
| bool anch::sql::ResultSet::get< anch::UUID > | ( | std::size_t | idx, |
| anch::UUID & | out ) |
Get field value by index as UUID (canonical form).
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or invalid UUID (non fatal), database error |
| std::optional< std::string > anch::sql::ResultSet::get< std::string > | ( | std::size_t | idx | ) |
Get field value by index as character string.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range (non fatal), database error |
| bool anch::sql::ResultSet::get< std::string > | ( | std::size_t | idx, |
| std::string & | out ) |
Get field value by index as character string.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range (non fatal), database error |
| T anch::sql::rowAs | ( | ResultSet & | result | ) |
Read current row of a result set as an object (or value) ( readRow )
| T | the row type |
| result | the result set (on the row to read) |
| SqlException | invalid value, NULL value of a field which is not optional (non fatal), database error |
|
extern |
Initialize a new SelectBuilder
| anch::sql::BoundValue anch::sql::toBound | ( | const T & | value | ) |
Convert value or list of values to bound value
| T | the value type |
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | B | value | ) |
Convert boolean to parameter value ( 1 / 0 : PostgreSQL boolean , MySQL BOOLEAN ( TINYINT ), SQLite integers). Only bool values are converted (pointers and other types are not booleans).
| B | bool |
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const anch::date::Date & | value | ) |
Convert date to parameter value ( YYYY-MM-DD )
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const anch::date::DateTime & | value | ) |
Convert point in time to parameter value ( YYYY-MM-DD HH:MM:SS.mmm , local time)
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const anch::date::Time & | value | ) |
Convert time of day to parameter value ( HH:MM:SS[.fraction] , RFC 3339 partial-time )
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const anch::UUID & | value | ) |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const char * | value | ) |
Convert character array to parameter value
| value | the value ( NULL pointer is SQL NULL ) |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const std::chrono::sys_time< Duration > & | value | ) |
Convert std::chrono::system_clock point in time ( std::chrono::sys_seconds , std::chrono::sys_days , ...) to parameter value: same format and time zone as anch::date::DateTime ( YYYY-MM-DD HH:MM:SS.mmm , local time ; sys_days is a point in time at midnight UTC, anch::date::Date is a calendar day). Points in time of other clocks are not bound ( std::chrono::clock_cast them).
| Duration | the duration type of the point in time |
| value | the value (between years 1678 and 2262: anch::date::DateTime range) |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const std::optional< T > & | value | ) |
Convert optional value to parameter value ( std::nullopt is SQL NULL )
| T | the value type |
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | const std::string & | value | ) |
Convert string to parameter value
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | double | value | ) |
Convert floating point number to parameter value (shortest representation which reads back the same value ; float values are converted as double )
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | int16_t | value | ) |
Convert 16 bits signed integer to parameter value
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | int32_t | value | ) |
Convert 32 bits signed integer to parameter value
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | int64_t | value | ) |
Convert 64 bits signed integer to parameter value
| value | the value |
|
inline |
SQL NULL parameter value
std::nullopt | anch::sql::ParameterValue anch::sql::toParameter | ( | uint16_t | value | ) |
Convert 16 bits unsigned integer to parameter value
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | uint32_t | value | ) |
Convert 32 bits unsigned integer to parameter value
| value | the value |
| anch::sql::ParameterValue anch::sql::toParameter | ( | uint64_t | value | ) |
Convert 64 bits unsigned integer to parameter value
| value | the value |
|
inlineconstexpr |
Default maximum number of prepared statements cached by a connection (see Connection::prepareStatement )