renamed basic_types enumerations
This commit is contained in:
parent
d4ef97ef5a
commit
108eca4e53
|
|
@ -154,61 +154,61 @@ utils::result<size_t, utils::error> postgres_connection::execute(const std::stri
|
|||
utils::basic_type oid2type(const Oid oid) {
|
||||
switch (oid) {
|
||||
case 16:
|
||||
return utils::basic_type::type_bool;
|
||||
return utils::basic_type::Boolean;
|
||||
case 17:
|
||||
return utils::basic_type::type_blob;
|
||||
return utils::basic_type::Blob;
|
||||
case 18:
|
||||
return utils::basic_type::type_int8;
|
||||
return utils::basic_type::Int8;
|
||||
case 21:
|
||||
return utils::basic_type::type_int16;
|
||||
return utils::basic_type::Int16;
|
||||
case 23:
|
||||
return utils::basic_type::type_int32;
|
||||
return utils::basic_type::Int32;
|
||||
case 20:
|
||||
return utils::basic_type::type_int64;
|
||||
return utils::basic_type::Int64;
|
||||
case 25:
|
||||
return utils::basic_type::type_text;
|
||||
return utils::basic_type::Text;
|
||||
case 1043:
|
||||
return utils::basic_type::type_varchar;
|
||||
return utils::basic_type::Varchar;
|
||||
case 700:
|
||||
return utils::basic_type::type_float;
|
||||
return utils::basic_type::Float;
|
||||
case 701:
|
||||
return utils::basic_type::type_double;
|
||||
return utils::basic_type::Double;
|
||||
case 1082:
|
||||
return utils::basic_type::type_date;
|
||||
return utils::basic_type::Date;
|
||||
case 1114:
|
||||
return utils::basic_type::type_time;
|
||||
return utils::basic_type::Time;
|
||||
default:
|
||||
return utils::basic_type::type_null;
|
||||
return utils::basic_type::Null;
|
||||
}
|
||||
}
|
||||
|
||||
utils::basic_type string2type(const char *type) {
|
||||
if (strcmp(type, "int2") == 0) {
|
||||
return utils::basic_type::type_int16;
|
||||
return utils::basic_type::Int16;
|
||||
} else if (strcmp(type, "int4") == 0) {
|
||||
return utils::basic_type::type_int32;
|
||||
return utils::basic_type::Int32;
|
||||
} else if (strcmp(type, "int8") == 0) {
|
||||
return utils::basic_type::type_int64;
|
||||
return utils::basic_type::Int64;
|
||||
} else if (strcmp(type, "bool") == 0) {
|
||||
return utils::basic_type::type_bool;
|
||||
return utils::basic_type::Boolean;
|
||||
} else if (strcmp(type, "date") == 0) {
|
||||
return utils::basic_type::type_date;
|
||||
return utils::basic_type::Date;
|
||||
} else if (strcmp(type, "timestamp") == 0) {
|
||||
return utils::basic_type::type_time;
|
||||
return utils::basic_type::Time;
|
||||
} else if (strcmp(type, "float4") == 0) {
|
||||
return utils::basic_type::type_float;
|
||||
return utils::basic_type::Float;
|
||||
} else if (strcmp(type, "float8") == 0) {
|
||||
return utils::basic_type::type_double;
|
||||
return utils::basic_type::Double;
|
||||
} else if (strncmp(type, "varchar", 7) == 0) {
|
||||
return utils::basic_type::type_varchar;
|
||||
return utils::basic_type::Varchar;
|
||||
} else if (strcmp(type, "character varying") == 0) {
|
||||
return utils::basic_type::type_varchar;
|
||||
return utils::basic_type::Varchar;
|
||||
} else if (strcmp(type, "text") == 0) {
|
||||
return utils::basic_type::type_text;
|
||||
return utils::basic_type::Text;
|
||||
} else if (strcmp(type, "bytea") == 0) {
|
||||
return utils::basic_type::type_blob;
|
||||
return utils::basic_type::Blob;
|
||||
} else {
|
||||
return utils::basic_type::type_null;
|
||||
return utils::basic_type::Null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
{dialect_token::BeginBinaryData, "'\\x"}
|
||||
})
|
||||
.with_data_type_replace_map({
|
||||
{matador::utils::basic_type::type_int8, "SMALLINT"},
|
||||
{matador::utils::basic_type::type_uint8, "SMALLINT"},
|
||||
{matador::utils::basic_type::type_float, "REAL"},
|
||||
{matador::utils::basic_type::type_double, "DOUBLE PRECISION"},
|
||||
{matador::utils::basic_type::type_time, "TIMESTAMP"},
|
||||
{matador::utils::basic_type::type_blob, "BYTEA"}
|
||||
{matador::utils::basic_type::Int8, "SMALLINT"},
|
||||
{matador::utils::basic_type::UInt8, "SMALLINT"},
|
||||
{matador::utils::basic_type::Float, "REAL"},
|
||||
{matador::utils::basic_type::Double, "DOUBLE PRECISION"},
|
||||
{matador::utils::basic_type::Time, "TIMESTAMP"},
|
||||
{matador::utils::basic_type::Blob, "BYTEA"}
|
||||
})
|
||||
.with_bool_strings("TRUE", "FALSE")
|
||||
.with_default_schema_name("public")
|
||||
|
|
|
|||
|
|
@ -172,41 +172,41 @@ void set_value<utils::blob>(const char* str, utils::value& value) {
|
|||
|
||||
void postgres_result_reader::read_value(const char * /*id*/, const size_t index, utils::value &val, size_t) {
|
||||
switch (val.type()) {
|
||||
case utils::basic_type::type_int8:
|
||||
case utils::basic_type::Int8:
|
||||
set_value<int8_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_int16:
|
||||
case utils::basic_type::Int16:
|
||||
set_value<int16_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_int32:
|
||||
case utils::basic_type::Int32:
|
||||
set_value<int32_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_int64:
|
||||
case utils::basic_type::Int64:
|
||||
set_value<int64_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_uint8:
|
||||
case utils::basic_type::UInt8:
|
||||
set_value<uint8_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_uint16:
|
||||
case utils::basic_type::UInt16:
|
||||
set_value<uint16_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_uint32:
|
||||
case utils::basic_type::UInt32:
|
||||
set_value<uint32_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_uint64:
|
||||
case utils::basic_type::UInt64:
|
||||
set_value<uint64_t>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_float:
|
||||
case utils::basic_type::Float:
|
||||
set_value<float>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_double:
|
||||
case utils::basic_type::Double:
|
||||
set_value<double>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_bool:
|
||||
case utils::basic_type::Boolean:
|
||||
set_value<bool>(column(index), val);
|
||||
break;
|
||||
case utils::basic_type::type_text:
|
||||
case utils::basic_type::type_varchar: {
|
||||
case utils::basic_type::Text:
|
||||
case utils::basic_type::Varchar: {
|
||||
if (const auto *column_value = column(index); column_value == nullptr) {
|
||||
val = std::string{};
|
||||
} else {
|
||||
|
|
@ -214,16 +214,16 @@ void postgres_result_reader::read_value(const char * /*id*/, const size_t index,
|
|||
}
|
||||
break;
|
||||
}
|
||||
case utils::basic_type::type_time:
|
||||
case utils::basic_type::type_date: {
|
||||
case utils::basic_type::Time:
|
||||
case utils::basic_type::Date: {
|
||||
val = std::string{column(index)};
|
||||
break;
|
||||
}
|
||||
case utils::basic_type::type_null: {
|
||||
case utils::basic_type::Null: {
|
||||
val = nullptr_t{};
|
||||
break;
|
||||
}
|
||||
case utils::basic_type::type_blob: {
|
||||
case utils::basic_type::Blob: {
|
||||
set_value<utils::blob>(column(index), val);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,22 +41,22 @@ public:
|
|||
[[nodiscard]] bool is_nullable() const { return null_option_type_ == null_option_type::Nullable; }
|
||||
[[nodiscard]] utils::basic_type type() const { return type_; }
|
||||
|
||||
[[nodiscard]] bool is_integer() const { return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64; }
|
||||
[[nodiscard]] bool is_floating_point() const { return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double; }
|
||||
[[nodiscard]] bool is_bool() const { return type_ == utils::basic_type::type_bool; }
|
||||
[[nodiscard]] bool is_string() const { return type_ == utils::basic_type::type_text; }
|
||||
[[nodiscard]] bool is_varchar() const { return type_ == utils::basic_type::type_varchar; }
|
||||
[[nodiscard]] bool is_date() const { return type_ == utils::basic_type::type_date; }
|
||||
[[nodiscard]] bool is_time() const { return type_ == utils::basic_type::type_time; }
|
||||
[[nodiscard]] bool is_blob() const { return type_ == utils::basic_type::type_blob; }
|
||||
[[nodiscard]] bool is_null() const { return type_ == utils::basic_type::type_null; }
|
||||
[[nodiscard]] bool is_integer() const { return type_ >= utils::basic_type::Int8 && type_ <= utils::basic_type::UInt64; }
|
||||
[[nodiscard]] bool is_floating_point() const { return type_ == utils::basic_type::Float || type_ == utils::basic_type::Double; }
|
||||
[[nodiscard]] bool is_bool() const { return type_ == utils::basic_type::Boolean; }
|
||||
[[nodiscard]] bool is_string() const { return type_ == utils::basic_type::Text; }
|
||||
[[nodiscard]] bool is_varchar() const { return type_ == utils::basic_type::Varchar; }
|
||||
[[nodiscard]] bool is_date() const { return type_ == utils::basic_type::Date; }
|
||||
[[nodiscard]] bool is_time() const { return type_ == utils::basic_type::Time; }
|
||||
[[nodiscard]] bool is_blob() const { return type_ == utils::basic_type::Blob; }
|
||||
[[nodiscard]] bool is_null() const { return type_ == utils::basic_type::Null; }
|
||||
|
||||
private:
|
||||
friend class object;
|
||||
|
||||
std::string name_;
|
||||
std::string alias_;
|
||||
utils::basic_type type_{utils::basic_type::type_null};
|
||||
utils::basic_type type_{utils::basic_type::Null};
|
||||
utils::field_attributes options_;
|
||||
null_option_type null_option_type_{null_option_type::NotNull};
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include "matador/orm/session.hpp"
|
||||
|
||||
template <> struct matador::utils::data_type_traits<work::core::timestamp, void> {
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; }
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
|
||||
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
|
||||
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ template <> struct matador::utils::data_type_traits<work::core::timestamp, void>
|
|||
};
|
||||
|
||||
template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> {
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; }
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
|
||||
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ private:
|
|||
|
||||
std::string name_;
|
||||
object *owner_{nullptr};
|
||||
utils::basic_type type_{utils::basic_type::type_null};
|
||||
utils::basic_type type_{utils::basic_type::Null};
|
||||
utils::field_attributes options_{};
|
||||
null_option_type null_option_{null_option_type::NotNull};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -243,23 +243,23 @@ private:
|
|||
};
|
||||
|
||||
data_type_to_string_map data_types_ {
|
||||
{utils::basic_type::type_int8, "TINYINT"},
|
||||
{utils::basic_type::type_int16, "SMALLINT"},
|
||||
{utils::basic_type::type_int32, "INTEGER"},
|
||||
{utils::basic_type::type_int64, "BIGINT"},
|
||||
{utils::basic_type::type_uint8, "TINYINT"},
|
||||
{utils::basic_type::type_uint16, "INTEGER"},
|
||||
{utils::basic_type::type_uint32, "BIGINT"},
|
||||
{utils::basic_type::type_uint64, "BIGINT"},
|
||||
{utils::basic_type::type_float, "FLOAT"},
|
||||
{utils::basic_type::type_double, "DOUBLE"},
|
||||
{utils::basic_type::type_bool, "BOOLEAN"},
|
||||
{utils::basic_type::type_varchar, "VARCHAR"},
|
||||
{utils::basic_type::type_text, "TEXT"},
|
||||
{utils::basic_type::type_date, "DATE"},
|
||||
{utils::basic_type::type_time, "DATETIME"},
|
||||
{utils::basic_type::type_blob, "BLOB"},
|
||||
{utils::basic_type::type_null, "NULL"}
|
||||
{utils::basic_type::Int8, "TINYINT"},
|
||||
{utils::basic_type::Int16, "SMALLINT"},
|
||||
{utils::basic_type::Int32, "INTEGER"},
|
||||
{utils::basic_type::Int64, "BIGINT"},
|
||||
{utils::basic_type::UInt8, "TINYINT"},
|
||||
{utils::basic_type::UInt16, "INTEGER"},
|
||||
{utils::basic_type::UInt32, "BIGINT"},
|
||||
{utils::basic_type::UInt64, "BIGINT"},
|
||||
{utils::basic_type::Float, "FLOAT"},
|
||||
{utils::basic_type::Double, "DOUBLE"},
|
||||
{utils::basic_type::Boolean, "BOOLEAN"},
|
||||
{utils::basic_type::Varchar, "VARCHAR"},
|
||||
{utils::basic_type::Text, "TEXT"},
|
||||
{utils::basic_type::Date, "DATE"},
|
||||
{utils::basic_type::Time, "DATETIME"},
|
||||
{utils::basic_type::Blob, "BLOB"},
|
||||
{utils::basic_type::Null, "NULL"}
|
||||
};
|
||||
|
||||
sql_func_to_string_map sql_func_map_ {
|
||||
|
|
|
|||
|
|
@ -9,24 +9,24 @@ namespace matador::utils {
|
|||
* @brief Enumeration type of all supported basic data types
|
||||
*/
|
||||
enum class basic_type : uint8_t {
|
||||
type_int8 = 0, /*!< Data type int8 */
|
||||
type_int16, /*!< Data type int16 */
|
||||
type_int32, /*!< Data type int32 */
|
||||
type_int64, /*!< Data type int64 */
|
||||
type_uint8, /*!< Data type unsigned int8 */
|
||||
type_uint16, /*!< Data type unsigned int16 */
|
||||
type_uint32, /*!< Data type unsigned int32 */
|
||||
type_uint64, /*!< Data type unsigned int64 */
|
||||
type_float, /*!< Data type float */
|
||||
type_double, /*!< Data type double */
|
||||
type_bool, /*!< Data type bool */
|
||||
type_varchar, /*!< Data type varchar */
|
||||
type_text, /*!< Data type text */
|
||||
type_date, /*!< Data type date */
|
||||
type_time, /*!< Data type time */
|
||||
type_blob, /*!< Data type blob */
|
||||
type_null, /*!< Data type null */
|
||||
type_unknown /*!< Data type unknown */
|
||||
Int8 = 0, /*!< Data type int8 */
|
||||
Int16, /*!< Data type int16 */
|
||||
Int32, /*!< Data type int32 */
|
||||
Int64, /*!< Data type int64 */
|
||||
UInt8, /*!< Data type unsigned int8 */
|
||||
UInt16, /*!< Data type unsigned int16 */
|
||||
UInt32, /*!< Data type unsigned int32 */
|
||||
UInt64, /*!< Data type unsigned int64 */
|
||||
Float, /*!< Data type float */
|
||||
Double, /*!< Data type double */
|
||||
Boolean, /*!< Data type bool */
|
||||
Varchar, /*!< Data type varchar */
|
||||
Text, /*!< Data type text */
|
||||
Date, /*!< Data type date */
|
||||
Time, /*!< Data type time */
|
||||
Blob, /*!< Data type blob */
|
||||
Null, /*!< Data type null */
|
||||
Unknown /*!< Data type unknown */
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class attribute_writer;
|
|||
*/
|
||||
template < class Type, class Enable = void >
|
||||
struct data_type_traits {
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_unknown; }
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::Unknown; }
|
||||
static void read_value(attribute_reader &/*reader*/, const char *id, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0) {}
|
||||
static void bind_value(attribute_writer &/*binder*/, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0) {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,105 +12,105 @@ namespace matador::utils {
|
|||
/// @cond MATADOR_DEV
|
||||
template <> struct data_type_traits<nullptr_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_null; }
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::Null; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<int8_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int8; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int8; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int8_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const int8_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<int16_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int16; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int16; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int16_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const int16_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<int32_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int32; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int32; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int32_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const int32_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<int64_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int64; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int64; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int64_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const int64_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<uint8_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint8; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt8; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint8_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const uint8_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<uint16_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint16; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt16; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint16_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const uint16_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<uint32_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint32; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt32; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint32_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const uint32_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<uint64_t, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint64; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt64; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint64_t &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const uint64_t &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<bool, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_bool; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Boolean; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, bool &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const bool &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<float, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_float; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Float; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, float &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const float &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<double, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_double; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Double; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, double &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const double &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<const char*, void>
|
||||
{
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, const char* value, size_t size);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const char *value, size_t size = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<char*, void>
|
||||
{
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, char *value, size_t size);
|
||||
static void bind_value(attribute_writer &binder, size_t index, const char *value, size_t size = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<char[], void>
|
||||
{
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||
template < int N >
|
||||
static void read_value(attribute_reader &reader, const char *id, const size_t index, char (&value)[N], const size_t size) {
|
||||
data_type_traits<const char*>::read_value(reader, id, index, value, size);
|
||||
|
|
@ -123,14 +123,14 @@ template <> struct data_type_traits<char[], void>
|
|||
|
||||
template <> struct data_type_traits<std::string, void>
|
||||
{
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, std::string &value, size_t size);
|
||||
static void bind_value(attribute_writer &binder, size_t index, std::string &value, size_t size = 0);
|
||||
};
|
||||
|
||||
template <> struct data_type_traits<utils::blob, void>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_blob; }
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::Blob; }
|
||||
static void read_value(attribute_reader &reader, const char *id, size_t index, utils::blob &value, size_t /*size*/ = 0);
|
||||
static void bind_value(attribute_writer &binder, size_t index, utils::blob &value, size_t /*size*/ = 0);
|
||||
};
|
||||
|
|
@ -152,7 +152,7 @@ template <> struct data_type_traits<utils::blob, void>
|
|||
template < typename EnumType >
|
||||
struct data_type_traits<EnumType, std::enable_if_t<std::is_enum_v<EnumType>>>
|
||||
{
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int32; }
|
||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int32; }
|
||||
static void read_value(attribute_reader &reader, const char *id, const size_t index, EnumType &value, const size_t size = 0) {
|
||||
data_type_traits<int>::read_value(reader, id, index, reinterpret_cast<int&>(value), size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ private:
|
|||
[[nodiscard]] virtual size_t hash() const = 0;
|
||||
|
||||
std::type_index type_index_;
|
||||
basic_type type_{basic_type::type_null};
|
||||
basic_type type_{basic_type::Null};
|
||||
};
|
||||
|
||||
template<class IdType>
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public:
|
|||
private:
|
||||
utils::database_type value_;
|
||||
size_t size_{};
|
||||
basic_type type_{basic_type::type_null};
|
||||
basic_type type_{basic_type::Null};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace matador::object {
|
||||
attribute::attribute(std::string name)
|
||||
: attribute(std::move(name), utils::basic_type::type_null, {}, null_option_type::NotNull) {
|
||||
: attribute(std::move(name), utils::basic_type::Null, {}, null_option_type::NotNull) {
|
||||
}
|
||||
|
||||
attribute::attribute(std::string name,
|
||||
|
|
@ -57,39 +57,39 @@ void attribute::change_type(const utils::basic_type type, const utils::field_att
|
|||
}
|
||||
|
||||
bool attribute::is_integer() const {
|
||||
return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64;
|
||||
return type_ >= utils::basic_type::Int8 && type_ <= utils::basic_type::UInt64;
|
||||
}
|
||||
|
||||
bool attribute::is_floating_point() const {
|
||||
return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double;
|
||||
return type_ == utils::basic_type::Float || type_ == utils::basic_type::Double;
|
||||
}
|
||||
|
||||
bool attribute::is_bool() const {
|
||||
return type_ == utils::basic_type::type_bool;
|
||||
return type_ == utils::basic_type::Boolean;
|
||||
}
|
||||
|
||||
bool attribute::is_string() const {
|
||||
return type_ == utils::basic_type::type_text;
|
||||
return type_ == utils::basic_type::Text;
|
||||
}
|
||||
|
||||
bool attribute::is_varchar() const {
|
||||
return type_ == utils::basic_type::type_varchar;
|
||||
return type_ == utils::basic_type::Varchar;
|
||||
}
|
||||
|
||||
bool attribute::is_date() const {
|
||||
return type_ == utils::basic_type::type_date;
|
||||
return type_ == utils::basic_type::Date;
|
||||
}
|
||||
|
||||
bool attribute::is_time() const {
|
||||
return type_ == utils::basic_type::type_time;
|
||||
return type_ == utils::basic_type::Time;
|
||||
}
|
||||
|
||||
bool attribute::is_blob() const {
|
||||
return type_ == utils::basic_type::type_blob;
|
||||
return type_ == utils::basic_type::Blob;
|
||||
}
|
||||
|
||||
bool attribute::is_null() const {
|
||||
return type_ == utils::basic_type::type_null;
|
||||
return type_ == utils::basic_type::Null;
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream &os, const attribute &attr) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ identifier::base::base(const std::type_index &ti, const basic_type type)
|
|||
{}
|
||||
|
||||
identifier::null_pk::null_pk()
|
||||
: base(std::type_index(typeid(null_type_t)), basic_type::type_null)
|
||||
: base(std::type_index(typeid(null_type_t)), basic_type::Null)
|
||||
{}
|
||||
|
||||
identifier::base* identifier::null_pk::copy() const
|
||||
|
|
@ -134,31 +134,31 @@ size_t identifier::use_count() const
|
|||
}
|
||||
|
||||
bool identifier::is_integer() const {
|
||||
return id_->type_ >= basic_type::type_int8 && id_->type_ <= basic_type::type_uint64;
|
||||
return id_->type_ >= basic_type::Int8 && id_->type_ <= basic_type::UInt64;
|
||||
}
|
||||
|
||||
bool identifier::is_floating_point() const {
|
||||
return id_->type_ == basic_type::type_float || id_->type_ == basic_type::type_double;
|
||||
return id_->type_ == basic_type::Float || id_->type_ == basic_type::Double;
|
||||
}
|
||||
|
||||
bool identifier::is_bool() const {
|
||||
return id_->type_ == basic_type::type_bool;
|
||||
return id_->type_ == basic_type::Boolean;
|
||||
}
|
||||
|
||||
bool identifier::is_varchar() const {
|
||||
return id_->type_ == basic_type::type_varchar;
|
||||
return id_->type_ == basic_type::Varchar;
|
||||
}
|
||||
|
||||
bool identifier::is_date() const {
|
||||
return id_->type_ == basic_type::type_date;
|
||||
return id_->type_ == basic_type::Date;
|
||||
}
|
||||
|
||||
bool identifier::is_time() const {
|
||||
return id_->type_ == basic_type::type_time;
|
||||
return id_->type_ == basic_type::Time;
|
||||
}
|
||||
|
||||
bool identifier::is_blob() const {
|
||||
return id_->type_ == basic_type::type_blob;
|
||||
return id_->type_ == basic_type::Blob;
|
||||
}
|
||||
|
||||
bool identifier::is_null() const
|
||||
|
|
|
|||
|
|
@ -6,41 +6,41 @@ namespace matador::utils {
|
|||
void initialize_by_basic_type(const basic_type type, database_type &val)
|
||||
{
|
||||
switch (type) {
|
||||
case basic_type::type_int8:
|
||||
case basic_type::Int8:
|
||||
val.emplace<int8_t>();
|
||||
break;
|
||||
case basic_type::type_int16:
|
||||
case basic_type::Int16:
|
||||
val.emplace<int16_t>();
|
||||
break;
|
||||
case basic_type::type_int32:
|
||||
case basic_type::Int32:
|
||||
val.emplace<int32_t>();
|
||||
break;
|
||||
case basic_type::type_int64:
|
||||
case basic_type::Int64:
|
||||
val.emplace<int64_t>();
|
||||
break;
|
||||
case basic_type::type_uint8:
|
||||
case basic_type::UInt8:
|
||||
val.emplace<uint8_t>();
|
||||
break;
|
||||
case basic_type::type_uint16:
|
||||
case basic_type::UInt16:
|
||||
val.emplace<uint16_t>();
|
||||
break;
|
||||
case basic_type::type_uint32:
|
||||
case basic_type::UInt32:
|
||||
val.emplace<uint32_t>();
|
||||
break;
|
||||
case basic_type::type_uint64:
|
||||
case basic_type::UInt64:
|
||||
val.emplace<uint64_t>();
|
||||
break;
|
||||
case basic_type::type_bool:
|
||||
case basic_type::Boolean:
|
||||
val.emplace<bool>();
|
||||
break;
|
||||
case basic_type::type_float:
|
||||
case basic_type::Float:
|
||||
val.emplace<float>();
|
||||
break;
|
||||
case basic_type::type_double:
|
||||
case basic_type::Double:
|
||||
val.emplace<double>();
|
||||
break;
|
||||
case basic_type::type_varchar:
|
||||
case basic_type::type_text:
|
||||
case basic_type::Varchar:
|
||||
case basic_type::Text:
|
||||
val.emplace<std::string>();
|
||||
break;
|
||||
// case basic_type::type_date:
|
||||
|
|
@ -49,7 +49,7 @@ void initialize_by_basic_type(const basic_type type, database_type &val)
|
|||
// case basic_type::type_time:
|
||||
// val.emplace<time>();
|
||||
// break;
|
||||
case basic_type::type_blob:
|
||||
case basic_type::Blob:
|
||||
val.emplace<utils::blob>();
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ value::value(value &&x) noexcept
|
|||
, type_(x.type_)
|
||||
{
|
||||
x.value_ = nullptr;
|
||||
x.type_ = basic_type::type_null;
|
||||
x.type_ = basic_type::Null;
|
||||
}
|
||||
|
||||
value &value::operator=(value &&x) noexcept
|
||||
|
|
@ -40,7 +40,7 @@ value &value::operator=(value &&x) noexcept
|
|||
value_ = std::move(x.value_);
|
||||
type_ = x.type_;
|
||||
x.value_ = nullptr;
|
||||
x.type_ = basic_type::type_null;
|
||||
x.type_ = basic_type::Null;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -66,87 +66,87 @@ void value::type(const basic_type t) {
|
|||
|
||||
bool value::is_integer() const
|
||||
{
|
||||
return type_ >= basic_type::type_int8 && type_ <= basic_type::type_uint64;
|
||||
return type_ >= basic_type::Int8 && type_ <= basic_type::UInt64;
|
||||
}
|
||||
|
||||
bool value::is_floating_point() const
|
||||
{
|
||||
return type_ == basic_type::type_float || type_ == basic_type::type_double;
|
||||
return type_ == basic_type::Float || type_ == basic_type::Double;
|
||||
}
|
||||
|
||||
bool value::is_bool() const
|
||||
{
|
||||
return type_ == basic_type::type_bool;
|
||||
return type_ == basic_type::Boolean;
|
||||
}
|
||||
|
||||
bool value::is_string() const
|
||||
{
|
||||
return type_ == basic_type::type_text;
|
||||
return type_ == basic_type::Text;
|
||||
}
|
||||
|
||||
bool value::is_varchar() const
|
||||
{
|
||||
return type_ == basic_type::type_varchar;
|
||||
return type_ == basic_type::Varchar;
|
||||
}
|
||||
|
||||
bool value::is_date() const
|
||||
{
|
||||
return type_ == basic_type::type_date;
|
||||
return type_ == basic_type::Date;
|
||||
}
|
||||
|
||||
bool value::is_time() const
|
||||
{
|
||||
return type_ == basic_type::type_time;
|
||||
return type_ == basic_type::Time;
|
||||
}
|
||||
|
||||
bool value::is_blob() const
|
||||
{
|
||||
return type_ == basic_type::type_blob;
|
||||
return type_ == basic_type::Blob;
|
||||
}
|
||||
|
||||
bool value::is_null() const
|
||||
{
|
||||
return type_ == basic_type::type_null;
|
||||
return type_ == basic_type::Null;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
void initialize_by_basic_type(const basic_type type, database_type &val) {
|
||||
switch (type) {
|
||||
case basic_type::type_int8:
|
||||
case basic_type::Int8:
|
||||
val.emplace<int8_t>();
|
||||
break;
|
||||
case basic_type::type_int16:
|
||||
case basic_type::Int16:
|
||||
val.emplace<int16_t>();
|
||||
break;
|
||||
case basic_type::type_int32:
|
||||
case basic_type::Int32:
|
||||
val.emplace<int32_t>();
|
||||
break;
|
||||
case basic_type::type_int64:
|
||||
case basic_type::Int64:
|
||||
val.emplace<int64_t>();
|
||||
break;
|
||||
case basic_type::type_uint8:
|
||||
case basic_type::UInt8:
|
||||
val.emplace<uint8_t>();
|
||||
break;
|
||||
case basic_type::type_uint16:
|
||||
case basic_type::UInt16:
|
||||
val.emplace<uint16_t>();
|
||||
break;
|
||||
case basic_type::type_uint32:
|
||||
case basic_type::UInt32:
|
||||
val.emplace<uint32_t>();
|
||||
break;
|
||||
case basic_type::type_uint64:
|
||||
case basic_type::UInt64:
|
||||
val.emplace<uint64_t>();
|
||||
break;
|
||||
case basic_type::type_bool:
|
||||
case basic_type::Boolean:
|
||||
val.emplace<bool>();
|
||||
break;
|
||||
case basic_type::type_float:
|
||||
case basic_type::Float:
|
||||
val.emplace<float>();
|
||||
break;
|
||||
case basic_type::type_double:
|
||||
case basic_type::Double:
|
||||
val.emplace<double>();
|
||||
break;
|
||||
case basic_type::type_varchar:
|
||||
case basic_type::type_text:
|
||||
case basic_type::Varchar:
|
||||
case basic_type::Text:
|
||||
val.emplace<std::string>();
|
||||
break;
|
||||
// case basic_type::type_date:
|
||||
|
|
@ -155,7 +155,7 @@ void initialize_by_basic_type(const basic_type type, database_type &val) {
|
|||
// case basic_type::type_time:
|
||||
// val.emplace<time>();
|
||||
// break;
|
||||
case basic_type::type_blob:
|
||||
case basic_type::Blob:
|
||||
val.emplace<utils::blob>();
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ sql::query_context query_compiler::compile(const query_data &data,
|
|||
std::string handle_column(sql::query_context &ctx, const sql::dialect *d, const query_data &data, const column &col) {
|
||||
if (col.is_function()) {
|
||||
ctx.prototype.emplace_back(col.has_alias() ? col.alias() : col.name());
|
||||
ctx.prototype.back().change_type(utils::basic_type::type_int32);
|
||||
ctx.prototype.back().change_type(utils::basic_type::Int32);
|
||||
} else {
|
||||
ctx.prototype.emplace_back(col.name());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ utils::result<size_t, utils::error> connection::execute(const std::string &sql)
|
|||
|
||||
bool has_unknown_columns(const std::vector<object::attribute> &columns) {
|
||||
return std::any_of(std::begin(columns), std::end(columns), [](const auto &col) {
|
||||
return col.type() == utils::basic_type::type_null;
|
||||
return col.type() == utils::basic_type::Null;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -228,7 +228,7 @@ utils::result<std::unique_ptr<statement_impl>, utils::error> connection::perform
|
|||
std::end(*result),
|
||||
[&col](const auto &value) { return value.name() == col.name(); }
|
||||
);
|
||||
if (col.type() == utils::basic_type::type_null && rit != result->end()) {
|
||||
if (col.type() == utils::basic_type::Null && rit != result->end()) {
|
||||
const_cast<object::attribute&>(col).change_type(rit->type());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
|||
auto res = query::create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
attribute("from", basic_type::type_varchar, 255),
|
||||
attribute("to", basic_type::type_varchar, 255)
|
||||
attribute("from", basic_type::Varchar, 255),
|
||||
attribute("to", basic_type::Varchar, 255)
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
|
@ -126,7 +126,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
|||
|
||||
// check table description
|
||||
std::vector<std::string> column_names = { "from", "to"};
|
||||
std::vector types = {basic_type::type_varchar, basic_type::type_varchar};
|
||||
std::vector types = {basic_type::Varchar, basic_type::Varchar};
|
||||
const auto columns = db.describe("quotes");
|
||||
REQUIRE(columns.is_ok());
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
|||
auto res = query::create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
attribute(name, basic_type::type_varchar, 255)
|
||||
attribute(name, basic_type::Varchar, 255)
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
|
@ -203,7 +203,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
|||
|
||||
for (const auto &col : *columns) {
|
||||
REQUIRE(col.name() == name);
|
||||
REQUIRE(col.type() == basic_type::type_varchar);
|
||||
REQUIRE(col.type() == basic_type::Varchar);
|
||||
}
|
||||
|
||||
res = query::drop()
|
||||
|
|
@ -221,7 +221,7 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
|
|||
auto res = query::create()
|
||||
.table("escapes")
|
||||
.columns({
|
||||
attribute("name", basic_type::type_varchar, 255)
|
||||
attribute("name", basic_type::Varchar, 255)
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
|
|
|||
|
|
@ -26,23 +26,23 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
|||
auto res = query::create()
|
||||
.table("types")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("val_char", basic_type::type_int8),
|
||||
attribute("val_short", basic_type::type_int16),
|
||||
attribute("val_int", basic_type::type_int32),
|
||||
attribute("val_long_long", basic_type::type_int64),
|
||||
attribute("val_uchar", basic_type::type_uint8),
|
||||
attribute("val_ushort", basic_type::type_uint16),
|
||||
attribute("val_uint", basic_type::type_uint32),
|
||||
attribute("val_ulong_long", basic_type::type_uint64),
|
||||
attribute("val_bool", basic_type::type_bool),
|
||||
attribute("val_float", basic_type::type_float),
|
||||
attribute("val_double", basic_type::type_double),
|
||||
attribute("val_string", basic_type::type_text),
|
||||
attribute("val_varchar", basic_type::type_varchar, 63),
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("val_char", basic_type::Int8),
|
||||
attribute("val_short", basic_type::Int16),
|
||||
attribute("val_int", basic_type::Int32),
|
||||
attribute("val_long_long", basic_type::Int64),
|
||||
attribute("val_uchar", basic_type::UInt8),
|
||||
attribute("val_ushort", basic_type::UInt16),
|
||||
attribute("val_uint", basic_type::UInt32),
|
||||
attribute("val_ulong_long", basic_type::UInt64),
|
||||
attribute("val_bool", basic_type::Boolean),
|
||||
attribute("val_float", basic_type::Float),
|
||||
attribute("val_double", basic_type::Double),
|
||||
attribute("val_string", basic_type::Text),
|
||||
attribute("val_varchar", basic_type::Varchar, 63),
|
||||
// attribute("val_date", basic_type::type_date),
|
||||
// attribute("val_time", basic_type::type_time),
|
||||
attribute("val_blob", basic_type::type_blob),
|
||||
attribute("val_blob", basic_type::Blob),
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_types").primary_key("id")
|
||||
|
|
@ -126,9 +126,9 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][recor
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -154,9 +154,9 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
|||
auto res = query::create()
|
||||
.table("airplane")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("brand", basic_type::type_varchar, 255),
|
||||
attribute("model", basic_type::type_varchar, 255),
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("brand", basic_type::Varchar, 255),
|
||||
attribute("model", basic_type::Varchar, 255),
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_airplane").primary_key("id"),
|
||||
|
|
@ -171,9 +171,9 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
|||
res = query::create()
|
||||
.table("flight")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("airplane_id", basic_type::type_uint32),
|
||||
attribute("pilot_name", basic_type::type_varchar, 255)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("airplane_id", basic_type::UInt32),
|
||||
attribute("pilot_name", basic_type::Varchar, 255)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_flight").primary_key("id"),
|
||||
|
|
@ -208,9 +208,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement", "[query][recor
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -251,9 +251,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
|||
auto res = query::create()
|
||||
.table("airplane")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("brand", basic_type::type_varchar, 255),
|
||||
attribute("model", basic_type::type_varchar, 255),
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("brand", basic_type::Varchar, 255),
|
||||
attribute("model", basic_type::Varchar, 255),
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_airplane").primary_key("id"),
|
||||
|
|
@ -266,9 +266,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
|||
res = query::create()
|
||||
.table("flight")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("airplane_id", basic_type::type_uint32),
|
||||
attribute("pilot_name", basic_type::type_varchar, 255)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("airplane_id", basic_type::UInt32),
|
||||
attribute("pilot_name", basic_type::Varchar, 255)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_flight").primary_key("id"),
|
||||
|
|
@ -314,9 +314,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute update record statement", "[query][recor
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -367,9 +367,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement", "[query][record]")
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -427,9 +427,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with order by", "[query
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -473,9 +473,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -526,9 +526,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute delete statement", "[query][record]") {
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -576,8 +576,8 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
|||
auto res = query::create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
attribute("from", basic_type::type_varchar, 255),
|
||||
attribute("to", basic_type::type_varchar, 255)
|
||||
attribute("from", basic_type::Varchar, 255),
|
||||
attribute("to", basic_type::Varchar, 255)
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
|
@ -587,8 +587,8 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
|||
// check table description
|
||||
std::vector<std::string> columns = { "from", "to"};
|
||||
std::vector types = {
|
||||
basic_type::type_varchar,
|
||||
basic_type::type_varchar
|
||||
basic_type::Varchar,
|
||||
basic_type::Varchar
|
||||
};
|
||||
auto fields = db.describe("quotes");
|
||||
REQUIRE(fields.is_ok());
|
||||
|
|
@ -637,9 +637,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create record", "[query][record][create]")
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -664,9 +664,9 @@ TEST_CASE_METHOD(QueryFixture, "Test insert record", "[query][record][insert]")
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -701,9 +701,9 @@ TEST_CASE_METHOD(QueryFixture, "Test update record", "[query][record][update]")
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -755,9 +755,9 @@ TEST_CASE_METHOD(QueryFixture, "Test prepared record statement", "[query][record
|
|||
auto stmt = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
@ -785,7 +785,7 @@ TEST_CASE_METHOD(QueryFixture, "Test scalar result", "[query][record][scalar][re
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32)
|
||||
attribute("id", basic_type::UInt32)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
|
|||
|
|
@ -110,9 +110,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
|||
auto res = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", matador::utils::basic_type::type_uint32),
|
||||
attribute("name", matador::utils::basic_type::type_varchar, 255),
|
||||
attribute("color", matador::utils::basic_type::type_varchar, 63)
|
||||
attribute("id", matador::utils::basic_type::UInt32),
|
||||
attribute("name", matador::utils::basic_type::Varchar, 255),
|
||||
attribute("color", matador::utils::basic_type::Varchar, 63)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
|
|
|
|||
|
|
@ -22,15 +22,15 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
|
|||
auto columns = attribute_generator::generate<matador::test::product>(repo, obj);
|
||||
|
||||
const std::vector expected_columns = {
|
||||
attribute{"product_name", basic_type::type_varchar, constraints::PrimaryKey, null_option_type::NotNull },
|
||||
attribute{"supplier_id", basic_type::type_uint32, constraints::ForeignKey, null_option_type::NotNull },
|
||||
attribute{"category_id", basic_type::type_uint32, constraints::ForeignKey, null_option_type::NotNull },
|
||||
attribute{"quantity_per_unit", basic_type::type_varchar, null_attributes, null_option_type::NotNull },
|
||||
attribute{"unit_price", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"units_in_stock", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"units_in_order", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"reorder_level", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"discontinued", basic_type::type_bool, null_attributes, null_option_type::NotNull }
|
||||
attribute{"product_name", basic_type::Varchar, constraints::PrimaryKey, null_option_type::NotNull },
|
||||
attribute{"supplier_id", basic_type::UInt32, constraints::ForeignKey, null_option_type::NotNull },
|
||||
attribute{"category_id", basic_type::UInt32, constraints::ForeignKey, null_option_type::NotNull },
|
||||
attribute{"quantity_per_unit", basic_type::Varchar, null_attributes, null_option_type::NotNull },
|
||||
attribute{"unit_price", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"units_in_stock", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"units_in_order", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"reorder_level", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||
attribute{"discontinued", basic_type::Boolean, null_attributes, null_option_type::NotNull }
|
||||
};
|
||||
REQUIRE(!columns.empty());
|
||||
REQUIRE(columns.size() == expected_columns.size());
|
||||
|
|
@ -49,9 +49,9 @@ TEST_CASE("Generate columns from object with nullable columns", "[column generat
|
|||
auto columns = attribute_generator::generate<matador::test::optional>(repo, obj);
|
||||
|
||||
const std::vector expected_columns = {
|
||||
attribute{"id", basic_type::type_uint32, constraints::PrimaryKey, null_option_type::NotNull },
|
||||
attribute{"name", basic_type::type_varchar, null_attributes, null_option_type::NotNull },
|
||||
attribute{"age", basic_type::type_uint32, null_attributes, null_option_type::NotNull }
|
||||
attribute{"id", basic_type::UInt32, constraints::PrimaryKey, null_option_type::NotNull },
|
||||
attribute{"name", basic_type::Varchar, null_attributes, null_option_type::NotNull },
|
||||
attribute{"age", basic_type::UInt32, null_attributes, null_option_type::NotNull }
|
||||
};
|
||||
REQUIRE(!columns.empty());
|
||||
REQUIRE(columns.size() == expected_columns.size());
|
||||
|
|
|
|||
|
|
@ -5,24 +5,24 @@
|
|||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE("Test default data types", "[data_types][type]") {
|
||||
REQUIRE(data_type_traits<int8_t>::type() == basic_type::type_int8);
|
||||
REQUIRE(data_type_traits<int16_t>::type() == basic_type::type_int16);
|
||||
REQUIRE(data_type_traits<int32_t>::type() == basic_type::type_int32);
|
||||
REQUIRE(data_type_traits<int64_t>::type() == basic_type::type_int64);
|
||||
REQUIRE(data_type_traits<uint8_t>::type() == basic_type::type_uint8);
|
||||
REQUIRE(data_type_traits<uint16_t>::type() == basic_type::type_uint16);
|
||||
REQUIRE(data_type_traits<uint32_t>::type() == basic_type::type_uint32);
|
||||
REQUIRE(data_type_traits<uint64_t>::type() == basic_type::type_uint64);
|
||||
REQUIRE(data_type_traits<bool>::type() == basic_type::type_bool);
|
||||
REQUIRE(data_type_traits<float>::type() == basic_type::type_float);
|
||||
REQUIRE(data_type_traits<double>::type() == basic_type::type_double);
|
||||
REQUIRE(data_type_traits<const char*>::type(32) == basic_type::type_varchar);
|
||||
REQUIRE(data_type_traits<const char*>::type(0) == basic_type::type_text);
|
||||
REQUIRE(data_type_traits<char*>::type(32) == basic_type::type_varchar);
|
||||
REQUIRE(data_type_traits<char*>::type(0) == basic_type::type_text);
|
||||
REQUIRE(data_type_traits<char[]>::type(32) == basic_type::type_varchar);
|
||||
REQUIRE(data_type_traits<char[]>::type(0) == basic_type::type_text);
|
||||
REQUIRE(data_type_traits<std::string>::type(32) == basic_type::type_varchar);
|
||||
REQUIRE(data_type_traits<std::string>::type(0) == basic_type::type_text);
|
||||
REQUIRE(data_type_traits<blob>::type(0) == basic_type::type_blob);
|
||||
REQUIRE(data_type_traits<int8_t>::type() == basic_type::Int8);
|
||||
REQUIRE(data_type_traits<int16_t>::type() == basic_type::Int16);
|
||||
REQUIRE(data_type_traits<int32_t>::type() == basic_type::Int32);
|
||||
REQUIRE(data_type_traits<int64_t>::type() == basic_type::Int64);
|
||||
REQUIRE(data_type_traits<uint8_t>::type() == basic_type::UInt8);
|
||||
REQUIRE(data_type_traits<uint16_t>::type() == basic_type::UInt16);
|
||||
REQUIRE(data_type_traits<uint32_t>::type() == basic_type::UInt32);
|
||||
REQUIRE(data_type_traits<uint64_t>::type() == basic_type::UInt64);
|
||||
REQUIRE(data_type_traits<bool>::type() == basic_type::Boolean);
|
||||
REQUIRE(data_type_traits<float>::type() == basic_type::Float);
|
||||
REQUIRE(data_type_traits<double>::type() == basic_type::Double);
|
||||
REQUIRE(data_type_traits<const char*>::type(32) == basic_type::Varchar);
|
||||
REQUIRE(data_type_traits<const char*>::type(0) == basic_type::Text);
|
||||
REQUIRE(data_type_traits<char*>::type(32) == basic_type::Varchar);
|
||||
REQUIRE(data_type_traits<char*>::type(0) == basic_type::Text);
|
||||
REQUIRE(data_type_traits<char[]>::type(32) == basic_type::Varchar);
|
||||
REQUIRE(data_type_traits<char[]>::type(0) == basic_type::Text);
|
||||
REQUIRE(data_type_traits<std::string>::type(32) == basic_type::Varchar);
|
||||
REQUIRE(data_type_traits<std::string>::type(0) == basic_type::Text);
|
||||
REQUIRE(data_type_traits<blob>::type(0) == basic_type::Blob);
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ TEST_CASE("Test assign value to identifier", "[identifier][assign]") {
|
|||
REQUIRE(id.is_valid());
|
||||
REQUIRE(id.is_integer());
|
||||
REQUIRE(id.str() == "7");
|
||||
REQUIRE(id.type() == basic_type::type_int32);
|
||||
REQUIRE(id.type() == basic_type::Int32);
|
||||
REQUIRE(id.type_index() == std::type_index(typeid(int)));
|
||||
|
||||
id = std::string{"UniqueId"};
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
|||
auto result = query::create()
|
||||
.table({"person"})
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("age", basic_type::UInt16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key({"id"})
|
||||
|
|
@ -51,10 +51,10 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
|||
auto ctx = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, {255, constraints::Unique}),
|
||||
attribute("age", basic_type::type_uint16),
|
||||
attribute("address", basic_type::type_uint32)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, {255, constraints::Unique}),
|
||||
attribute("age", basic_type::UInt16),
|
||||
attribute("address", basic_type::UInt32)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key({"id"}),
|
||||
|
|
@ -219,9 +219,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create, insert and select a blob column", "
|
|||
auto result = query::create()
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("data", basic_type::type_blob)
|
||||
attribute("id", basic_type::UInt32),
|
||||
attribute("name", basic_type::Varchar, 255),
|
||||
attribute("data", basic_type::Blob)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key({"id"})
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@ TEST_CASE("Test create empty column", "[column]") {
|
|||
attribute c("name");
|
||||
|
||||
REQUIRE(c.name() == "name");
|
||||
REQUIRE(c.type() == basic_type::type_null);
|
||||
REQUIRE(c.type() == basic_type::Null);
|
||||
|
||||
c.change_type<std::string>(255);
|
||||
REQUIRE(c.type() == basic_type::type_varchar);
|
||||
REQUIRE(c.type() == basic_type::Varchar);
|
||||
|
||||
c.change_type<int32_t>(7);
|
||||
REQUIRE(c.type() == basic_type::type_int32);
|
||||
REQUIRE(c.type() == basic_type::Int32);
|
||||
}
|
||||
|
||||
TEST_CASE("Test copy and move column", "[column]") {
|
||||
attribute c(
|
||||
"name",
|
||||
basic_type::type_varchar,
|
||||
basic_type::Varchar,
|
||||
// 2,
|
||||
// std::make_shared<attribute>("author", basic_type::type_uint32, "books", attribute_options{constraints::ForeignKey}),
|
||||
{255, constraints::ForeignKey},
|
||||
|
|
@ -32,7 +32,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
|||
// REQUIRE(c.reference_column());
|
||||
// REQUIRE(c.reference_column()->name() == "author");
|
||||
// REQUIRE(c.reference_column()->table_name() == "books");
|
||||
REQUIRE(c.type() == basic_type::type_varchar);
|
||||
REQUIRE(c.type() == basic_type::Varchar);
|
||||
REQUIRE(c.attributes().size() == 255);
|
||||
|
||||
auto c2 = c;
|
||||
|
|
@ -41,7 +41,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
|||
// REQUIRE(c2.reference_column());
|
||||
// REQUIRE(c2.reference_column()->name() == "author");
|
||||
// REQUIRE(c2.reference_column()->table_name() == "books");
|
||||
REQUIRE(c2.type() == basic_type::type_varchar);
|
||||
REQUIRE(c2.type() == basic_type::Varchar);
|
||||
REQUIRE(c2.attributes().size() == 255);
|
||||
|
||||
auto c3 = std::move(c2);
|
||||
|
|
@ -50,7 +50,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
|||
// REQUIRE(c3.reference_column());
|
||||
// REQUIRE(c3.reference_column()->name() == "author");
|
||||
// REQUIRE(c3.reference_column()->table_name() == "books");
|
||||
REQUIRE(c3.type() == basic_type::type_varchar);
|
||||
REQUIRE(c3.type() == basic_type::Varchar);
|
||||
REQUIRE(c3.attributes().size() == 255);
|
||||
|
||||
REQUIRE(c2.name().empty());
|
||||
|
|
|
|||
Loading…
Reference in New Issue