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

Function main

Exercises/Modules/Chapter 18/Soln18_03/Soln18_03.cpp:19–61  ·  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 /*
23 DBConnectionRAII copy{ connection }; // Will not compile (copy constructor is deleted)
24
25 DBConnectionRAII otherConnection{ db_connect() };
26 otherConnection = connection; // Will not compile (copy assignment operator is deleted)
27 */
28 try
29 {
30 DBQueryResultRAII result{ db_query(connection, "SELECT * FROM CUSTOMER_TABEL") };
31 if (!result)
32 {
33 throw DatabaseException{"Query failed"};
34 }
35
36 /*
37 DBQueryResultRAII copy{ result }; // Will not compile (copy constructor is deleted)
38
39 DBQueryResultRAII otherResult{ db_query(connection, "SELECT * FROM CUSTOMER_TABEL") };
40 otherResult = result; // Will not compile (copy assignment operator is deleted)
41 */
42
43 std::vector<Customer> customers{ readCustomers(result) };
44
45 if (customers.empty())
46 {
47 std::cerr << "No customers found?" << std::endl;
48 return 2;
49 }
50
51 for (auto& customer : customers)
52 {
53 print(std::cout, customer);
54 }
55 }
56 catch (std::exception& caught)
57 {
58 std::cerr << caught.what() << std::endl;
59 return 1;
60 }
61}
62
63std::vector<Customer> readCustomers(DB_QUERY_RESULT* result)
64{

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