The evaluate()
method evaluates one server-side expression over the output of a query,
expecting exactly one result, and it returns that result. Inevitably
the expression will be a call to an aggregate function.
For any query q
, you can call q
.evaluate(
exprn
)
, provided that exprn
is an exprn_mapper<
T
>
for some mapped type T
.
q
's value mapper will be visible
to exprn
.
q
.evaluate(
exprn
)
returns a T
(i.e. exprn
's result type).
q
produces no records, then q
.evaluate(
exprn
)
throws no_row_exception
.
exprn
produces a single value, when
evaluated over the totality of q
's output,
then q
.evaluate(
exprn
)
returns that value.
exprn
produces multiple values, when
evaluated over the totality of q
's output,
then q
.evaluate(
exprn
)
throws multi_row_exception
.
So, to print the sum of the lengths of all movie titles:
std::cout << movies.evaluate(sum(length(movies->title))) << std::endl;
size()
,
empty()
The functions size()
and empty()
perform two of the most common uses of evaluate()
.
For any query q
:
q
.size()
returns a uint64_t
,
equal to the number of records that q
would produce.
q
.empty()
returns a bool
, which
is true if and only if q
would produce
no records.