Sqlite: Add range getter

Sometimes it is handy to return a range so you can break in a for range
loop. So you can now write:

for (auto [key, value] :
    statement.range<std::tuple<long long, std::string>>()) {
    values.push_back(value);
    if (value == Tuple{"foo", 23.3, 2})
         break;
}

for (auto [key, value] :
    statement.rangeWithTransaction<std::tuple<long long, std::string>>()) {
    values.push_back(value);
    if (value == Tuple{"foo", 23.3, 2})
         break;
}

It will only step over the statement to the break. So you don't fetch
not used values anymore. The second version will add a transaction
around the range.

But be careful. The range is view to the statement. Holding it longer or
reusing it can lead to strange behavior because the state of the
statement is changing.

Change-Id: I90191f7da5a015c7d8077d5bc428655a2b53246c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2021-04-21 14:31:36 +02:00
parent 44b4c461ff
commit f69314b6ae
5 changed files with 517 additions and 24 deletions

View File

@@ -42,6 +42,8 @@ public:
Base::checkColumnCount(ResultCount);
}
using Base::range;
using Base::rangeWithTransaction;
using Base::readCallback;
using Base::readTo;
using Base::toValue;