diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 9d3f54ea..c24f236f 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -126,10 +126,22 @@ namespace sqlpp return _parameter_list_t::size::value; } + template + struct is_table_subset_of_table + { + static constexpr bool value = ::sqlpp::detail::is_subset_of::value; + }; + + void _check_consistency() const + { + // FIXME: Read up on what is allowed/prohibited in INSERT + } + template std::size_t _run(Database& db) const { -#warning add _check_consistency here and for remove and update + _check_consistency(); + static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); return db.insert(*this); } @@ -138,6 +150,8 @@ namespace sqlpp auto _prepare(Database& db) const -> prepared_insert_t { + _check_consistency(); + return {{}, db.prepare_insert(*this)}; } diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 9ea1fd6c..ed12718f 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -132,11 +132,26 @@ namespace sqlpp return _parameter_list_t::size::value; } + template + struct is_table_subset_of_table + { + static constexpr bool value = ::sqlpp::detail::is_subset_of::value; + }; + + void _check_consistency() const + { + static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows"); + + // FIXME: Read more details about what is allowed and what not in SQL DELETE + static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables"); + } + template std::size_t _run(Database& db) const { + _check_consistency(); + static_assert(_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead"); - static_assert(is_where_t<_where_t>::value, "cannot run remove without having a where condition, use .where(true) to remove all rows"); return db.remove(*this); } @@ -144,7 +159,8 @@ namespace sqlpp auto _prepare(Database& db) const -> prepared_remove_t { - static_assert(is_where_t<_where_t>::value, "cannot run remove without having a where condition, use .where(true) to remove all rows"); + _check_consistency(); + return {{}, db.prepare_remove(*this)}; } diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index e58a0ad8..fd1b3a59 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -256,6 +256,8 @@ namespace sqlpp void _check_consistency() const { + static_assert(is_select_column_list_t<_column_list_t>::value, "no columns selected"); + static_assert(is_table_subset_of_from<_flag_list_t>::value, "flags require additional tables in from()"); static_assert(is_table_subset_of_from<_column_list_t>::value, "selected columns require additional tables in from()"); static_assert(is_table_subset_of_from<_where_t>::value, "where() expression requires additional tables in from()"); diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 496adb14..5865651a 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -130,9 +130,25 @@ namespace sqlpp return _parameter_list_t::size::value; } + template + struct is_table_subset_of_table + { + static constexpr bool value = ::sqlpp::detail::is_subset_of::value; + }; + + void _check_consistency() const + { + static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows"); + + static_assert(is_table_subset_of_table<_update_list_t>::value, "updates require additional tables"); + static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables"); + } + template std::size_t _run(Database& db) const { + _check_consistency(); + static_assert(_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); return db.update(*this); } @@ -141,6 +157,8 @@ namespace sqlpp auto _prepare(Database& db) const -> prepared_update_t { + _check_consistency(); + return {{}, db.prepare_update(*this)}; }