mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Dynamic methods of select, insert and co return *this now.
Not sure if chaining makes much sense, but it is possible now
This commit is contained in:
parent
bd337954fa
commit
96c6e5d435
@ -44,6 +44,11 @@ namespace sqlpp
|
||||
using _value_type = boolean;
|
||||
|
||||
bool_operand(bool t): _t(t) {}
|
||||
bool_operand(const bool_operand&) = default;
|
||||
bool_operand(bool_operand&&) = default;
|
||||
bool_operand& operator=(const bool_operand&) = default;
|
||||
bool_operand& operator=(bool_operand&&) = default;
|
||||
~bool_operand() = default;
|
||||
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
@ -53,7 +58,7 @@ namespace sqlpp
|
||||
|
||||
bool _is_trivial() const { return _t == false; }
|
||||
|
||||
const bool _t;
|
||||
bool _t;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -63,6 +68,11 @@ namespace sqlpp
|
||||
using _value_type = numeric;
|
||||
|
||||
numeric_operand(T t): _t(t) {}
|
||||
numeric_operand(const numeric_operand&) = default;
|
||||
numeric_operand(numeric_operand&&) = default;
|
||||
numeric_operand& operator=(const numeric_operand&) = default;
|
||||
numeric_operand& operator=(numeric_operand&&) = default;
|
||||
~numeric_operand() = default;
|
||||
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
@ -72,7 +82,7 @@ namespace sqlpp
|
||||
|
||||
bool _is_trivial() const { return _t == 0; }
|
||||
|
||||
const T _t;
|
||||
T _t;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -82,6 +92,11 @@ namespace sqlpp
|
||||
using _value_type = text;
|
||||
|
||||
text_operand(const T& t): _t(t) {}
|
||||
text_operand(const text_operand&) = default;
|
||||
text_operand(text_operand&&) = default;
|
||||
text_operand& operator=(const text_operand&) = default;
|
||||
text_operand& operator=(text_operand&&) = default;
|
||||
~text_operand() = default;
|
||||
|
||||
template<typename Db>
|
||||
void serialize(std::ostream& os, Db& db) const
|
||||
@ -91,7 +106,7 @@ namespace sqlpp
|
||||
|
||||
bool _is_trivial() const { return _t.empty(); }
|
||||
|
||||
const std::string _t;
|
||||
std::string _t;
|
||||
};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
|
@ -80,11 +80,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Assignment>
|
||||
void add_set(Assignment&& assignment)
|
||||
insert_t add_set(Assignment&& assignment)
|
||||
{
|
||||
static_assert(is_dynamic_t<InsertList>::value, "cannot call add_set() in a non-dynamic set");
|
||||
|
||||
_insert_list.add(std::forward<Assignment>(assignment));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Db>
|
||||
|
@ -73,23 +73,25 @@ namespace sqlpp
|
||||
};
|
||||
}
|
||||
|
||||
auto dynamic_using_()
|
||||
auto dynamic_using_()
|
||||
-> set_using_t<dynamic_using_t<Database>>
|
||||
{
|
||||
static_assert(std::is_same<Using, noop>::value, "cannot call using() twice");
|
||||
static_assert(std::is_same<Where, noop>::value, "cannot call using() after where()");
|
||||
return {
|
||||
_table,
|
||||
_table,
|
||||
{{}},
|
||||
_where
|
||||
};
|
||||
}
|
||||
|
||||
template<typename Tab>
|
||||
void add_using_(Tab&& table)
|
||||
template<typename Tab>
|
||||
remove_t& add_using_(Tab&& table)
|
||||
{
|
||||
static_assert(is_dynamic_t<Using>::value, "cannot call add_using() in a non-dynamic using");
|
||||
_using.add(std::forward<Tab>(table));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
@ -116,11 +118,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
void add_where(Expr&& expr)
|
||||
remove_t& add_where(Expr&& expr)
|
||||
{
|
||||
static_assert(is_dynamic_t<Where>::value, "cannot call add_where() in a non-dynamic where");
|
||||
|
||||
_where.add(std::forward<Expr>(expr));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -206,12 +206,14 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Table>
|
||||
void add_from(Table&& table)
|
||||
select_t& add_from(Table&& table)
|
||||
{
|
||||
static_assert(not is_noop<ExpressionList>::value, "cannot call add_from() without having selected anything");
|
||||
static_assert(is_dynamic_t<From>::value, "cannot call add_from() in a non-dynamic from");
|
||||
|
||||
_from.add(std::forward<Table>(table));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
@ -252,11 +254,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
void add_where(Expr&& expr)
|
||||
select_t& add_where(Expr&& expr)
|
||||
{
|
||||
static_assert(is_dynamic_t<Where>::value, "cannot call add_where() in a non-dynamic where");
|
||||
|
||||
_where.add(std::forward<Expr>(expr));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Col>
|
||||
@ -297,11 +301,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
void add_group_by(Expr&& expr)
|
||||
select_t& add_group_by(Expr&& expr)
|
||||
{
|
||||
static_assert(is_dynamic_t<GroupBy>::value, "cannot call add_group_by() in a non-dynamic group_by");
|
||||
|
||||
_group_by.add(std::forward<Expr>(expr));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
@ -342,11 +348,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
void add_having(Expr&& expr)
|
||||
select_t& add_having(Expr&& expr)
|
||||
{
|
||||
static_assert(is_dynamic_t<Having>::value, "cannot call add_having() in a non-dynamic having");
|
||||
|
||||
_having.add(std::forward<Expr>(expr));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... OrderExpr>
|
||||
@ -387,11 +395,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
void add_order_by(Expr&& expr)
|
||||
select_t& add_order_by(Expr&& expr)
|
||||
{
|
||||
static_assert(is_dynamic_t<OrderBy>::value, "cannot call add_order_by() in a non-dynamic order_by");
|
||||
|
||||
_order_by.add(std::forward<Expr>(expr));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto limit(std::size_t limit)
|
||||
@ -430,11 +440,13 @@ namespace sqlpp
|
||||
};
|
||||
}
|
||||
|
||||
void set_limit(std::size_t limit)
|
||||
select_t& set_limit(std::size_t limit)
|
||||
{
|
||||
static_assert(is_dynamic_t<Limit>::value, "cannot call set_limit() in a non-dynamic limit");
|
||||
|
||||
_limit.set(limit);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto offset(std::size_t offset)
|
||||
@ -473,11 +485,13 @@ namespace sqlpp
|
||||
};
|
||||
}
|
||||
|
||||
void set_offset(std::size_t offset)
|
||||
select_t& set_offset(std::size_t offset)
|
||||
{
|
||||
static_assert(is_dynamic_t<Offset>::value, "cannot call set_offset() in a non-dynamic limit");
|
||||
|
||||
_offset.set(offset);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename AliasProvider>
|
||||
|
@ -85,11 +85,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Assignment>
|
||||
void add_set(Assignment&& assignment)
|
||||
update_t& add_set(Assignment&& assignment)
|
||||
{
|
||||
static_assert(is_dynamic_t<Assignments>::value, "cannot call add_set() in a non-dynamic set");
|
||||
|
||||
_assignments.add(std::forward<Assignment>(assignment));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
@ -118,11 +120,13 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
void add_where(Expr&& expr)
|
||||
update_t& add_where(Expr&& expr)
|
||||
{
|
||||
static_assert(is_dynamic_t<Where>::value, "cannot call add_where() in a non-dynamic where");
|
||||
|
||||
_where.add(std::forward<Expr>(expr));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Db>
|
||||
|
@ -51,7 +51,7 @@ int main()
|
||||
insert_into(t).serialize(std::cerr, db); std::cerr << "\n";
|
||||
insert_into(t).set(t.beta = "kirschauflauf").serialize(std::cerr, db); std::cerr << "\n";
|
||||
auto i = dynamic_insert_into(db, t).dynamic_set();
|
||||
i.add_set(t.beta = "kirschauflauf");
|
||||
i = i.add_set(t.beta = "kirschauflauf");
|
||||
i.serialize(std::cerr, db); std::cerr << "\n";
|
||||
//insert_into(t).values(7, "wurstwaren", true).serialize(std::cerr, db); std::cerr << "\n";
|
||||
//insert_into(t).columns(t.alpha, t.beta).values(25, "drei").serialize(std::cerr, db); std::cerr << "\n";
|
||||
|
@ -49,8 +49,8 @@ int main()
|
||||
remove_from(t).where(t.beta != "transparent").serialize(std::cerr, db); std::cerr << "\n";
|
||||
remove_from(t).using_(t).serialize(std::cerr, db); std::cerr << "\n";
|
||||
auto r = dynamic_remove_from(db, t).dynamic_using_().dynamic_where();
|
||||
r.add_using_(t);
|
||||
r.add_where(t.beta != "transparent");
|
||||
r = r.add_using_(t);
|
||||
r = r.add_where(t.beta != "transparent");
|
||||
r.serialize(std::cerr, db); std::cerr << "\n";
|
||||
//insert_into(t).values(7, "wurstwaren", true).serialize(std::cerr, db); std::cerr << "\n";
|
||||
//insert_into(t).columns(t.alpha, t.beta).values(25, "drei").serialize(std::cerr, db); std::cerr << "\n";
|
||||
|
@ -264,10 +264,10 @@ int main()
|
||||
|
||||
{
|
||||
auto s = dynamic_select(db, t).dynamic_from().dynamic_where().dynamic_limit().dynamic_offset();
|
||||
s.add_from(t);
|
||||
s.add_where(t.alpha > 7);
|
||||
s.set_limit(30);
|
||||
s.set_limit(3);
|
||||
s = s.add_from(t);
|
||||
s = s.add_where(t.alpha > 7);
|
||||
s = s.set_limit(30);
|
||||
s = s.set_limit(3);
|
||||
std::cerr << "------------------------\n";
|
||||
s.serialize(std::cerr, db);
|
||||
std::cerr << "------------------------\n";
|
||||
|
@ -49,7 +49,7 @@ int main()
|
||||
update(t).set(t.gamma = false).serialize(std::cerr, db); std::cerr << "\n";
|
||||
update(t).set(t.gamma = false).where(t.beta != "transparent").serialize(std::cerr, db); std::cerr << "\n";
|
||||
auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where();
|
||||
u.add_set(t.gamma = false);
|
||||
u = u.add_set(t.gamma = false);
|
||||
u.serialize(std::cerr, db); std::cerr << "\n";
|
||||
|
||||
//insert_into(t).values(7, "wurstwaren", true).serialize(std::cerr, db); std::cerr << "\n";
|
||||
|
Loading…
Reference in New Issue
Block a user