diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 669b49bb..653b0d01 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -36,116 +36,111 @@ namespace sqlpp { - // boolean operators - namespace detail + // boolean value type + struct boolean { - // boolean value type - struct boolean + using _traits = make_traits; + using _tag = ::sqlpp::tag::is_boolean; + using _cpp_value_type = bool; + + struct _parameter_t { - using _traits = make_traits; - using _tag = ::sqlpp::tag::is_boolean; - using _cpp_value_type = bool; + using _value_type = boolean; // FIXME - struct _parameter_t + _parameter_t(): + _value(false), + _is_null(true) + {} + + _parameter_t(const _cpp_value_type& value): + _value(value), + _is_null(false) + {} + + _parameter_t& operator=(const _cpp_value_type& value) { - using _value_type = boolean; // FIXME + _value = value; + _is_null = (false); + return *this; + } - _parameter_t(): - _value(false), - _is_null(true) - {} - - _parameter_t(const _cpp_value_type& value): - _value(value), - _is_null(false) - {} - - _parameter_t& operator=(const _cpp_value_type& value) - { - _value = value; - _is_null = (false); - return *this; - } - - _parameter_t& operator=(const std::nullptr_t&) - { - _value = false; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - _cpp_value_type value() const - { - return _value; - } - - operator _cpp_value_type() const { return value(); } - - template - void _bind(Target& target, size_t index) const - { - target._bind_boolean_parameter(index, &_value, _is_null); - } - - private: - signed char _value; - bool _is_null; - }; - - template - struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_boolean_t::value // the correct value type is required, of course - ; - }; - - template - struct expression_operators: public basic_expression_operators + _parameter_t& operator=(const std::nullptr_t&) { - template - logical_and_t> operator and(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + _value = false; + _is_null = true; + return *this; + } - return { *static_cast(this), rhs{t} }; - } + bool is_null() const + { + return _is_null; + } - template - logical_or_t> operator or(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + _cpp_value_type value() const + { + return _value; + } - return { *static_cast(this), rhs{t} }; - } + operator _cpp_value_type() const { return value(); } - logical_not_t operator not() const + template + void _bind(Target& target, size_t index) const { - return { *static_cast(this) }; + target._bind_boolean_parameter(index, &_value, _is_null); } - }; - template - struct column_operators - { - }; + private: + signed char _value; + bool _is_null; }; - } + template + struct _is_valid_operand + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_boolean_t::value // the correct value type is required, of course + ; + }; + + template + struct expression_operators: public basic_expression_operators + { + template + logical_and_t> operator and(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), rhs{t} }; + } + + template + logical_or_t> operator or(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), rhs{t} }; + } + + logical_not_t operator not() const + { + return { *static_cast(this) }; + } + }; + + template + struct column_operators + { + }; + }; template - struct result_field_t: public result_field_methods_t> + struct result_field_t: public result_field_methods_t> { - static_assert(std::is_same, detail::boolean>::value, "field type mismatch"); - using _cpp_value_type = typename detail::boolean::_cpp_value_type; + static_assert(std::is_same, boolean>::value, "field type mismatch"); + using _cpp_value_type = typename boolean::_cpp_value_type; result_field_t(): _is_valid(false), @@ -212,12 +207,10 @@ namespace sqlpp }; template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) { return serialize(e, os); } - using boolean = detail::boolean; - } #endif diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index a2970de1..814dcf22 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -33,10 +33,10 @@ namespace sqlpp { template - struct count_t: public sqlpp::detail::integral::template expression_operators>, + struct count_t: public sqlpp::integral::template expression_operators>, public alias_operators> { - using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; + using _traits = make_traits<::sqlpp::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; using _recursive_traits = make_recursive_traits; static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index cb221ccd..22c6c92b 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -40,7 +40,7 @@ namespace sqlpp { template - struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, + struct binary_expression_t: public ::sqlpp::boolean::template expression_operators>, public alias_operators> { using _traits = make_traits; @@ -88,7 +88,7 @@ namespace sqlpp }; template - struct binary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, + struct binary_expression_t: public ::sqlpp::boolean::template expression_operators>, public alias_operators> { using _traits = make_traits; @@ -136,7 +136,7 @@ namespace sqlpp }; template - struct unary_expression_t: public ::sqlpp::detail::boolean::template expression_operators>, + struct unary_expression_t: public ::sqlpp::boolean::template expression_operators>, public alias_operators> { using _traits = make_traits; diff --git a/include/sqlpp11/expression_fwd.h b/include/sqlpp11/expression_fwd.h index 2a389e5b..71958635 100644 --- a/include/sqlpp11/expression_fwd.h +++ b/include/sqlpp11/expression_fwd.h @@ -29,64 +29,61 @@ namespace sqlpp { - namespace detail - { - struct boolean; - struct integral; - struct floating_point; - } + struct boolean; + struct integral; + struct floating_point; namespace op { struct less { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; static constexpr const char* _name = "<"; }; struct less_equal { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; static constexpr const char* _name = "<="; }; struct equal_to { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; }; struct not_equal_to { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; }; struct greater_equal { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; static constexpr const char* _name = ">="; }; struct greater { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; static constexpr const char* _name = ">"; }; struct logical_or { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; static constexpr const char* _name = " OR "; }; struct logical_and { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; static constexpr const char* _name = " AND "; }; struct logical_not { - using _traits = make_traits<::sqlpp::detail::boolean>; + using _traits = make_traits<::sqlpp::boolean>; }; template @@ -112,13 +109,13 @@ namespace sqlpp struct divides { - using _traits = make_traits<::sqlpp::detail::floating_point>; + using _traits = make_traits<::sqlpp::floating_point>; static constexpr const char* _name = "/"; }; struct modulus { - using _traits = make_traits<::sqlpp::detail::integral>; + using _traits = make_traits<::sqlpp::integral>; static constexpr const char* _name = "%"; }; diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 683ae1f9..12bb9979 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -35,195 +35,190 @@ namespace sqlpp { - namespace detail + // floating_point value type + struct floating_point { + using _traits = make_traits; + using _tag = ::sqlpp::tag::is_floating_point; + using _cpp_value_type = double; - // floating_point value type - struct floating_point + struct _parameter_t { - using _traits = make_traits; - using _tag = ::sqlpp::tag::is_floating_point; - using _cpp_value_type = double; + using _value_type = floating_point; - struct _parameter_t + _parameter_t(): + _value(0), + _is_null(true) + {} + + _parameter_t(const _cpp_value_type& value): + _value(value), + _is_null(false) + {} + + _parameter_t& operator=(const _cpp_value_type& value) { - using _value_type = floating_point; + _value = value; + _is_null = false; + return *this; + } - _parameter_t(): - _value(0), - _is_null(true) - {} - - _parameter_t(const _cpp_value_type& value): - _value(value), - _is_null(false) - {} - - _parameter_t& operator=(const _cpp_value_type& value) - { - _value = value; - _is_null = false; - return *this; - } - - _parameter_t& operator=(const std::nullptr_t&) - { - _value = 0; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - const _cpp_value_type& value() const - { - return _value; - } - - operator _cpp_value_type() const { return _value; } - - template - void _bind(Target& target, size_t index) const - { - target._bind_floating_point_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - template - struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_numeric_t::value // the correct value type is required, of course - ; - }; - - template - struct expression_operators: public basic_expression_operators + _parameter_t& operator=(const std::nullptr_t&) { - template - plus_t> operator +(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + _value = 0; + _is_null = true; + return *this; + } - return { *static_cast(this), rhs{t} }; - } + bool is_null() const + { + return _is_null; + } - template - minus_t> operator -(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + const _cpp_value_type& value() const + { + return _value; + } - return { *static_cast(this), rhs{t} }; - } + operator _cpp_value_type() const { return _value; } - template - multiplies_t> operator *(T t) const - { - using rhs = wrap_operand_t; - - return { *static_cast(this), rhs{t} }; - } - - template - divides_t> operator /(T t) const - { - using rhs = wrap_operand_t; - - return { *static_cast(this), rhs{t} }; - } - - unary_plus_t operator +() const + template + void _bind(Target& target, size_t index) const { - return { *static_cast(this) }; + target._bind_floating_point_parameter(index, &_value, _is_null); } - unary_minus_t operator -() const - { - return { *static_cast(this) }; - } - }; - - template - struct column_operators - { - template - auto operator +=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - - template - auto operator -=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - - template - auto operator /=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - - template - auto operator *=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - }; + private: + _cpp_value_type _value; + bool _is_null; }; - } + template + struct _is_valid_operand + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_numeric_t::value // the correct value type is required, of course + ; + }; + + template + struct expression_operators: public basic_expression_operators + { + template + plus_t> operator +(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), rhs{t} }; + } + + template + minus_t> operator -(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), rhs{t} }; + } + + template + multiplies_t> operator *(T t) const + { + using rhs = wrap_operand_t; + + return { *static_cast(this), rhs{t} }; + } + + template + divides_t> operator /(T t) const + { + using rhs = wrap_operand_t; + + return { *static_cast(this), rhs{t} }; + } + + unary_plus_t operator +() const + { + return { *static_cast(this) }; + } + + unary_minus_t operator -() const + { + return { *static_cast(this) }; + } + }; + + template + struct column_operators + { + template + auto operator +=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + + template + auto operator -=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + + template + auto operator /=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + + template + auto operator *=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + }; + }; template - struct result_field_t: public result_field_methods_t> - { - static_assert(std::is_same, detail::floating_point>::value, "field type mismatch"); - using _cpp_value_type = typename detail::floating_point::_cpp_value_type; - - result_field_t(): - _is_valid(false), - _is_null(true), - _value(0) - {} - - void _validate() + struct result_field_t: public result_field_methods_t> { - _is_valid = true; - } + static_assert(std::is_same, floating_point>::value, "field type mismatch"); + using _cpp_value_type = typename floating_point::_cpp_value_type; - void _invalidate() - { - _is_valid = false; - _is_null = true; - _value = 0; - } + result_field_t(): + _is_valid(false), + _is_null(true), + _value(0) + {} - bool is_null() const - { - if (not _is_valid) - throw exception("accessing is_null in non-existing row"); + void _validate() + { + _is_valid = true; + } + + void _invalidate() + { + _is_valid = false; + _is_null = true; + _value = 0; + } + + bool is_null() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); return _is_null; } @@ -267,13 +262,10 @@ namespace sqlpp }; template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) { return serialize(e, os); } - - using floating_point = detail::floating_point; - } #endif diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 24b9ebe1..8c6ae5ec 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -37,182 +37,178 @@ namespace sqlpp { - namespace detail + // integral value type + struct integral { + using _traits = make_traits; + using _tag = ::sqlpp::tag::is_integral; + using _cpp_value_type = int64_t; - // integral value type - struct integral + struct _parameter_t { - using _traits = make_traits; - using _tag = ::sqlpp::tag::is_integral; - using _cpp_value_type = int64_t; + using _value_type = integral; - struct _parameter_t + _parameter_t(): + _value(0), + _is_null(true) + {} + + explicit _parameter_t(const _cpp_value_type& value): + _value(value), + _is_null(false) + {} + + _parameter_t& operator=(const _cpp_value_type& value) { - using _value_type = integral; + _value = value; + _is_null = false; + return *this; + } - _parameter_t(): - _value(0), - _is_null(true) - {} - - explicit _parameter_t(const _cpp_value_type& value): - _value(value), - _is_null(false) - {} - - _parameter_t& operator=(const _cpp_value_type& value) - { - _value = value; - _is_null = false; - return *this; - } - - void set_null() - { - _value = 0; - _is_null = true; - } - - bool is_null() const - { - return _is_null; - } - - const _cpp_value_type& value() const - { - return _value; - } - - operator _cpp_value_type() const { return _value; } - - template - void _bind(Target& target, size_t index) const - { - target._bind_integral_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - template - struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_numeric_t::value // the correct value type is required, of course - ; - }; - - template - struct expression_operators: public basic_expression_operators + void set_null() { - template - plus_t, wrap_operand_t> operator +(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + _value = 0; + _is_null = true; + } - return { *static_cast(this), {t} }; - } + bool is_null() const + { + return _is_null; + } - template - minus_t, wrap_operand_t> operator -(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + const _cpp_value_type& value() const + { + return _value; + } - return { *static_cast(this), {t} }; - } + operator _cpp_value_type() const { return _value; } - template - multiplies_t, wrap_operand_t> operator *(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return { *static_cast(this), {t} }; - } - - template - divides_t> operator /(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return { *static_cast(this), {t} }; - } - - template - modulus_t> operator %(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return { *static_cast(this), {t} }; - } - - unary_plus_t operator +() const + template + void _bind(Target& target, size_t index) const { - return { *static_cast(this) }; + target._bind_integral_parameter(index, &_value, _is_null); } - unary_minus_t operator -() const - { - return { *static_cast(this) }; - } - }; - - template - struct column_operators - { - template - auto operator +=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - - template - auto operator -=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - - template - auto operator /=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - - template - auto operator *=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - }; + private: + _cpp_value_type _value; + bool _is_null; }; - } + template + struct _is_valid_operand + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_numeric_t::value // the correct value type is required, of course + ; + }; + + template + struct expression_operators: public basic_expression_operators + { + template + plus_t, wrap_operand_t> operator +(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), {t} }; + } + + template + minus_t, wrap_operand_t> operator -(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), {t} }; + } + + template + multiplies_t, wrap_operand_t> operator *(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), {t} }; + } + + template + divides_t> operator /(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), {t} }; + } + + template + modulus_t> operator %(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), {t} }; + } + + unary_plus_t operator +() const + { + return { *static_cast(this) }; + } + + unary_minus_t operator -() const + { + return { *static_cast(this) }; + } + }; + + template + struct column_operators + { + template + auto operator +=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + + template + auto operator -=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + + template + auto operator /=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + + template + auto operator *=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + }; + }; + template - struct result_field_t: public result_field_methods_t> + struct result_field_t: public result_field_methods_t> { - static_assert(std::is_same, detail::integral>::value, "field type mismatch"); - using _cpp_value_type = typename detail::integral::_cpp_value_type; + static_assert(std::is_same, integral>::value, "field type mismatch"); + using _cpp_value_type = typename integral::_cpp_value_type; result_field_t(): _is_valid(false), @@ -279,15 +275,15 @@ namespace sqlpp }; template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) { return serialize(e, os); } - using tinyint = detail::integral; - using smallint = detail::integral; - using integer = detail::integral; - using bigint = detail::integral; + using tinyint = integral; + using smallint = integral; + using integer = integral; + using bigint = integral; } #endif diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 3ab024a0..676a8eef 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -184,12 +184,12 @@ namespace sqlpp using _impl = detail::result_row_impl, FieldSpecs...>; struct _field_spec_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; struct _name_t {}; }; - using _field_type = result_field_t; + using _field_type = result_field_t; static constexpr size_t _last_static_index = _impl::_last_index; bool _is_valid; diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 85201f33..6c87e845 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -36,119 +36,115 @@ namespace sqlpp { - namespace detail + // text value type + struct text { - // text value type - struct text + using _traits = make_traits; + using _tag = ::sqlpp::tag::is_text; + using _cpp_value_type = std::string; + + struct _parameter_t { - using _traits = make_traits; - using _tag = ::sqlpp::tag::is_text; - using _cpp_value_type = std::string; + using _value_type = text; - struct _parameter_t + _parameter_t(): + _value(""), + _is_null(true) + {} + + _parameter_t(const _cpp_value_type& value): + _value(value), + _is_null(false) + {} + + _parameter_t& operator=(const _cpp_value_type& value) { - using _value_type = text; + _value = value; + _is_null = false; + return *this; + } - _parameter_t(): - _value(""), - _is_null(true) - {} - - _parameter_t(const _cpp_value_type& value): - _value(value), - _is_null(false) - {} - - _parameter_t& operator=(const _cpp_value_type& value) - { - _value = value; - _is_null = false; - return *this; - } - - _parameter_t& operator=(const std::nullptr_t&) - { - _value = ""; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - _cpp_value_type value() const - { - return _value; - } - - operator _cpp_value_type() const { return value(); } - - template - void _bind(Target& target, size_t index) const - { - target._bind_text_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - - template - struct _is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_text_t::value // the correct value type is required, of course - ; - }; - - template - struct expression_operators: public basic_expression_operators + _parameter_t& operator=(const std::nullptr_t&) { - template - concat_t> operator+(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + _value = ""; + _is_null = true; + return *this; + } - return { *static_cast(this), {t} }; - } + bool is_null() const + { + return _is_null; + } - template - like_t> like(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid argument for like()"); + _cpp_value_type value() const + { + return _value; + } - return { *static_cast(this), {t} }; - } - }; + operator _cpp_value_type() const { return value(); } - template - struct column_operators + template + void _bind(Target& target, size_t index) const { - template - auto operator +=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + target._bind_text_parameter(index, &_value, _is_null); + } - return { *static_cast(this), { *static_cast(this), rhs{t} } }; - } - }; + private: + _cpp_value_type _value; + bool _is_null; }; - } + + template + struct _is_valid_operand + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and is_text_t::value // the correct value type is required, of course + ; + }; + + template + struct expression_operators: public basic_expression_operators + { + template + concat_t> operator+(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return { *static_cast(this), {t} }; + } + + template + like_t> like(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid argument for like()"); + + return { *static_cast(this), {t} }; + } + }; + + template + struct column_operators + { + template + auto operator +=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return { *static_cast(this), { *static_cast(this), rhs{t} } }; + } + }; + }; template - struct result_field_t: public result_field_methods_t> + struct result_field_t: public result_field_methods_t> { - static_assert(std::is_same, detail::text>::value, "field type mismatch"); - using _cpp_value_type = typename detail::text::_cpp_value_type; + static_assert(std::is_same, text>::value, "field type mismatch"); + using _cpp_value_type = typename text::_cpp_value_type; result_field_t(): _is_valid(false), @@ -218,9 +214,9 @@ namespace sqlpp }; template - struct serializer_t> + struct serializer_t> { - using T = result_field_t; + using T = result_field_t; static Context& _(const T& t, Context& context) { @@ -237,7 +233,7 @@ namespace sqlpp }; template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) { if (e.is_null() and not null_is_trivial_value_t::value) { @@ -250,10 +246,9 @@ namespace sqlpp return serialize(e, os); } - using text = detail::text; - using blob = detail::text; - using varchar = detail::text; - using char_ = detail::text; + using blob = text; + using varchar = text; + using char_ = text; } #endif diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index b6926055..ffab6e94 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -33,17 +33,14 @@ namespace sqlpp { - namespace detail - { - struct boolean; - struct integral; - struct floating_point; - struct text; - } + struct boolean; + struct integral; + struct floating_point; + struct text; struct boolean_operand { - using _traits = make_traits<::sqlpp::detail::boolean, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits<::sqlpp::boolean, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = bool; @@ -81,7 +78,7 @@ namespace sqlpp struct integral_operand { - using _traits = make_traits<::sqlpp::detail::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits<::sqlpp::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = int64_t; @@ -120,7 +117,7 @@ namespace sqlpp struct floating_point_operand { - using _traits = make_traits<::sqlpp::detail::floating_point, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits<::sqlpp::floating_point, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = double; @@ -158,7 +155,7 @@ namespace sqlpp struct text_operand { - using _traits = make_traits<::sqlpp::detail::text, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits<::sqlpp::text, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = std::string; diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index ea62ace4..b927e239 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -101,7 +101,7 @@ int main() // functions serialize(sqlpp::value(7), printer).str(); - serialize(sqlpp::verbatim("irgendwas integrales"), printer).str(); + serialize(sqlpp::verbatim("irgendwas integrales"), printer).str(); serialize(sqlpp::value_list(std::vector({1,2,3,4,5,6,8})), printer).str(); serialize(exists(select(t.alpha).from(t)), printer).str(); serialize(any(select(t.alpha).from(t)), printer).str();