diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 39a2c214..b69bcecd 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -77,13 +77,15 @@ namespace sqlpp template struct join_t { - static_assert(is_table_t::value, "invalid lhs argument for join()"); - static_assert(is_table_t::value, "invalid rhs argument for join()"); + static_assert(is_table_t::value, "lhs argument for join() has to be a table or join"); + static_assert(is_table_t::value, "rhs argument for join() has to be a table"); + static_assert(not is_join_t::value, "rhs argument for join must not be a join"); static_assert(vendor::is_noop::value or is_on_t::value, "invalid on expression in join().on()"); static_assert(Lhs::_table_set::template is_disjunct_from::value, "joined tables must not be identical"); using _is_table = std::true_type; + using _is_join = std::true_type; using _table_set = typename Lhs::_table_set::template join::type; template @@ -140,7 +142,6 @@ namespace sqlpp On _on; }; - // FIXME: Need to check if db supports the join type. e.g. sqlite does not support right outer or full outer join namespace vendor { template @@ -154,9 +155,7 @@ namespace sqlpp interpret(t._lhs, context); context << JoinType::_name; context << " JOIN "; - context << "("; interpret(t._rhs, context); - context << ")"; interpret(t._on, context); return context; } diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index b0c3708d..1234b099 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -94,6 +94,7 @@ namespace sqlpp SQLPP_IS_COLUMN_TRAIT_GENERATOR(can_be_null); SQLPP_TYPE_TRAIT_GENERATOR(is_table); + SQLPP_TYPE_TRAIT_GENERATOR(is_join); SQLPP_TYPE_TRAIT_GENERATOR(is_pseudo_table); SQLPP_TYPE_TRAIT_GENERATOR(is_column); SQLPP_TYPE_TRAIT_GENERATOR(is_select); diff --git a/include/sqlpp11/vendor/assignment.h b/include/sqlpp11/vendor/assignment.h index 3b5061c4..5d2cfc67 100644 --- a/include/sqlpp11/vendor/assignment.h +++ b/include/sqlpp11/vendor/assignment.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace sqlpp { @@ -68,7 +69,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - interpret(t._lhs, context); + interpret(simple_column(t._lhs), context); context << "="; interpret(t._rhs, context); return context; @@ -107,7 +108,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - interpret(t._lhs, context); + interpret(simple_column(t._lhs), context); if (t._rhs._value._is_trivial()) { context << "=NULL"; diff --git a/include/sqlpp11/vendor/insert_list.h b/include/sqlpp11/vendor/insert_list.h index 23dd989c..0a85e995 100644 --- a/include/sqlpp11/vendor/insert_list.h +++ b/include/sqlpp11/vendor/insert_list.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace sqlpp { @@ -54,25 +55,6 @@ namespace sqlpp } }; - template - struct insert_column_t - { - Column _column; - }; - - template - struct interpreter_t> - { - using T = insert_column_t; - - static Context& _(const T& t, Context& context) - { - context << t._column._get_name(); - return context; - } - }; - - template struct insert_list_t { @@ -110,12 +92,12 @@ namespace sqlpp { static_assert(is_assignment_t::type>::value, "set() arguments require to be assigments"); static_assert(not must_not_insert_t::type>::value, "set() argument must not be used in insert"); - _dynamic_columns.emplace_back(insert_column_t{std::forward(assignment._lhs)}); + _dynamic_columns.emplace_back(simple_column_t{std::forward(assignment._lhs)}); _dynamic_values.emplace_back(std::forward(assignment._rhs)); } - std::tuple...> _columns; + std::tuple...> _columns; std::tuple _values; typename vendor::interpretable_list_t _dynamic_columns; typename vendor::interpretable_list_t _dynamic_values; diff --git a/include/sqlpp11/vendor/simple_column.h b/include/sqlpp11/vendor/simple_column.h new file mode 100644 index 00000000..ccc6f09a --- /dev/null +++ b/include/sqlpp11/vendor/simple_column.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, 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_SIMPLE_COLUMN_H +#define SQLPP_SIMPLE_COLUMN_H + +#include + +namespace sqlpp +{ + namespace vendor + { + template + struct simple_column_t + { + Column _column; + }; + + template + struct interpreter_t> + { + using T = simple_column_t; + + static Context& _(const T& t, Context& context) + { + context << t._column._get_name(); + return context; + } + }; + + template + simple_column_t simple_column(Column c) + { + return {c}; + } + } +} + +#endif