| sqlpp11 | sqlpp23 |
|---|---|
|
Dynamically selected column | |
auto s = dynamic_select(db, tab.id)
.from(tab)
.unconditionally();
if (maybe) {
s.selected_columns.add(tab.int_value);
}
for (const auto& row : db(s)) {
const int64_t id = row.id;
const std::string need_to_parse =
row.at("int_value");
} |
for (const auto& row :
db(select(tab.id,
dynamic(maybe, tab.int_value))
.from(tab))) {
const int64_t id = row.id;
const int64_t = row.int_value;
} |
Conditions can be used in where, having, for instance. The tables here use where as an example.
| sqlpp11 | sqlpp23 |
|---|---|
|
Dynamic AND | |
auto s = dynamic_select(db, tab.id)
.from(tab)
.dynamic_where(tab.lang == "c++");
if (maybe_23) {
s.where.add(tab.version >= "23");
}
for (const auto& row : db(s)) {
do_something(row.id);
} |
for (const auto& row :
db(select(tab.id).from(tab).where(
tab.lang == "c++" and
dynamic(maybe_23, tab_version >= 23)))) {
do_something(row.id);
} |
|
Dynamic OR | |
// Not supported. |
for (const auto& row :
db(select(tab.id).from(tab).where(
tab.lang == "c++" or
dynamic(maybe_23, tab_version >= 23)))) {
do_something(row.id);
} |
|
Nested dynamic | |
// Not supported. |
for (const auto& row :
db(select(tab.id).from(tab).where(
tab.lang == "c++" and
(tab.legacy == true or
dynamic(maybe_23,
tab_version >= 23))))) {
do_something(row.id);
} |