Setting upper limit on the number of resultset rows

accounts accounts=accounts::create(conn);

accounts->search("balance", ">", 0);
accounts->limit(10);

for (const auto &row: *all_accounts)
{
    // ...
}

limit() limits the number of rows that the resultsets iterate over, the upper limit on the resultset's size. The default value of 0 specifies no limit on the resultset's size. The above example will iterate over at most ten rows. If the executed SELECT query would return more rows, the additional rows get ignored.

This is done using the underlying database driver's most efficient implementation (which, sadly, is buggy sometimes).

int64_t account_id;

// ...

accounts accounts=accounts::create(conn);

accounts->search("account_id", "=", account_id);

accounts::base::rowptr maybe_row=accounts->maybe();

accounts::base::row must_row=accounts->only();

It is common to expect a SELECT to return at most one row, or maybe no rows at all. This is the expected result when using constraints on the table's primary key. maybe() and only() methods are shortcuts that implement the following steps: