diff --git a/examples/Sample.h b/examples/Sample.h index 43aa3dc2..01e7d92d 100644 --- a/examples/Sample.h +++ b/examples/Sample.h @@ -3,6 +3,7 @@ #include #include +#include namespace test { @@ -10,9 +11,10 @@ namespace test { struct Id { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "id"; } + static constexpr const char _literal[] = "id"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -25,9 +27,10 @@ namespace test }; struct Name { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "name"; } + static constexpr const char _literal[] = "name"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -40,9 +43,10 @@ namespace test }; struct Feature { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "feature"; } + static constexpr const char _literal[] = "feature"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -60,9 +64,10 @@ namespace test TabPerson_::Name, TabPerson_::Feature> { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "tab_person"; } + static constexpr const char _literal[] = "tab_person"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -76,9 +81,10 @@ namespace test { struct Id { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "id"; } + static constexpr const char _literal[] = "id"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -91,9 +97,10 @@ namespace test }; struct Name { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "name"; } + static constexpr const char _literal[] = "name"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -106,9 +113,10 @@ namespace test }; struct Fatal { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "fatal"; } + static constexpr const char _literal[] = "fatal"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -126,9 +134,10 @@ namespace test TabFeature_::Name, TabFeature_::Fatal> { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "tab_feature"; } + static constexpr const char _literal[] = "tab_feature"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index 22c49dcf..2f5b9c1f 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -41,7 +41,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid argument for an expression alias"); static_assert(not is_alias_t::value, "cannot create an alias of an alias"); - using _name_t = typename AliasProvider::_name_t; + using _alias_t = typename AliasProvider::_alias_t; Expression _expression; }; @@ -57,7 +57,7 @@ namespace sqlpp context << '('; serialize(t._expression, context); context << ") AS "; - context << T::_name_t::_get_name(); + context << name_of::char_ptr(); return context; } }; diff --git a/include/sqlpp11/alias_provider.h b/include/sqlpp11/alias_provider.h index 78dcf1e3..266ec51e 100644 --- a/include/sqlpp11/alias_provider.h +++ b/include/sqlpp11/alias_provider.h @@ -28,13 +28,15 @@ #define SQLPP_ALIAS_PROVIDER_H #include +#include #define SQLPP_ALIAS_PROVIDER(name) \ struct name##_t\ {\ - struct _name_t\ + struct _alias_t\ {\ - static constexpr const char* _get_name() { return #name; }\ + static constexpr const char _literal[] = #name;\ + using _name_t = sqlpp::make_char_sequence;\ template\ struct _member_t\ {\ @@ -55,7 +57,7 @@ namespace sqlpp }; template - struct is_alias_provider_t>::value, void>::type> + struct is_alias_provider_t>::value, void>::type> { static constexpr bool value = true; }; diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index 2cc6d8a8..2941718f 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -28,6 +28,7 @@ #define SQLPP_ANY_H #include +#include #include namespace sqlpp @@ -38,9 +39,10 @@ namespace sqlpp using _traits = make_traits, tag::is_multi_expression>; using _recursive_traits = make_recursive_traits::value, "exists() requires a select expression as argument"); - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "EXISTS"; } + static constexpr const char _literal[] = "exists_"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { diff --git a/include/sqlpp11/field_spec.h b/include/sqlpp11/field_spec.h index c745545f..16540042 100644 --- a/include/sqlpp11/field_spec.h +++ b/include/sqlpp11/field_spec.h @@ -40,7 +40,7 @@ namespace sqlpp >; using _recursive_traits = make_recursive_traits<>; - using _name_t = NameType; + using _alias_t = NameType; }; template @@ -56,7 +56,7 @@ namespace sqlpp static constexpr bool _can_be_null = can_be_null_t::value; static constexpr bool _depends_on_outer_table = detail::make_intersect_set_t, typename Select::_used_outer_tables>::size::value > 0; - using type = field_spec_t, logic::any_t<_can_be_null, _depends_on_outer_table>::value, null_is_trivial_value_t::value>; diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index d5c0cf6f..bbe7d939 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -77,7 +77,7 @@ namespace sqlpp static_assert(is_table_t::value, "invalid table argument in from::add()"); using _known_tables = detail::make_joined_set_t...>; // Hint: Joins contain more than one table using _known_table_names = detail::transform_set_t; - static_assert(not detail::is_element_of::value, "Must not use the same table name twice in from()"); + static_assert(not detail::is_element_of::value, "Must not use the same table name twice in from()"); using _serialize_check = sqlpp::serialize_check_t; _serialize_check::_(); diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 9172cb81..b31dd741 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -31,7 +31,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -129,7 +131,7 @@ namespace sqlpp template constexpr const char* get_sql_name(const T&) { - return T::_name_t::_get_name(); + return name_of::char_ptr(); } diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index 6726f7b5..613b1158 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -28,26 +28,27 @@ #define SQLPP_IN_H #include +#include #include #include #include namespace sqlpp { - template + template struct in_t: - public expression_operators, boolean>, - public alias_operators> + public expression_operators, boolean>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; - static constexpr bool _inverted = not NotInverted; static_assert(sizeof...(Args) > 0, "in() requires at least one argument"); - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return _inverted ? "NOT IN" : "IN"; } + static constexpr const char _literal[] = "in_"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -70,16 +71,16 @@ namespace sqlpp std::tuple _args; }; - template - struct serializer_t> + template + struct serializer_t> { using _serialize_check = serialize_check_of; - using T = in_t; + using T = in_t; static Context& _(const T& t, Context& context) { serialize(t._operand, context); - context << (t._inverted ? " NOT IN(" : " IN("); + context << " IN("; if (sizeof...(Args) == 1) serialize(std::get<0>(t._args), context); // FIXME: this is a bit of a hack until there is a better overall strategy for using braces // see https://github.com/rbock/sqlpp11/issues/18 diff --git a/include/sqlpp11/in_fwd.h b/include/sqlpp11/in_fwd.h index 3b464307..f35552ef 100644 --- a/include/sqlpp11/in_fwd.h +++ b/include/sqlpp11/in_fwd.h @@ -29,8 +29,10 @@ namespace sqlpp { - template + template struct in_t; + template + struct not_in_t; } diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 9e8b81a4..5aa99a33 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -44,7 +44,7 @@ namespace sqlpp struct insert_t: public statement_name_t { using _traits = make_traits; - struct _name_t {}; + struct _alias_t {}; template struct _result_methods_t diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index bcf4055a..78413be7 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -63,7 +63,7 @@ namespace sqlpp using _data_t = into_data_t; - struct _name_t {}; + struct _alias_t {}; // Member implementation with data and methods template diff --git a/include/sqlpp11/is_not_null.h b/include/sqlpp11/is_not_null.h new file mode 100644 index 00000000..3db4f148 --- /dev/null +++ b/include/sqlpp11/is_not_null.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2013-2014, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SQLPP_IS_NOT_NULL_H +#define SQLPP_IS_NOT_NULL_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct is_not_null_t: + public expression_operators, boolean>, + public alias_operators> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + struct _alias_t + { + static constexpr const char _literal[] = "is_not_null_"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T is_not_null; + }; + }; + + is_not_null_t(Operand operand): + _operand(operand) + {} + + is_not_null_t(const is_not_null_t&) = default; + is_not_null_t(is_not_null_t&&) = default; + is_not_null_t& operator=(const is_not_null_t&) = default; + is_not_null_t& operator=(is_not_null_t&&) = default; + ~is_not_null_t() = default; + + Operand _operand; + }; + + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = is_not_null_t; + + static Context& _(const T& t, Context& context) + { + serialize(t._operand, context); + context << " IS NOT NULL"; + return context; + } + }; + +} + +#endif diff --git a/include/sqlpp11/is_null.h b/include/sqlpp11/is_null.h index bca37cf0..f40d7cf5 100644 --- a/include/sqlpp11/is_null.h +++ b/include/sqlpp11/is_null.h @@ -29,27 +29,27 @@ #include #include +#include #include namespace sqlpp { - template + template struct is_null_t: - public expression_operators, boolean>, - public alias_operators> + public expression_operators, boolean>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; - static constexpr bool _inverted = not NotInverted; - - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return _inverted ? "IS NOT NULL" : "IS NULL"; } + static constexpr const char _literal[] = "is_nnull_"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { - T in; + T is_null; }; }; @@ -66,16 +66,16 @@ namespace sqlpp Operand _operand; }; - template - struct serializer_t> + template + struct serializer_t> { using _serialize_check = serialize_check_of; - using T = is_null_t; + using T = is_null_t; static Context& _(const T& t, Context& context) { serialize(t._operand, context); - context << (t._inverted ? " IS NOT NULL" : " IS NULL"); + context << " IS NULL"; return context; } }; diff --git a/include/sqlpp11/is_null_fwd.h b/include/sqlpp11/is_null_fwd.h index 8d53cc01..21db3436 100644 --- a/include/sqlpp11/is_null_fwd.h +++ b/include/sqlpp11/is_null_fwd.h @@ -29,8 +29,10 @@ namespace sqlpp { - template + template struct is_null_t; + template + struct is_not_null_t; } #endif diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index b5bb9101..9ae9940c 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -29,6 +29,7 @@ #include #include +#include #include namespace sqlpp @@ -41,9 +42,10 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits; - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "LIKE"; } + static constexpr const char _literal[] = "like_"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 251d6023..4bba58fc 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -28,6 +28,7 @@ #define SQLPP_MAX_H #include +#include namespace sqlpp { @@ -39,9 +40,10 @@ namespace sqlpp using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _recursive_traits = make_recursive_traits; - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "MAX"; } + static constexpr const char _literal[] = "max_"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 04bb30cf..2077ae4c 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -28,6 +28,7 @@ #define SQLPP_MIN_H #include +#include namespace sqlpp { @@ -39,9 +40,10 @@ namespace sqlpp using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _recursive_traits = make_recursive_traits; - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "MIN"; } + static constexpr const char _literal[] = "min_"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 24d300c4..70dbec66 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -77,7 +77,7 @@ namespace sqlpp static_assert(logic::all_t::value...>::value, "multi_column parameters need to be named expressions"); - using _name_t = typename AliasProvider::_name_t; + using _alias_t = typename AliasProvider::_alias_t; multi_column_alias_t(multi_column_t multi_column): _columns(multi_column._columns) diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index 3ec6c1ea..6ebacd04 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace sqlpp { @@ -111,7 +112,7 @@ namespace sqlpp std::string _get_name() const { - return T::_name_t::_get_name(); + return name_of::char_ptr(); } T _t; diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index 62f3b7db..dfa2c2ff 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -39,7 +39,7 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; - struct _name_t {}; + struct _alias_t {}; template struct _result_methods_t diff --git a/include/sqlpp11/not_in.h b/include/sqlpp11/not_in.h new file mode 100644 index 00000000..0aa47547 --- /dev/null +++ b/include/sqlpp11/not_in.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2013-2014, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SQLPP_NOT_IN_H +#define SQLPP_NOT_IN_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct not_in_t: + public expression_operators, boolean>, + public alias_operators> + { + using _traits = make_traits; + using _recursive_traits = make_recursive_traits; + + static_assert(sizeof...(Args) > 0, "not_in() requires at least one argument"); + + struct _alias_t + { + static constexpr const char _literal[] = "not_in_"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t + { + T not_in; + }; + }; + + not_in_t(Operand operand, Args... args): + _operand(operand), + _args(args...) + {} + + not_in_t(const not_in_t&) = default; + not_in_t(not_in_t&&) = default; + not_in_t& operator=(const not_in_t&) = default; + not_in_t& operator=(not_in_t&&) = default; + ~not_in_t() = default; + + Operand _operand; + std::tuple _args; + }; + + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = not_in_t; + + static Context& _(const T& t, Context& context) + { + serialize(t._operand, context); + context << " NOT IN("; + if (sizeof...(Args) == 1) + serialize(std::get<0>(t._args), context); // FIXME: this is a bit of a hack until there is a better overall strategy for using braces + // see https://github.com/rbock/sqlpp11/issues/18 + else + interpret_tuple(t._args, ',', context); + context << ')'; + return context; + } + }; + +} + +#endif diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 8d5f43be..e9337e14 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -44,7 +44,7 @@ namespace sqlpp struct remove_t: public statement_name_t { using _traits = make_traits; - struct _name_t {}; + struct _alias_t {}; template struct _result_methods_t diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 60528ed0..f9e21fcf 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -186,7 +186,7 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; - struct _name_t {}; + struct _alias_t {}; }; using _field_type = result_field_t; diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 84341eb4..eedf03e3 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -48,14 +48,14 @@ namespace sqlpp struct select_traits { using _traits = make_traits; - struct _name_t {}; + struct _alias_t {}; }; template struct select_traits { using _traits = make_traits, tag::is_select_column_list, tag::is_return_value, tag::is_expression, tag::is_selectable>; - using _name_t = typename Column::_name_t; + using _alias_t = typename Column::_alias_t; }; } @@ -69,7 +69,7 @@ namespace sqlpp template void emplace_back(Expr expr) { - _dynamic_expression_names.push_back(Expr::_name_t::_get_name()); + _dynamic_expression_names.push_back(name_of::char_ptr()); _dynamic_columns.emplace_back(expr); } @@ -166,7 +166,7 @@ namespace sqlpp using _traits = typename detail::select_traits::_traits; using _recursive_traits = make_recursive_traits; - using _name_t = typename detail::select_traits::_name_t; + using _alias_t = typename detail::select_traits::_alias_t; using _is_dynamic = is_database; @@ -191,8 +191,8 @@ namespace sqlpp static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); static_assert(is_selectable_t::value, "invalid named expression argument in selected_columns::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in selected_columns::add()"); - using column_names = detail::make_type_set_t; - static_assert(not detail::is_element_of::value, "a column of this name is present in the select already"); + using column_names = detail::make_type_set_t; + static_assert(not detail::is_element_of::value, "a column of this name is present in the select already"); using _serialize_check = sqlpp::serialize_check_t; _serialize_check::_(); @@ -351,7 +351,7 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; - struct _name_t {}; + struct _alias_t {}; // Data using _data_t = no_data_t; @@ -431,7 +431,7 @@ namespace sqlpp -> _new_statement_t<_check, select_column_list_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected"); - static_assert(not detail::has_duplicates::value, "at least one duplicate name detected"); + static_assert(not detail::has_duplicates::value, "at least one duplicate name detected"); return { static_cast&>(*this), typename select_column_list_t::_data_t{args} }; } diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index 28429e5f..7e50d87a 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -35,7 +35,7 @@ namespace sqlpp template struct select_column_spec_t { - using _name_t = typename NamedExpr::_name_t; + using _alias_t = typename NamedExpr::_alias_t; static constexpr bool _can_be_null = can_be_null_t::value; static constexpr bool _depends_on_outer_table = detail::make_intersect_set_t, typename Select::_used_outer_tables>::size::value > 0; diff --git a/include/sqlpp11/simple_column.h b/include/sqlpp11/simple_column.h index 7bd0c02e..e9cff94f 100644 --- a/include/sqlpp11/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -35,7 +35,8 @@ namespace sqlpp template struct simple_column_t { - Column _column; + using _column_t = Column; + _column_t _column; using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; @@ -49,7 +50,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - context << t._column._get_name(); + context << name_of::char_ptr(); return context; } }; diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 1b8839a9..fe4efefa 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -65,7 +65,7 @@ namespace sqlpp using _data_t = single_table_data_t; - struct _name_t {}; + struct _alias_t {}; // Member implementation with data and methods template diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index d457680d..04f351fe 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -29,6 +29,7 @@ #include #include +#include namespace sqlpp { @@ -38,9 +39,10 @@ namespace sqlpp using _traits = make_traits, tag::is_multi_expression>; using _recursive_traits = make_recursive_traits
::size::value == 0, "table aliases must not depend on external tables"); - using _name_t = typename AliasProvider::_name_t; + using _alias_t = typename AliasProvider::_alias_t; using _column_tuple_t = std::tuple...>; table_alias_t(Table table): @@ -74,7 +74,7 @@ namespace sqlpp { context << "("; serialize(t._table, context); - context << ") AS " << T::_name_t::_get_name(); + context << ") AS " << name_of::char_ptr(); return context; } }; diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index ec1510bb..e1980ec0 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -201,7 +201,10 @@ namespace sqlpp using recursive_tags_of = typename T::_recursive_traits::_tags; template - using name_of = typename T::_name_t; + using alias_of = typename T::_alias_t; + + template + using name_of = typename T::_alias_t::_name_t; template struct make_traits @@ -239,7 +242,7 @@ namespace sqlpp }; template - using member_t = typename NameProvider::_name_t::template _member_t; + using member_t = typename NameProvider::_alias_t::template _member_t; template using derived_statement_t = typename Policies::_statement_t; diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 7e1058f6..b24a81fc 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -44,7 +44,7 @@ namespace sqlpp struct update_t: public statement_name_t { using _traits = make_traits; - struct _name_t {}; + struct _alias_t {}; template struct _result_methods_t diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index a58a7e56..275061b6 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -35,8 +35,10 @@ namespace sqlpp { struct unusable_pseudo_column_t { - struct _name_t + struct _alias_t { + static constexpr const char _literal[] = "pseudo_column"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -53,7 +55,11 @@ namespace sqlpp using _provided_outer_tables = detail::type_set; }; - struct _name_t {}; + struct _alias_t + { + static constexpr const char _literal[] = "verbatim_table"; // FIXME need to use alias for verbatim table + using _name_t = sqlpp::make_char_sequence; + }; verbatim_table_t(std::string representation): _representation(representation) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index dd09cf86..67d885ee 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -118,6 +118,7 @@ print('#define '+get_include_guard_name(namespace, pathToHeader), file=header) print('', file=header) print('#include <' + INCLUDE + '/table.h>', file=header) print('#include <' + INCLUDE + '/column_types.h>', file=header) +print('#include <' + INCLUDE + '/char_sequence.h>', file=header) print('', file=header) print('namespace ' + namespace, file=header) print('{', file=header) @@ -143,9 +144,10 @@ for tableCreation in tableCreations: columnCanBeNull = not column.notNull print(' struct ' + columnClass, file=header) print(' {', file=header) - print(' struct _name_t', file=header) + print(' struct _alias_t', file=header) print(' {', file=header) - print(' static constexpr const char* _get_name() { return "' + sqlColumnName + '"; }', file=header) + print(' static constexpr const char _literal[] = "' + sqlColumnName + '";', file=header) + print(' using _name_t = sqlpp::make_char_sequence;', file=header) print(' template', file=header) print(' struct _member_t', file=header) print(' {', file=header) @@ -154,7 +156,6 @@ for tableCreation in tableCreations: print(' const T& operator()() const { return ' + columnMember + '; }', file=header) print(' };', file=header) print(' };', file=header) - #print(sqlColumnType) traitslist = [NAMESPACE + '::' + types[sqlColumnType]]; requireInsert = True if column.hasAutoValue: @@ -175,9 +176,10 @@ for tableCreation in tableCreations: print(' struct ' + tableClass + ': ' + NAMESPACE + '::table_t<' + tableTemplateParameters + '>', file=header) print(' {', file=header) - print(' struct _name_t', file=header) + print(' struct _alias_t', file=header) print(' {', file=header) - print(' static constexpr const char* _get_name() { return "' + sqlTableName + '"; }', file=header) + print(' static constexpr const char _literal[] = "' + sqlTableName + '";', file=header) + print(' using _name_t = sqlpp::make_char_sequence;', file=header) print(' template', file=header) print(' struct _member_t', file=header) print(' {', file=header) diff --git a/tests/Sample.h b/tests/Sample.h index 5f1bf1de..2fa909e5 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -3,6 +3,7 @@ #include #include +#include namespace test { @@ -10,9 +11,10 @@ namespace test { struct Delta { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "delta"; } + static constexpr const char _literal[] = "delta"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -25,9 +27,10 @@ namespace test }; struct Epsilon { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "epsilon"; } + static constexpr const char _literal[] = "epsilon"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -40,9 +43,10 @@ namespace test }; struct Omega { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "omega"; } + static constexpr const char _literal[] = "omega"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -60,9 +64,10 @@ namespace test TabFoo_::Epsilon, TabFoo_::Omega> { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "tab_foo"; } + static constexpr const char _literal[] = "tab_foo"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -76,9 +81,10 @@ namespace test { struct Alpha { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "alpha"; } + static constexpr const char _literal[] = "alpha"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -91,9 +97,10 @@ namespace test }; struct Beta { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "beta"; } + static constexpr const char _literal[] = "beta"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -106,9 +113,10 @@ namespace test }; struct Gamma { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "gamma"; } + static constexpr const char _literal[] = "gamma"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -121,9 +129,10 @@ namespace test }; struct Delta { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "delta"; } + static constexpr const char _literal[] = "delta"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { @@ -142,9 +151,10 @@ namespace test TabBar_::Gamma, TabBar_::Delta> { - struct _name_t + struct _alias_t { - static constexpr const char* _get_name() { return "tab_bar"; } + static constexpr const char _literal[] = "tab_bar"; + using _name_t = sqlpp::make_char_sequence; template struct _member_t { diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 76138240..1ff66977 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -41,7 +41,6 @@ int main() test::TabFoo f; test::TabBar t; - select(t.alpha).flags(sqlpp::all).from(t); for (const auto& row : db(select(all_of(t)).from(t).where(true))) { int64_t a = row.alpha;