| 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 | /* |
| 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 | |
| 63 | std::vector<Customer> readCustomers(DB_QUERY_RESULT* result) |
| 64 | { |
nothing calls this directly
no test coverage detected