| 15 | void print(std::ostream& stream, const Customer& customer); // Print a given customer to a given output stream |
| 16 | |
| 17 | int 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 | |
| 54 | std::vector<Customer> readCustomers(DB_QUERY_RESULT* result) |
| 55 | { |
nothing calls this directly
no test coverage detected