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

Function main

Exercises/NoModules/Chapter 18/Soln18_04/Soln18_04.cpp:19–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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