diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 95c334bb..06193dab 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -84,6 +84,14 @@ namespace sqlpp return { *this, {t} }; } + template + auto operator =(T t) const + -> typename std::enable_if::type>::value and not std::is_same::value), + vendor::assignment_t::type>>::type + { + static_assert(sqlpp::vendor::wrong_t::value, "invalid assignment operand"); + } + auto operator =(sqlpp::null_t) const ->vendor::assignment_t { diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 0afcb168..aa5e5983 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -475,7 +475,7 @@ namespace sqlpp const _dynamic_names_t& get_dynamic_names() const { - return _column_list_t::_dynamic_columns._dynamic_expression_names; + return _column_list._dynamic_columns._dynamic_expression_names; } static constexpr size_t _get_static_no_of_parameters() diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index f7d535ea..33ad3f75 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -179,6 +179,12 @@ namespace sqlpp return { *static_cast(this), {t} }; } + template + auto operator +=(T t) const -> decltype(std::declval() = std::declval() + t) + { + return *static_cast(this) = operator +(t); + } + template vendor::like_t::type> like(T t) const { diff --git a/include/sqlpp11/vendor/insert_value_list.h b/include/sqlpp11/vendor/insert_value_list.h index 5fb1239c..9959c823 100644 --- a/include/sqlpp11/vendor/insert_value_list.h +++ b/include/sqlpp11/vendor/insert_value_list.h @@ -157,9 +157,7 @@ namespace sqlpp } template - void add_values_impl(const std::false_type&, Assignments... assignments) - { - } + void add_values_impl(const std::false_type&, Assignments... assignments); }; diff --git a/include/sqlpp11/vendor/where.h b/include/sqlpp11/vendor/where.h index 7cff9e35..e61feef5 100644 --- a/include/sqlpp11/vendor/where.h +++ b/include/sqlpp11/vendor/where.h @@ -47,7 +47,8 @@ namespace sqlpp using _parameter_tuple_t = std::tuple; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in where()"); - static_assert(sqlpp::detail::and_t::value, "at least one argument is not an expression in where()"); + static_assert(not sqlpp::detail::or_t::value, "at least one argument is an assignment in where()"); + static_assert(sqlpp::detail::and_t::value, "at least one argument is not valid expression in where()"); using _parameter_list_t = typename make_parameter_list_t<_parameter_tuple_t>::type; @@ -80,6 +81,7 @@ namespace sqlpp { using _is_where = std::true_type; using _is_dynamic = std::false_type; + using _table_set = ::sqlpp::detail::type_set<>; where_t(bool condition): _condition(condition) diff --git a/include/sqlpp11/vendor/wrap_operand.h b/include/sqlpp11/vendor/wrap_operand.h index 97d9cd8a..1dfce4a2 100644 --- a/include/sqlpp11/vendor/wrap_operand.h +++ b/include/sqlpp11/vendor/wrap_operand.h @@ -50,6 +50,20 @@ namespace sqlpp using _value_t = bool; using _table_set = ::sqlpp::detail::type_set<>; + boolean_operand(): + _t{} + {} + + boolean_operand(_value_t t): + _t(t) + {} + + boolean_operand(const boolean_operand&) = default; + boolean_operand(boolean_operand&&) = default; + boolean_operand& operator=(const boolean_operand&) = default; + boolean_operand& operator=(boolean_operand&&) = default; + ~boolean_operand() = default; + bool _is_trivial() const { return _t == false; } _value_t _t; @@ -67,23 +81,36 @@ namespace sqlpp } }; - template - struct integral_operand + struct integral_operand + { + static constexpr bool _is_expression = true; + using _value_type = ::sqlpp::detail::integral; + using _value_t = int64_t; + using _table_set = ::sqlpp::detail::type_set<>; + + integral_operand(): + _t{} + {} + + integral_operand(_value_t t): + _t(t) + {} + + integral_operand(const integral_operand&) = default; + integral_operand(integral_operand&&) = default; + integral_operand& operator=(const integral_operand&) = default; + integral_operand& operator=(integral_operand&&) = default; + ~integral_operand() = default; + + bool _is_trivial() const { return _t == 0; } + + _value_t _t; + }; + + template + struct interpreter_t { - static constexpr bool _is_expression = true; - using _value_type = ::sqlpp::detail::integral; - using _value_t = T; - using _table_set = ::sqlpp::detail::type_set<>; - - bool _is_trivial() const { return _t == 0; } - - _value_t _t; - }; - - template - struct interpreter_t> - { - using Operand = integral_operand; + using Operand = integral_operand; static Context& _(const Operand& t, Context& context) { @@ -93,23 +120,36 @@ namespace sqlpp }; - template - struct floating_point_operand + struct floating_point_operand + { + static constexpr bool _is_expression = true; + using _value_type = ::sqlpp::detail::floating_point; + using _value_t = double; + using _table_set = ::sqlpp::detail::type_set<>; + + floating_point_operand(): + _t{} + {} + + floating_point_operand(_value_t t): + _t(t) + {} + + floating_point_operand(const floating_point_operand&) = default; + floating_point_operand(floating_point_operand&&) = default; + floating_point_operand& operator=(const floating_point_operand&) = default; + floating_point_operand& operator=(floating_point_operand&&) = default; + ~floating_point_operand() = default; + + bool _is_trivial() const { return _t == 0; } + + _value_t _t; + }; + + template + struct interpreter_t { - static constexpr bool _is_expression = true; - using _value_type = ::sqlpp::detail::floating_point; - using _value_t = T; - using _table_set = ::sqlpp::detail::type_set<>; - - bool _is_trivial() const { return _t == 0; } - - _value_t _t; - }; - - template - struct interpreter_t> - { - using Operand = floating_point_operand; + using Operand = floating_point_operand; static Context& _(const Operand& t, Context& context) { @@ -125,6 +165,20 @@ namespace sqlpp using _value_t = std::string; using _table_set = ::sqlpp::detail::type_set<>; + text_operand(): + _t{} + {} + + text_operand(_value_t t): + _t(t) + {} + + text_operand(const text_operand&) = default; + text_operand(text_operand&&) = default; + text_operand& operator=(const text_operand&) = default; + text_operand& operator=(text_operand&&) = default; + ~text_operand() = default; + bool _is_trivial() const { return _t.empty(); } _value_t _t; @@ -157,13 +211,13 @@ namespace sqlpp template struct wrap_operand::value>::type> { - using type = integral_operand; + using type = integral_operand; }; template struct wrap_operand::value>::type> { - using type = floating_point_operand; + using type = floating_point_operand; }; template diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b2a56c15..8d04a9e3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,5 +19,6 @@ find_package(PythonInterp REQUIRED) add_custom_command( OUTPUT ${CMAKE_CURRENT_LIST_DIR}/Sample.h COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/ddl2cpp ${CMAKE_CURRENT_LIST_DIR}/sample.sql Sample test + DEPENDS ${CMAKE_CURRENT_LIST_DIR}/sample.sql ) diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index 9a343a0c..55e5bbc7 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -62,8 +62,9 @@ int main() interpret(insert_into(t), printer).flush(); interpret(insert_into(t).set(t.beta = "kirschauflauf"), printer).flush(); interpret(insert_into(t).columns(t.beta), printer).flush(); - auto multi_insert = insert_into(t).columns(t.beta); - multi_insert.add_values(t.beta = "cheesecake"); + auto multi_insert = insert_into(t).columns(t.beta, t.delta); + multi_insert.add_values(t.beta = "cheesecake", t.delta = 1); + multi_insert.add_values(t.beta = sqlpp::default_value, t.delta = sqlpp::default_value); auto i = dynamic_insert_into(db, t).dynamic_set(); i.add_set(t.beta = "kirschauflauf"); interpret(i, printer).flush(); diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 5c9c7b2b..c41c4d85 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -273,7 +273,7 @@ int main() // Test that select(all_of(tab)) is expanded in select { auto a = select(all_of(t)); - auto b = select(t.alpha, t.beta, t.gamma); + auto b = select(t.alpha, t.beta, t.gamma, t.delta); //auto c = select(t); static_assert(std::is_same::value, "all_of(t) has to be expanded by select()"); //static_assert(std::is_same::value, "t has to be expanded by select()"); @@ -282,14 +282,14 @@ int main() // Test that select(all_of(tab)) is expanded in multi_column { auto a = multi_column(alias::a, all_of(t)); - auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma); + auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma, t.delta); static_assert(std::is_same::value, "all_of(t) has to be expanded by multi_column"); } // Test that select(tab) is expanded in multi_column { auto a = multi_column(alias::a, all_of(t)); - auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma); + auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma, t.delta); static_assert(std::is_same::value, "t has to be expanded by multi_column"); } diff --git a/tests/sample.sql b/tests/sample.sql index 4fa7e01c..75f48445 100644 --- a/tests/sample.sql +++ b/tests/sample.sql @@ -35,6 +35,7 @@ CREATE TABLE tab_bar ( alpha bigint AUTO_INCREMENT, beta varchar(255) NULL DEFAULT "", - gamma bool NOT NULL + gamma bool NOT NULL, + delta int );