Using scrollable cursors

An optional last argument to fetch() and fetch_vectors() defaults to x::sql::fetch::next, which normally returns the next row or vector of rows from the resultset:

float price;
std::vector<float> prices;

stmt->fetch("prices", price, x::sql::fetch::next);

size_t cnt=stmt->fetch_vectors(1000, "prices", prices, x::sql::fetch::next);

This is the default action, if omitted, that fetches the next row or vector of rows from the cursor. Depending on the cursor type, and the database drivers, other possible values are:

float price;
std::vector<float> prices;

stmt->fetch("prices", price, x::sql::fetch::prior);

size_t cnt=stmt->fetch_vectors(1000, "prices", prices, x::sql::fetch::prior);

x::sql::fetch::prior fetches the previous row or vector of rows from the cursor.

float price;
std::vector<float> prices;

stmt->fetch("prices", price, x::sql::fetch::first);

size_t cnt=stmt->fetch_vectors(1000, "prices", prices, x::sql::fetch::first);

x::sql::fetch::first fetches the first row or vector of rows from the cursor.

float price;
std::vector<float> prices;

stmt->fetch("prices", price, x::sql::fetch::last);

size_t cnt=stmt->fetch_vectors(1000, "prices", prices, x::sql::fetch::last);

x::sql::fetch::last fetches the last row or vector of rows from the cursor.

float price;
std::vector<float> prices;

stmt->fetch("prices", price, x::sql::fetch::absolute(100));

size_t cnt=stmt->fetch_vectors(1000, "prices", prices, x::sql::fetch::absolute(0));

x::sql::fetch::absolute(n) fetches a row or vector of rows starting with the given absolute row number from the cursor. The row numbers are 0-based.

float price;
std::vector<float> prices;

stmt->fetch("prices", price, x::sql::fetch::relative(-1));

size_t cnt=stmt->fetch_vectors(1000, "prices", prices, x::sql::fetch::relative(10));

x::sql::fetch::relative(n) fetches a row or vector of rows starting with the given offset from the start of the current resultset row or row vector.

float price;
std::vector<float> prices;

x::sql::bookmark bookmark;

std::vector<x::sql::bookmark> bookmarks;

auto stmt=conn->create_newstatement("BOOKMARKS", "ON", "CURSOR_TYPE", "STATIC")->execute("SELECT prices FROM books order by stock_id");

stmt->fetch(bookmark, "price", price);

stmt->fetch_vectors(100, bookmarks, "price", price);

stmt->fetch("prices", price, x::sql::fetch::atbookmark(bookmark, -1));

size_t cnt=stmt->fetch_vectors(1000, "prices", prices, x::sql::fetch::atbookmark(bookmark));

An x::sql::bookmark is an opaque object that stores a row's bookmark. In static cursors it's equivalent to the number of the row in the resultset. Dynamic cursors' row numbers can change, but a given row's bookmark remains the same (unless the row gets deleted), allowing the cursor to get repositioned to the same row even if other rows were added or deleted from the cursor's resultset, shifting its position.

An optional bookmark passed as the first lvalue parameter to fetch(); or a vector of bookmarks gets passed as the first vector to fetch_fectors(). This retrieves each row's bookmark. The bookmark lvalue must be the first lvalue parameter.

x::sql::fetch::atbookmark fetches a row or vector of rows starting with the previously-obtained bookmark row, with an optional relative offset.