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>
|
template<typename Expr>
|
||||||
struct avg_t: public boolean::template operators<avg_t<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
|
struct _value_type: public Expr::_value_type::_base_value_type
|
||||||
{
|
{
|
||||||
@ -71,6 +71,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_avg, "avg() not supported by current database");
|
||||||
os << "AVG(";
|
os << "AVG(";
|
||||||
_expr.serialize(os, db);
|
_expr.serialize(os, db);
|
||||||
os << ")";
|
os << ")";
|
||||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_count, "count() not supported by current database");
|
||||||
os << "COUNT(";
|
os << "COUNT(";
|
||||||
_expr.serialize(os, db);
|
_expr.serialize(os, db);
|
||||||
os << ")";
|
os << ")";
|
||||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_exists, "exists() not supported by current database");
|
||||||
os << "EXISTS(";
|
os << "EXISTS(";
|
||||||
_select.serialize(os, db);
|
_select.serialize(os, db);
|
||||||
os << ")";
|
os << ")";
|
||||||
|
@ -57,6 +57,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_group_by, "group_by() not supported by current database");
|
||||||
os << " GROUP BY ";
|
os << " GROUP BY ";
|
||||||
detail::serialize_tuple(os, db, _expressions, ',');
|
detail::serialize_tuple(os, db, _expressions, ',');
|
||||||
}
|
}
|
||||||
@ -80,6 +81,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_group_by, "group_by() not supported by current database");
|
||||||
if (_expressions.empty())
|
if (_expressions.empty())
|
||||||
return;
|
return;
|
||||||
os << " GROUP BY ";
|
os << " GROUP BY ";
|
||||||
|
@ -46,6 +46,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_having, "having() not supported by current database");
|
||||||
os << " HAVING ";
|
os << " HAVING ";
|
||||||
_expr.serialize(os, db);
|
_expr.serialize(os, db);
|
||||||
}
|
}
|
||||||
@ -69,6 +70,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_having, "having() not supported by current database");
|
||||||
if (_conditions.empty())
|
if (_conditions.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -35,10 +35,10 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template<bool not_inverted, typename Operand, typename... Args>
|
template<bool NotInverted, typename Operand, typename... Args>
|
||||||
struct in_t: public Operand::_value_type::template operators<in_t<not_inverted, Operand, 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");
|
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
||||||
|
|
||||||
struct _value_type: public Operand::_value_type::_base_value_type
|
struct _value_type: public Operand::_value_type::_base_value_type
|
||||||
@ -48,7 +48,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
struct _name_t
|
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>
|
template<typename T>
|
||||||
struct _member_t
|
struct _member_t
|
||||||
{
|
{
|
||||||
@ -75,8 +75,10 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
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);
|
_operand.serialize(os, db);
|
||||||
os << (inverted ? " NOT IN(" : " IN(");
|
os << (_inverted ? " NOT IN(" : " IN(");
|
||||||
detail::serialize_tuple(os, db, _args, ',');
|
detail::serialize_tuple(os, db, _args, ',');
|
||||||
os << ")";
|
os << ")";
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_like, "like() not supported by current database");
|
||||||
_operand.serialize(os, db);
|
_operand.serialize(os, db);
|
||||||
os << " LIKE(";
|
os << " LIKE(";
|
||||||
_pattern.serialize(os, db);
|
_pattern.serialize(os, db);
|
||||||
|
@ -40,6 +40,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_limit, "limit not supported by current database");
|
||||||
os << " LIMIT " << _limit;
|
os << " LIMIT " << _limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +70,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_limit, "limit not supported by current database");
|
||||||
if (_limit > 0)
|
if (_limit > 0)
|
||||||
os << " LIMIT " << _limit;
|
os << " LIMIT " << _limit;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_max, "max not supported by current database");
|
||||||
os << "MAX(";
|
os << "MAX(";
|
||||||
_expr.serialize(os, db);
|
_expr.serialize(os, db);
|
||||||
os << ")";
|
os << ")";
|
||||||
|
@ -71,6 +71,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_min, "min not supported by current database");
|
||||||
os << "MIN(";
|
os << "MIN(";
|
||||||
_expr.serialize(os, db);
|
_expr.serialize(os, db);
|
||||||
os << ")";
|
os << ")";
|
||||||
|
@ -54,6 +54,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_order_by, "order by not supported by current database");
|
||||||
os << " ORDER BY ";
|
os << " ORDER BY ";
|
||||||
detail::serialize_tuple(os, db, _orderExpressions, ',');
|
detail::serialize_tuple(os, db, _orderExpressions, ',');
|
||||||
}
|
}
|
||||||
@ -76,6 +77,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
void serialize(std::ostream& os, Db& db) const
|
void serialize(std::ostream& os, Db& db) const
|
||||||
{
|
{
|
||||||
|
static_assert(Db::_supports_order_by, "order by not supported by current database");
|
||||||
if (_expressions.empty())
|
if (_expressions.empty())
|
||||||
return;
|
return;
|
||||||
os << " ORDER BY ";
|
os << " ORDER BY ";
|
||||||
|
@ -69,6 +69,7 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
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);
|
_select.serialize(os, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ namespace sqlpp
|
|||||||
template<typename Expr>
|
template<typename Expr>
|
||||||
struct max_t: public boolean::template operators<max_t<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
|
struct _value_type: public Expr::_value_type::_base_value_type
|
||||||
{
|
{
|
||||||
@ -46,7 +46,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
struct _name_t
|
struct _name_t
|
||||||
{
|
{
|
||||||
static constexpr const char* _get_name() { return "MAX"; }
|
static constexpr const char* _get_name() { return "SUM"; }
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct _member_t
|
struct _member_t
|
||||||
{
|
{
|
||||||
@ -71,7 +71,8 @@ namespace sqlpp
|
|||||||
template<typename Db>
|
template<typename Db>
|
||||||
void serialize(std::ostream& os, Db& db) const
|
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);
|
_expr.serialize(os, db);
|
||||||
os << ")";
|
os << ")";
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,34 @@
|
|||||||
class DbMock: public sqlpp::connection
|
class DbMock: public sqlpp::connection
|
||||||
{
|
{
|
||||||
public:
|
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_function = true;
|
||||||
static constexpr bool _use_concat_operator = false;
|
|
||||||
|
|
||||||
const std::string& escape(const std::string& text) { return text; }
|
const std::string& escape(const std::string& text) { return text; }
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user