From fdbe08946b2df60d09397e85247ab2c6a164ebfb Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 24 Mar 2024 09:20:54 +0100 Subject: [PATCH] Add size() function to mysql::char_result_t #562 --- include/sqlpp11/mysql/char_result.h | 5 +++++ tests/mysql/usage/Select.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/sqlpp11/mysql/char_result.h b/include/sqlpp11/mysql/char_result.h index e05ac2fb..1afbf6b6 100644 --- a/include/sqlpp11/mysql/char_result.h +++ b/include/sqlpp11/mysql/char_result.h @@ -68,6 +68,11 @@ namespace sqlpp return _handle == rhs._handle; } + size_t size() const + { + return _handle ? mysql_num_rows(_handle->mysql_res) : size_t{}; + } + template void next(ResultRow& result_row) { diff --git a/tests/mysql/usage/Select.cpp b/tests/mysql/usage/Select.cpp index 3f4d12b2..96eb3e5a 100644 --- a/tests/mysql/usage/Select.cpp +++ b/tests/mysql/usage/Select.cpp @@ -107,6 +107,10 @@ int Select(int, char*[]) db(insert_into(tab).set(tab.gamma = true, tab.beta = "cheesecake")); testSelectAll(db, 3); + // Test size functionality + const auto test_size = db(select(all_of(tab)).from(tab).unconditionally()); + assert(test_size.size() == 3ull); + // test functions and operators db(select(all_of(tab)).from(tab).where(tab.alpha.is_null())); db(select(all_of(tab)).from(tab).where(tab.alpha.is_not_null()));