You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[8. Development and Testing](#8-development-and-testing)
150
153
*[8.1. Testing](#81-testing)
151
154
*[9. Getting Help](#9-getting-help)
@@ -3680,13 +3683,64 @@ Exceptions which can be thrown by SQL API are stated at below:
3680
3683
-`illegal_access` is thrown if page fetch operation is already progress. To prevent this wait for the `boost::future<sql_page>` which belongs to previous `next()` call.
3681
3684
-`sql_result::iterator()` can throw two types of exceptions.
3682
3685
-`illegal_state` is thrown if it is not an `SELECT` query or `sql_result::iterator()` is requested more than once.
3686
+
-`sql_result::iterator()` throws `hazelcast_sql_exception` if it sql_result is already closed.
3687
+
-`sql_result::pbegin()` calls `sql_result::iterator()` method internally, so it throws same exceptions.
3683
3688
-`sql_result::row_metadata()` can throw `illegal_state` exception if the result contains only update count.
3684
3689
-`sql_page::sql_row::get_object(int)` can throw `index_out_of_bounds` exception if the index is out of range.
3685
3690
-`sql_page::sql_row::get_object(std::string)` can throw `illegal_argument` exception if the column doesn't exist.
3691
+
-`sql_result::page_iterator_sync::operator++()` can throw `no_such_element` exception if the fetch operation is timed out.
3692
+
-`sql_result::page_iterator_sync::operator*()` can throw `no_such_element` exception if the iterator points to past-end element;
3686
3693
3687
3694
In addition, any method which returns `boost::future<T>` can throw an exception.
3688
3695
Unless otherwise is stated, `sql::hazelcast_sql_exception` is thrown.
3689
3696
3697
+
### 7.11.8 Iterators
3698
+
There are several iterators in SQL Api to satisfy different use cases. They are listed below:
3699
+
3700
+
-`page_iterator` (Async page iterator)
3701
+
-`page_iterator_sync` (Sync page iterator)
3702
+
3703
+
Reminder 1, only one type of iterator can be used. So it is suggested to choose appropriate one to fetch `SELECT` query results.
3704
+
3705
+
Reminder 2, it is not possible to iterate from beginning to end more than once.
3706
+
3707
+
Reminder 3, it is not possible to acquire iterators more than once, so consecutive calls to `sql_result::iterator()`, `sql_result::pbegin(std::chrono::milliseconds timeout)`, `sql_result::begin(std::chrono::milliseconds timeout)` methods will throw `illegal_state` exception.
3708
+
3709
+
#### 7.11.8.1 page_iterator
3710
+
`page_iterator` is the basic and the most essential one. It supports fetching pages asynchronously by `next()` method which returns `boost::future<sql_page>`.
3711
+
Therefore, users are able to fetch `SELECT` query results page by page. It is acquired by calling `sql_result::iterator()` method.
3712
+
3713
+
```C++
3714
+
auto result = sql.execute("SELECT * FROM integers").get();
3715
+
3716
+
for (auto itr = result->iterator(); itr.has_next();) {
3717
+
auto page = itr.next().get();
3718
+
3719
+
std::cout << "There are " << page->row_count() << " rows the page."
`page_iterator_sync` is the second iterator which wraps `page_iterator` and serves it as a sync iterator. It allows users to iterator over pages.
3730
+
It is similar to native C++ iterators. So it can be used with `algorithm` header.
3731
+
It supports `operator*()`, `operator->()`, `operator++()` operators. Post increment operator is marked as `delete`.
3732
+
`operator++()`(pre-increment operator) fetches the next page in a blocking manner. `timeout` can be set. `operator++()` might throw `exception::no_such_element` exception if the fetch operation is timed out.
3733
+
`page_iterator_sync` is copyable but it is there only for convenience. Copy is shallow copy so copied instances should not be used simultaneously.
3734
+
This iterator is acquired by `sql_result::pbegin(std::chrono::milliseconds timeout)` and `sql_result::pend()`. `timeout` is defaulted to `std::chrono::milliseconds{ -1 }` which means wait forever.
3735
+
3736
+
```C++
3737
+
auto result = client.get_sql().execute("SELECT * FROM integers").get();
0 commit comments