test16.cxx 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <iostream>
  2. #include <pqxx/connection>
  3. #include <pqxx/robusttransaction>
  4. #include "test_helpers.hxx"
  5. using namespace pqxx;
  6. // Test robusttransaction.
  7. namespace
  8. {
  9. void test_016()
  10. {
  11. connection conn;
  12. robusttransaction<> tx{conn};
  13. result R{tx.exec("SELECT * FROM pg_tables")};
  14. result::const_iterator c;
  15. for (c = std::begin(R); c != std::end(R); ++c)
  16. ;
  17. // See if back() and row comparison work properly
  18. PQXX_CHECK(
  19. std::size(R) >= 2, "Not enough rows in pg_tables to test, sorry!");
  20. --c;
  21. PQXX_CHECK_EQUAL(
  22. c->size(), std::size(R.back()),
  23. "Size mismatch between row iterator and back().");
  24. std::string const nullstr;
  25. for (pqxx::row::size_type i{0}; i < c->size(); ++i)
  26. PQXX_CHECK_EQUAL(
  27. c[i].as(nullstr), R.back()[i].as(nullstr), "Value mismatch in back().");
  28. PQXX_CHECK(*c == R.back(), "Row equality is broken.");
  29. PQXX_CHECK(not(*c != R.back()), "Row inequality is broken.");
  30. tx.commit();
  31. }
  32. PQXX_REGISTER_TEST(test_016);
  33. } // namespace