mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Streamlined portable static asserts.
This commit is contained in:
parent
674af5b215
commit
9a29f41037
@ -30,6 +30,7 @@
|
||||
#include <sqlpp11/interpret.h>
|
||||
#include <sqlpp11/alias.h>
|
||||
#include <sqlpp11/multi_column.h>
|
||||
#include <sqlpp11/portable_static_assert.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@ -51,16 +52,7 @@ namespace sqlpp
|
||||
return {};
|
||||
}
|
||||
|
||||
struct assert_no_stand_alone_all_of_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "all_of(table) seems to be used outside of select");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_no_stand_alone_all_of_t, "all_of(table) seems to be used outside of select");
|
||||
|
||||
template <typename Context, typename Table>
|
||||
struct serializer_t<Context, all_of_t<Table>>
|
||||
|
@ -55,17 +55,9 @@ namespace sqlpp
|
||||
interpretable_list_t<Database> _dynamic_expressions;
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_in_group_by_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"at least one group-by expression requires a table which is otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(
|
||||
assert_no_unknown_tables_in_group_by_t,
|
||||
"at least one group-by expression requires a table which is otherwise not known in the statement");
|
||||
|
||||
// GROUP BY
|
||||
template <typename Database, typename... Expressions>
|
||||
|
@ -54,17 +54,9 @@ namespace sqlpp
|
||||
interpretable_list_t<Database> _dynamic_expressions;
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_in_having_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"at least one having-expression requires a table which is otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(
|
||||
assert_no_unknown_tables_in_having_t,
|
||||
"at least one having-expression requires a table which is otherwise not known in the statement");
|
||||
|
||||
// HAVING
|
||||
template <typename Database, typename... Expressions>
|
||||
|
@ -274,17 +274,8 @@ namespace sqlpp
|
||||
std::vector<_value_tuple_t> _insert_values;
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_in_column_list_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"at least one column requires a table which is otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_no_unknown_tables_in_column_list_t,
|
||||
"at least one column requires a table which is otherwise not known in the statement");
|
||||
|
||||
template <typename... Columns>
|
||||
struct column_list_t
|
||||
@ -357,16 +348,7 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
struct assert_insert_values_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "insert values required, e.g. set(...) or default_values()");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_values_t, "insert values required, e.g. set(...) or default_values()");
|
||||
|
||||
// NO INSERT COLUMNS/VALUES YET
|
||||
struct no_insert_value_list_t
|
||||
|
@ -100,16 +100,7 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
struct assert_into_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "into() required");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_into_t, "into() required");
|
||||
|
||||
// NO INTO YET
|
||||
struct no_into_t
|
||||
|
@ -55,17 +55,9 @@ namespace sqlpp
|
||||
interpretable_list_t<Database> _dynamic_expressions;
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_in_order_by_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"at least one order-by expression requires a table which is otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(
|
||||
assert_no_unknown_tables_in_order_by_t,
|
||||
"at least one order-by expression requires a table which is otherwise not known in the statement");
|
||||
|
||||
// ORDER BY
|
||||
template <typename Database, typename... Expressions>
|
||||
|
@ -27,6 +27,8 @@
|
||||
#ifndef SQLPP_PORTABLE_STATIC_ASSERT_H
|
||||
#define SQLPP_PORTABLE_STATIC_ASSERT_H
|
||||
|
||||
#include <sqlpp11/consistent.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
#define SQLPP_PORTABLE_STATIC_ASSERT(name, message) \
|
||||
|
@ -156,28 +156,11 @@ namespace sqlpp
|
||||
dynamic_select_column_list<Database> _dynamic_columns;
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_in_selected_columns_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"at least one selected column requires a table which is otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
|
||||
struct assert_aggregates_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "not all columns are made of aggregates, despite group_by or similar");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(
|
||||
assert_no_unknown_tables_in_selected_columns_t,
|
||||
"at least one selected column requires a table which is otherwise not known in the statement");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_aggregates_t,
|
||||
"not all columns are made of aggregates, despite group_by or similar");
|
||||
|
||||
// SELECTED COLUMNS
|
||||
template <typename Database, typename... Columns>
|
||||
|
@ -28,19 +28,11 @@
|
||||
#define SQLPP_SERIALIZER_H
|
||||
|
||||
#include <sqlpp11/wrong.h>
|
||||
#include <sqlpp11/portable_static_assert.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
struct assert_serializer_specialization_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "missing serializer specialization");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_serializer_specialization_t, "missing serializer specialization");
|
||||
|
||||
template <typename Context, typename T, typename Enable = void>
|
||||
struct serializer_t
|
||||
|
@ -44,39 +44,13 @@ namespace sqlpp
|
||||
template <typename Db, typename... Policies>
|
||||
struct statement_t;
|
||||
|
||||
struct assert_no_unknown_ctes_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"one clause requires common table expressions which are otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "one clause requires tables which are otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
|
||||
struct assert_no_parameters_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "cannot run statements with parameters directly, use prepare instead");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(
|
||||
assert_no_unknown_ctes_t,
|
||||
"one clause requires common table expressions which are otherwise not known in the statement");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_no_unknown_tables_t,
|
||||
"one clause requires tables which are otherwise not known in the statement");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_no_parameters_t,
|
||||
"cannot run statements with parameters directly, use prepare instead");
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
@ -56,16 +56,8 @@ namespace sqlpp
|
||||
_operand_t _value;
|
||||
};
|
||||
|
||||
struct assert_tvin_with_correct_operator_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "tvin may only be used with operators =, == and !=");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_tvin_with_correct_operator_t,
|
||||
"tvin may only be used with operators =, == and !=");
|
||||
|
||||
template <typename Context, typename Operand>
|
||||
struct serializer_t<Context, tvin_arg_t<Operand>>
|
||||
|
@ -373,28 +373,10 @@ namespace sqlpp
|
||||
using serialize_check_of =
|
||||
detail::get_first_if<is_inconsistent_t, consistent_t, typename serializer_t<Context, T>::_serialize_check...>;
|
||||
|
||||
struct assert_run_statement_or_prepared_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"connection cannot run something that is neither statement nor prepared statement");
|
||||
}
|
||||
};
|
||||
|
||||
struct assert_prepare_statement_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "connection cannot prepare something that is not a statement");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_run_statement_or_prepared_t,
|
||||
"connection cannot run something that is neither statement nor prepared statement");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_prepare_statement_t,
|
||||
"connection cannot prepare something that is not a statement");
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct consistency_check
|
||||
|
@ -52,17 +52,9 @@ namespace sqlpp
|
||||
interpretable_list_t<Database> _dynamic_assignments;
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_in_update_assignments_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value,
|
||||
"at least one update assignment requires a table which is otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(
|
||||
assert_no_unknown_tables_in_update_assignments_t,
|
||||
"at least one update assignment requires a table which is otherwise not known in the statement");
|
||||
|
||||
// UPDATE ASSIGNMENTS
|
||||
template <typename Database, typename... Assignments>
|
||||
@ -146,16 +138,7 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
struct assert_update_assignments_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "update assignments required, i.e. set(...)");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_assignments_t, "update assignments required, i.e. set(...)");
|
||||
|
||||
struct no_update_list_t
|
||||
{
|
||||
|
@ -55,18 +55,9 @@ namespace sqlpp
|
||||
interpretable_list_t<Database> _dynamic_expressions;
|
||||
};
|
||||
|
||||
struct assert_no_unknown_tables_in_where_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(
|
||||
wrong_t<T>::value,
|
||||
"at least one expression in where() requires a table which is otherwise not known in the statement");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(
|
||||
assert_no_unknown_tables_in_where_t,
|
||||
"at least one expression in where() requires a table which is otherwise not known in the statement");
|
||||
|
||||
// WHERE(EXPR)
|
||||
template <typename Database, typename... Expressions>
|
||||
@ -198,16 +189,7 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
struct assert_where_t
|
||||
{
|
||||
using type = std::false_type;
|
||||
|
||||
template <typename T = void>
|
||||
static void _()
|
||||
{
|
||||
static_assert(wrong_t<T>::value, "where expression required, e.g. where(true)");
|
||||
}
|
||||
};
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_t, "where expression required, e.g. where(true)");
|
||||
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_expressions_t,
|
||||
"at least one argument is not a boolean expression in where()");
|
||||
|
Loading…
Reference in New Issue
Block a user