From 935baebedbb8b8f0b0be3b87a874e1dcc2824b21 Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 25 Nov 2014 21:46:09 +0100 Subject: [PATCH] Added more specific static asserts for the consistency checks --- include/sqlpp11/from.h | 1 + include/sqlpp11/group_by.h | 15 ++++++++++++++- include/sqlpp11/having.h | 15 ++++++++++++++- include/sqlpp11/insert_value_list.h | 15 ++++++++++++++- include/sqlpp11/order_by.h | 15 ++++++++++++++- include/sqlpp11/update_list.h | 15 ++++++++++++++- include/sqlpp11/using.h | 1 + include/sqlpp11/where.h | 16 ++++++++++++++-- 8 files changed, 86 insertions(+), 7 deletions(-) diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index c1e4fc34..efc338ba 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -120,6 +120,7 @@ namespace sqlpp template struct _methods_t { + // FIXME: We might want to check if we have too many tables define in the FROM using _consistency_check = consistent_t; }; }; diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 6c6fdd09..be7d01aa 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -55,6 +55,17 @@ namespace sqlpp interpretable_list_t _dynamic_expressions; }; + struct assert_no_unknown_tables_in_group_by_t + { + using type = std::false_type; + + template + static void _() + { + static_assert(wrong_t::value, "at least one group-by expression requires a table which is otherwise not known in the statement"); + } + }; + // GROUP BY template struct group_by_t @@ -128,7 +139,9 @@ namespace sqlpp template struct _methods_t { - using _consistency_check = consistent_t; + using _consistency_check = typename std::conditional::value, + consistent_t, + assert_no_unknown_tables_in_group_by_t>::type; }; }; diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index c0cdb80f..e524da76 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -54,6 +54,17 @@ namespace sqlpp interpretable_list_t _dynamic_expressions; }; + struct assert_no_unknown_tables_in_having_t + { + using type = std::false_type; + + template + static void _() + { + static_assert(wrong_t::value, "at least one having-expression requires a table which is otherwise not known in the statement"); + } + }; + // HAVING template struct having_t @@ -126,7 +137,9 @@ namespace sqlpp template struct _methods_t { - using _consistency_check = consistent_t; + using _consistency_check = typename std::conditional::value, + consistent_t, + assert_no_unknown_tables_in_having_t>::type; }; }; diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index b893f641..8190829b 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -236,6 +236,17 @@ namespace sqlpp std::vector<_value_tuple_t> _insert_values; }; + struct assert_no_unknown_tables_in_column_list_t + { + using type = std::false_type; + + template + static void _() + { + static_assert(wrong_t::value, "at least one column requires a table which is otherwise not known in the statement"); + } + }; + template struct column_list_t { @@ -301,7 +312,9 @@ namespace sqlpp template struct _methods_t { - using _consistency_check = consistent_t; + using _consistency_check = typename std::conditional::value, + consistent_t, + assert_no_unknown_tables_in_column_list_t>::type; }; }; diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index 12dc3a8a..afac7e97 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -55,6 +55,17 @@ namespace sqlpp interpretable_list_t _dynamic_expressions; }; + struct assert_no_unknown_tables_in_order_by_t + { + using type = std::false_type; + + template + static void _() + { + static_assert(wrong_t::value, "at least one order-by expression requires a table which is otherwise not known in the statement"); + } + }; + // ORDER BY template struct order_by_t @@ -128,7 +139,9 @@ namespace sqlpp template struct _methods_t { - using _consistency_check = consistent_t; + using _consistency_check = typename std::conditional::value, + consistent_t, + assert_no_unknown_tables_in_order_by_t>::type; }; }; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index f3e45257..f17e2c7b 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -52,6 +52,17 @@ namespace sqlpp interpretable_list_t _dynamic_assignments; }; + struct assert_no_unknown_tables_in_update_assignments_t + { + using type = std::false_type; + + template + static void _() + { + static_assert(wrong_t::value, "at least one update assignment requires a table which is otherwise not known in the statement"); + } + }; + // UPDATE ASSIGNMENTS template struct update_list_t @@ -124,7 +135,9 @@ namespace sqlpp template struct _methods_t { - using _consistency_check = consistent_t; + using _consistency_check = typename std::conditional::value, + consistent_t, + assert_no_unknown_tables_in_update_assignments_t>::type; }; }; diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index d6fb872b..6e2be749 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -121,6 +121,7 @@ namespace sqlpp template struct _methods_t { + // FIXME: Maybe check for unused tables, similar to from using _consistency_check = consistent_t; }; }; diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 70217c17..983e2658 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -55,6 +55,17 @@ namespace sqlpp interpretable_list_t _dynamic_expressions; }; + struct assert_no_unknown_tables_in_where_t + { + using type = std::false_type; + + template + static void _() + { + static_assert(wrong_t::value, "at least one expression in where() requires a table which is otherwise not known in the statement"); + } + }; + // WHERE(EXPR) template struct where_t @@ -128,8 +139,9 @@ namespace sqlpp template struct _methods_t { -#warning: here and elsewhere: add check for missing tables (see select columns, for instance) - using _consistency_check = consistent_t; + using _consistency_check = typename std::conditional::value, + consistent_t, + assert_no_unknown_tables_in_where_t>::type; }; };