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

Function main

Exercises/NoModules/Chapter 16/Exer16_06/Exer16_06.cpp:17–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected