Add size() function to mysql::char_result_t #562

This commit is contained in:
Roland Bock
2024-03-24 09:20:54 +01:00
parent 93ab3fef86
commit fdbe08946b
2 changed files with 9 additions and 0 deletions

View File

@@ -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 <typename ResultRow>
void next(ResultRow& result_row)
{

View File

@@ -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()));