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