Started to use flags to indicate database traits

e.g. support for any or outer join, or how string concatenation is
implemented
This commit is contained in:
Roland Bock
2013-11-01 12:23:50 +01:00
parent a17a8ecfa6
commit e63a798a82
7 changed files with 54 additions and 11 deletions

View File

@@ -72,6 +72,7 @@ namespace sqlpp
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
static_assert(Db::_supports_any, "any() not supported by current database");
os << "ANY(";
_select.serialize(os, db);
os << ")";

View File

@@ -74,9 +74,19 @@ namespace sqlpp
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "CONCAT(";
detail::serialize_tuple(os, db, _args, ',');
os << ")";
static_assert(Db::_use_concat_operator or Db::_use_concat_function, "neither concat operator nor concat function supported by current database");
if (Db::_use_concat_operator)
{
os << "(";
detail::serialize_tuple(os, db, _args, "||");
os << ")";
}
else if (Db::_use_concat_function)
{
os << "CONCAT(";
detail::serialize_tuple(os, db, _args, ',');
os << ")";
}
}
private:

View File

@@ -38,8 +38,8 @@ namespace sqlpp
template<std::size_t begin, std::size_t index, std::size_t end>
struct tuple_serializer_impl
{
template<typename Db, typename Tuple>
static void serialize(std::ostream& os, Db& db, const Tuple& flags_and_columns, char separator)
template<typename Db, typename Tuple, typename Separator>
static void serialize(std::ostream& os, Db& db, const Tuple& flags_and_columns, const Separator& separator)
{
if (index > begin)
os << separator;
@@ -56,14 +56,14 @@ namespace sqlpp
template<std::size_t begin, std::size_t end>
struct tuple_serializer_impl<begin, end, end>
{
template<typename Db, typename Tuple>
static void serialize(std::ostream& os, Db& db, const Tuple& flags_and_columns, char separator)
template<typename Db, typename Tuple, typename Separator>
static void serialize(std::ostream& os, Db& db, const Tuple& flags_and_columns, const Separator& separator)
{
}
};
template<typename Db, typename Tuple>
static void serialize_tuple(std::ostream& os, Db& db, const Tuple& flags_and_columns, char separator)
template<typename Db, typename Tuple, typename Separator>
static void serialize_tuple(std::ostream& os, Db& db, const Tuple& flags_and_columns, const Separator& separator)
{
tuple_serializer_impl<0, 0, std::tuple_size<Tuple>::value>::serialize(os, db, flags_and_columns, separator);
}

View File

@@ -101,7 +101,7 @@ namespace sqlpp
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << '"' << db.escape(_t) << '"';
os << '\'' << db.escape(_t) << '\'';
}
bool _is_trivial() const { return _t.empty(); }

View File

@@ -34,18 +34,42 @@ namespace sqlpp
{
struct inner_join_t
{
template<typename Db>
struct _is_supported
{
static constexpr bool value = Db::_supports_inner_join;
};
static constexpr const char* _name = " INNER ";
};
struct outer_join_t
{
template<typename Db>
struct _is_supported
{
static constexpr bool value = Db::_supports_outer_join;
};
static constexpr const char* _name = " OUTER ";
};
struct left_outer_join_t
{
template<typename Db>
struct _is_supported
{
static constexpr bool value = Db::_supports_left_outer_join;
};
static constexpr const char* _name = " LEFT OUTER ";
};
struct right_outer_join_t
{
template<typename Db>
struct _is_supported
{
static constexpr bool value = Db::_supports_right_outer_join;
};
static constexpr const char* _name = " RIGHT OUTER ";
};
@@ -109,6 +133,7 @@ namespace sqlpp
void serialize(std::ostream& os, Db& db) const
{
// FIXME: Need to check if db supports the join type. e.g. sqlite does not support right outer or full outer join
static_assert(JoinType::template _is_supported<Db>::value, "join type not supported by current database");
static_assert(not is_noop<On>::value, "joined tables require on()");
_lhs.serialize(os, db);
os << JoinType::_name;

View File

@@ -72,6 +72,7 @@ namespace sqlpp
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
static_assert(Db::_supports_some, "some() not supported by current database");
os << "SOME(";
_select.serialize(os, db);
os << ")";