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