31 #ifndef DATA_DATA_HPP_ 32 #define DATA_DATA_HPP_ 144 _overflow{_if_too_large::_error};
198 explicit Value(
const std::string& value) : _s(value),
_isnull(false) {}
440 constexpr std::array boolTypes{
"bool",
"boolean"};
441 constexpr std::array int32Types{
"bit",
"tinyint",
"smallint",
"mediumint",
"int",
"integer"};
442 constexpr std::array int64Types{
"bigint"};
443 constexpr std::array doubleTypes{
"float",
"double",
"double precision",
"decimal",
"dec"};
444 constexpr std::array stringTypes{
466 return std::tolower(c);
471 const auto bracketPos{sqlType.find_first_of(
'(')};
473 if(bracketPos != std::string::npos) {
474 const auto bracketEnd{sqlType.find_first_of(
')', bracketPos + 1)};
476 if(bracketEnd != std::string::npos) {
477 sqlType = sqlType.substr(0, bracketPos) + sqlType.substr(bracketEnd + 1);
482 for(
const auto& type : boolTypes) {
483 const std::string typeString{type};
485 if(sqlType.substr(0, typeString.length()) == typeString) {
490 for(
const auto& type : int32Types) {
491 const std::string typeString{type};
492 const auto unsignedType{typeString +
" unsigned"};
494 if(sqlType.substr(0, unsignedType.length()) == unsignedType) {
498 if(sqlType.substr(0, typeString.length()) == typeString) {
503 for(
const auto& type : int64Types) {
504 const std::string typeString{type};
505 const auto unsignedType{typeString +
" unsigned"};
507 if(sqlType.substr(0, unsignedType.length()) == unsignedType) {
511 if(sqlType.substr(0, typeString.length()) == typeString) {
516 for(
const auto& type : doubleTypes) {
517 const std::string typeString{type};
519 if(sqlType.substr(0, typeString.length()) == typeString) {
524 for(
const auto& type : stringTypes) {
525 const std::string typeString{type};
527 if(sqlType.substr(0, typeString.length()) == typeString) {
558 return getTypeOfSizeT<sizeof(std::size_t)>();
std::vector< std::string > order
Optional order to be applied to the SQL query retrieving the values of the columns.
Definition: Data.hpp:303
32-bit integer.
Definition: Data.hpp:74
std::vector< std::string > columns
Vector containing the names of the columns to be retrieved.
Definition: Data.hpp:230
std::vector< std::tuple< std::string, Type, Value > > columns_types_values
Vector containing the names of the columns to be updated, their data types and the new values to be s...
Definition: Data.hpp:416
std::uint32_t _ui32
Unsigned 32-bit integer value.
Definition: Data.hpp:106
Type parseSQLType(std::string sqlType)
Parses the given SQL data type.
Definition: Data.hpp:438
std::string condition
The condition to be added to the SQL query updating the value.
Definition: Data.hpp:419
Use a null value instead.
Definition: Data.hpp:136
std::vector< std::tuple< std::string, Type, Value > > columns_types_values
Vector containing the names of the columns, their data types and the values to be inserted into them...
Definition: Data.hpp:365
Unknown data type.
Definition: Data.hpp:68
String.
Definition: Data.hpp:89
Type getTypeOfSizeT< bytes32bit >()
Identifies std::size_t as a 32-bit integer.
Definition: Data.hpp:547
std::string table
The name of the table.
Definition: Data.hpp:227
std::vector< std::string > columns
Vector containing the names of the columns.
Definition: Data.hpp:289
Boolean value.
Definition: Data.hpp:71
std::string condition
Condition to be added to the SQL query retrieving the values.
Definition: Data.hpp:251
std::vector< std::pair< std::string, Value > > columns_values
Vector containing the names of the columns to be updated and the new values to be set...
Definition: Data.hpp:398
Value(double value)
Constructor initializing a floating point value (with double precision).
Definition: Data.hpp:190
std::vector< std::pair< std::string, Value > > columns_values
Vector containing the names of the columns and the values to be inserted into them.
Definition: Data.hpp:353
Value value
The new value to be set.
Definition: Data.hpp:383
std::string table
The name of the table.
Definition: Data.hpp:362
Value(std::int32_t value)
Constructor initializing a 32-bit integer.
Definition: Data.hpp:162
Structure for retrieving multiple table columns of different types.
Definition: Data.hpp:310
std::string table
The name of the table.
Definition: Data.hpp:260
std::int64_t _i64
64-bit integer value.
Definition: Data.hpp:109
std::string column
The name of the column.
Definition: Data.hpp:212
std::vector< std::pair< std::string, Type > > columns_types
Vector containing the names and data types of the columns to be retrieved.
Definition: Data.hpp:315
std::string condition
Condition to be added to the SQL query retrieving the values.
Definition: Data.hpp:236
std::string condition
Optional condition to be added to the SQL query retrieving the values of the columns.
Definition: Data.hpp:318
std::string table
The name of the table.
Definition: Data.hpp:371
std::string condition
Optional condition to be added to the SQL query retrieving the values of the columns.
Definition: Data.hpp:295
std::string condition
The condition to be added to the SQL query updating the value.
Definition: Data.hpp:386
Unsigned 32-bit integer.
Definition: Data.hpp:77
void clear()
Clears the current value and re-initializes it as null value.
Definition: Data.hpp:201
Structure for getting multiple values of different types from a table column.
Definition: Data.hpp:243
Structure for updating multiple values of different types in a table.
Definition: Data.hpp:408
std::vector< Value > values
Vector containing the retrieved values.
Definition: Data.hpp:254
std::string table
The name of the table.
Definition: Data.hpp:392
constexpr auto bytes64bit
The number of bytes of a 64-bit value.
Definition: Data.hpp:57
Structure for updating one value in a table.
Definition: Data.hpp:369
Type
Data types.
Definition: Data.hpp:66
std::uint64_t _ui64
Unsigned 64-bit integer value.
Definition: Data.hpp:112
std::string table
The name of the table.
Definition: Data.hpp:286
bool _isnull
Null value.
Definition: Data.hpp:122
Type getTypeOfSizeT< bytes64bit >()
Identifies std::size_t as a 64-bit integer.
Definition: Data.hpp:552
Structure for inserting multiple values of different types into a row.
Definition: Data.hpp:360
Value value
The retrieved value.
Definition: Data.hpp:221
Value(bool value)
Constructor initializing a boolean value.
Definition: Data.hpp:155
Structure for retrieving one value from a table column.
Definition: Data.hpp:207
Throw a Database::Exception.
Definition: Data.hpp:127
Unsigned 64-bit integer.
Definition: Data.hpp:83
std::string column
The name of the column.
Definition: Data.hpp:263
double _d
Floating point value (with double precision).
Definition: Data.hpp:115
Structure for updating multiple values of the same type in a table.
Definition: Data.hpp:390
Floating point value (with double precision).
Definition: Data.hpp:86
Value(std::uint64_t value)
Constructor initializing an unsigned 64-bit integer.
Definition: Data.hpp:183
std::vector< std::vector< Value > > values
Vector containing the retrieved columns as vectors of the retrieved values.
Definition: Data.hpp:306
std::string table
The name of the table.
Definition: Data.hpp:350
std::string _s
String value.
Definition: Data.hpp:119
std::vector< Value > values
Vector containing the retrieved values.
Definition: Data.hpp:239
Structure for retrieving multiple table columns of the same type.
Definition: Data.hpp:284
std::vector< std::string > order
Optional order to be applied to the SQL query retrieving the values of the columns.
Definition: Data.hpp:326
Value(std::uint32_t value)
Constructor initializing an unsigned 32-bit integer.
Definition: Data.hpp:169
std::int32_t _i32
32-bit integer value.
Definition: Data.hpp:103
Type getTypeOfSizeT()
Resolves std::size_t into the appropriate data type.
Definition: Data.hpp:557
Use an empty string instead.
Definition: Data.hpp:133
std::string column
The name of the column.
Definition: Data.hpp:374
Structure for retrieving multiple values of the same type from a table column.
Definition: Data.hpp:225
std::string table
The name of the table.
Definition: Data.hpp:335
Value(std::int64_t value)
Constructor initializing a 64-bit integer.
Definition: Data.hpp:176
std::string condition
Optional condition to be added to the SQL query retrieving the values of the column.
Definition: Data.hpp:269
bool _b
Boolean value.
Definition: Data.hpp:100
std::string table
The name of the table.
Definition: Data.hpp:410
std::vector< std::string > order
Optional order to be applied to the SQL query retrieving the values of the column.
Definition: Data.hpp:277
Structure for retrieving the values in a table column.
Definition: Data.hpp:258
std::string condition
The condition to be added to the SQL query updating the value.
Definition: Data.hpp:404
64-bit integer.
Definition: Data.hpp:80
std::vector< std::pair< std::string, Type > > columns_types
Vector containing the names and data types of the columns to be retrieved.
Definition: Data.hpp:248
_if_too_large
Enumeration for the action that will be performed if a string is too large for the database...
Definition: Data.hpp:125
Value(const std::string &value)
Constructor initializing a string value.
Definition: Data.hpp:198
std::string condition
Condition to be added to the SQL query retrieving the value.
Definition: Data.hpp:218
Value()=default
Default constructor initializing a null value.
A generic value.
Definition: Data.hpp:96
constexpr auto bytes32bit
The number of bytes of a 32-bit value.
Definition: Data.hpp:54
Value value
The value to be inserted.
Definition: Data.hpp:344
Namespace for different types of data.
std::vector< Value > values
Vector containing the retrieved values.
Definition: Data.hpp:280
Structure for inserting one value into a table.
Definition: Data.hpp:333
std::string table
The name of the table.
Definition: Data.hpp:245
std::string column
The name of the column.
Definition: Data.hpp:338
Structure for inserting multiple values of the same type into a table.
Definition: Data.hpp:348
Trim the string to an acceptable size.
Definition: Data.hpp:130
std::vector< std::vector< Value > > values
Vector containing the retrieved columns as vectors of the retrieved values.
Definition: Data.hpp:329
std::string table
The name of the table.
Definition: Data.hpp:209
std::string table
The name of the table.
Definition: Data.hpp:312