MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Exercises/Modules/Chapter 16/Soln16_06/Soln16_06.cpp:43–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41void print(std::ostream& stream, const Customer& customer); // Print a given customer to a given output stream
42
43int main()
44{
45 DBConnectionRAII connection{ db_connect() };
46 try
47 {
48 DBQueryResultRAII result{ db_query(connection, "SELECT * FROM CUSTOMER_TABEL") };
49 if (!result)
50 {
51 throw DatabaseException{"Query failed"};
52 }
53
54 std::vector customers{ readCustomers(result) };
55
56 if (customers.empty())
57 {
58 std::cerr << "No customers found?" << std::endl;
59 return 2;
60 }
61
62 for (auto& customer : customers)
63 {
64 print(std::cout, customer);
65 }
66 }
67 catch (const std::exception& caught)
68 {
69 std::cerr << caught.what() << std::endl;
70 return 1;
71 }
72}
73
74std::vector<Customer> readCustomers(DB_QUERY_RESULT* result)
75{

Callers

nothing calls this directly

Calls 6

db_connectFunction · 0.70
db_queryFunction · 0.70
readCustomersFunction · 0.70
printFunction · 0.70
emptyMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected