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

Function main

Exercises/Modules/Chapter 18/Soln18_05/Soln18_05.cpp:16–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14void print(std::ostream& stream, const Customer& customer); // Print a given customer to a given output stream
15
16int main()
17{
18 DBConnectionRAII connection{ db_connect() };
19 DBConnectionRAII moved_connection{ std::move(connection) };
20
21 try
22 {
23 DBQueryResultRAII result{ db_query(moved_connection, "SELECT * FROM CUSTOMER_TABEL") };
24 if (!result)
25 {
26 throw DatabaseException{"Query failed"};
27 }
28
29 DBQueryResultRAII moved_result;
30 moved_result = std::move(result);
31
32 std::vector<Customer> customers{ readCustomers(moved_result) };
33
34 if (customers.empty())
35 {
36 std::cerr << "No customers found?" << std::endl;
37 return 2;
38 }
39
40 for (auto& customer : customers)
41 {
42 print(std::cout, customer);
43 }
44 }
45 catch (std::exception& caught)
46 {
47 std::cerr << caught.what() << std::endl;
48 return 1;
49 }
50}
51
52std::vector<Customer> readCustomers(DB_QUERY_RESULT* result)
53{

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