2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-01-28 19:32:10 +00:00

Row reading reworks

- Removed distinction between row and owning_row
- Changed semantics for fetch_one to row& + bool
- Renamed all fetch_* fns to read_*
- Added row.clear()
This commit is contained in:
Ruben Perez
2021-02-19 21:23:40 +01:00
parent dd2447c6cb
commit 4c7ca0a1b4
38 changed files with 798 additions and 507 deletions

View File

@@ -8,6 +8,7 @@
//[example_query_async_coroutinescpp20
#include "boost/mysql/mysql.hpp"
#include "boost/mysql/row.hpp"
#include <boost/asio/io_context.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/co_spawn.hpp>
@@ -101,16 +102,15 @@ boost::asio::awaitable<void> start_query(
auto result = co_await conn.async_query(sql, boost::asio::use_awaitable);
/**
* Get all rows in the resultset. We will employ resultset::async_fetch_one(),
* which returns a single row at every call. The returned row is a pointer
* to memory owned by the resultset, and is re-used for each row. Thus, returned
* rows remain valid until the next call to async_fetch_one(). When no more
* rows are available, async_fetch_one returns nullptr.
*/
while (const boost::mysql::row* row =
co_await result.async_fetch_one(boost::asio::use_awaitable))
* Get all rows in the resultset. We will employ resultset::async_read_one(),
* which reads a single row at every call. The row is read in-place, preventing
* unnecessary copies. resultset::async_read_one() returns true if a row has been
* read, false if no more rows are available or an error occurred.
*/
boost::mysql::row row;
while (co_await result.async_read_one(row, boost::asio::use_awaitable))
{
print_employee(*row);
print_employee(row);
}
// Notify the MySQL server we want to quit, then close the underlying connection.