mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Added more checks for database traits
This commit is contained in:
parent
e63a798a82
commit
d3963e04b6
@ -37,7 +37,7 @@ namespace sqlpp
|
||||
template<typename Expr>
|
||||
struct avg_t: public boolean::template operators<avg_t<Expr>>
|
||||
{
|
||||
static_assert(is_value_t<Expr>::value, "avg() requires a value expression as argument");
|
||||
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
|
||||
|
||||
struct _value_type: public Expr::_value_type::_base_value_type
|
||||
{
|
||||
@ -71,6 +71,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_avg, "avg() not supported by current database");
|
||||
os << "AVG(";
|
||||
_expr.serialize(os, db);
|
||||
os << ")";
|
||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_count, "count() not supported by current database");
|
||||
os << "COUNT(";
|
||||
_expr.serialize(os, db);
|
||||
os << ")";
|
||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_exists, "exists() not supported by current database");
|
||||
os << "EXISTS(";
|
||||
_select.serialize(os, db);
|
||||
os << ")";
|
||||
|
@ -57,6 +57,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_group_by, "group_by() not supported by current database");
|
||||
os << " GROUP BY ";
|
||||
detail::serialize_tuple(os, db, _expressions, ',');
|
||||
}
|
||||
@ -80,6 +81,7 @@ namespace sqlpp
|
||||
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_group_by, "group_by() not supported by current database");
|
||||
if (_expressions.empty())
|
||||
return;
|
||||
os << " GROUP BY ";
|
||||
|
@ -46,6 +46,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_having, "having() not supported by current database");
|
||||
os << " HAVING ";
|
||||
_expr.serialize(os, db);
|
||||
}
|
||||
@ -69,6 +70,7 @@ namespace sqlpp
|
||||
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_having, "having() not supported by current database");
|
||||
if (_conditions.empty())
|
||||
return;
|
||||
|
||||
|
@ -35,10 +35,10 @@ namespace sqlpp
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<bool not_inverted, typename Operand, typename... Args>
|
||||
struct in_t: public Operand::_value_type::template operators<in_t<not_inverted, Operand, Args...>>
|
||||
template<bool NotInverted, typename Operand, typename... Args>
|
||||
struct in_t: public Operand::_value_type::template operators<in_t<NotInverted, Operand, Args...>>
|
||||
{
|
||||
static constexpr bool inverted = not not_inverted;
|
||||
static constexpr bool _inverted = not NotInverted;
|
||||
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
||||
|
||||
struct _value_type: public Operand::_value_type::_base_value_type
|
||||
@ -48,7 +48,7 @@ namespace sqlpp
|
||||
|
||||
struct _name_t
|
||||
{
|
||||
static constexpr const char* _get_name() { return inverted ? "NOT IN" : "IN"; }
|
||||
static constexpr const char* _get_name() { return _inverted ? "NOT IN" : "IN"; }
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
@ -75,8 +75,10 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(NotInverted and Db::_supports_in
|
||||
or _inverted and Db::_supports_not_in, "in() not supported by current database");
|
||||
_operand.serialize(os, db);
|
||||
os << (inverted ? " NOT IN(" : " IN(");
|
||||
os << (_inverted ? " NOT IN(" : " IN(");
|
||||
detail::serialize_tuple(os, db, _args, ',');
|
||||
os << ")";
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_like, "like() not supported by current database");
|
||||
_operand.serialize(os, db);
|
||||
os << " LIKE(";
|
||||
_pattern.serialize(os, db);
|
||||
|
@ -40,6 +40,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_limit, "limit not supported by current database");
|
||||
os << " LIMIT " << _limit;
|
||||
}
|
||||
|
||||
@ -69,6 +70,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_limit, "limit not supported by current database");
|
||||
if (_limit > 0)
|
||||
os << " LIMIT " << _limit;
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_max, "max not supported by current database");
|
||||
os << "MAX(";
|
||||
_expr.serialize(os, db);
|
||||
os << ")";
|
||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_min, "min not supported by current database");
|
||||
os << "MIN(";
|
||||
_expr.serialize(os, db);
|
||||
os << ")";
|
||||
|
@ -54,6 +54,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_order_by, "order by not supported by current database");
|
||||
os << " ORDER BY ";
|
||||
detail::serialize_tuple(os, db, _orderExpressions, ',');
|
||||
}
|
||||
@ -76,6 +77,7 @@ namespace sqlpp
|
||||
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_order_by, "order by not supported by current database");
|
||||
if (_expressions.empty())
|
||||
return;
|
||||
os << " ORDER BY ";
|
||||
|
@ -69,6 +69,7 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
static_assert(Db::_supports_select_as_table, "select as table not supported by current database");
|
||||
_select.serialize(os, db);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace sqlpp
|
||||
template<typename Expr>
|
||||
struct max_t: public boolean::template operators<max_t<Expr>>
|
||||
{
|
||||
static_assert(is_value_t<Expr>::value, "max() requires a value expression as argument");
|
||||
static_assert(is_numeric_t<Expr>::value, "sum() requires a numeric expression as argument");
|
||||
|
||||
struct _value_type: public Expr::_value_type::_base_value_type
|
||||
{
|
||||
@ -46,7 +46,7 @@ namespace sqlpp
|
||||
|
||||
struct _name_t
|
||||
{
|
||||
static constexpr const char* _get_name() { return "MAX"; }
|
||||
static constexpr const char* _get_name() { return "SUM"; }
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
@ -71,7 +71,8 @@ namespace sqlpp
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
{
|
||||
os << "MAX(";
|
||||
static_assert(Db::_supports_sum, "sum not supported by current database");
|
||||
os << "SUM(";
|
||||
_expr.serialize(os, db);
|
||||
os << ")";
|
||||
}
|
||||
|
@ -32,10 +32,34 @@
|
||||
class DbMock: public sqlpp::connection
|
||||
{
|
||||
public:
|
||||
static constexpr bool _supports_any = true;
|
||||
// join types
|
||||
static constexpr bool _supports_inner_join = true;
|
||||
static constexpr bool _supports_outer_join = true;
|
||||
static constexpr bool _supports_left_outer_join = true;
|
||||
static constexpr bool _supports_right_outer_join = true;
|
||||
|
||||
// functions
|
||||
static constexpr bool _supports_avg = true;
|
||||
static constexpr bool _supports_count = true;
|
||||
static constexpr bool _supports_exists = true;
|
||||
static constexpr bool _supports_like = true;
|
||||
static constexpr bool _supports_in = true;
|
||||
static constexpr bool _supports_max = true;
|
||||
static constexpr bool _supports_min = true;
|
||||
static constexpr bool _supports_not_in = true;
|
||||
static constexpr bool _supports_sum = true;
|
||||
|
||||
// select
|
||||
static constexpr bool _supports_group_by = true;
|
||||
static constexpr bool _supports_having = true;
|
||||
static constexpr bool _supports_limit = true;
|
||||
static constexpr bool _supports_order_by = true;
|
||||
static constexpr bool _supports_select_as_table = true;
|
||||
|
||||
static constexpr bool _supports_some = true;
|
||||
static constexpr bool _supports_any = true;
|
||||
static constexpr bool _use_concat_operator = true;
|
||||
static constexpr bool _use_concat_function = true;
|
||||
static constexpr bool _use_concat_operator = false;
|
||||
|
||||
const std::string& escape(const std::string& text) { return text; }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user