|
10 | 10 | DatabaseConnection::DatabaseConnection(const std::string& endpoint, int port, |
11 | 11 | const std::string& dbname, const std::string& user, |
12 | 12 | const std::string& password) { |
13 | | - connection_string = |
14 | | - "host=" + endpoint + " " |
15 | | - "port=" + std::to_string(port) + " " |
16 | | - "dbname=" + dbname + " " |
17 | | - "user=" + user + " " |
18 | | - "password=" + password + " " |
19 | | - "connect_timeout=3"; |
| 13 | + connection_string = std::format("host={} port={} dbname={} user={} password={} connect_timeout=3", |
| 14 | + endpoint, port, dbname, user, password); |
20 | 15 | } |
21 | 16 |
|
22 | 17 | void DatabaseConnection::executeQuery(const std::string& query) const { |
@@ -49,13 +44,11 @@ void DatabaseConnection::executeQuery(const std::string& query) const { |
49 | 44 | txn.commit(); |
50 | 45 |
|
51 | 46 | } catch (const pqxx::broken_connection& e) { |
52 | | - std::cerr << "Connection error: " << e.what() << std::endl; |
53 | | - } catch (const pqxx::sql_error& e) { |
54 | | - std::cerr << "SQL error: " << e.what() << std::endl; |
55 | | - std::cerr << "Query was: " << e.query() << std::endl; |
56 | | - } catch (const pqxx::usage_error& e) { |
57 | | - std::cerr << "Usage error: " << e.what() << std::endl; |
58 | | - } catch (const std::exception& e) { |
59 | | - std::cerr << "General error: " << e.what() << std::endl; |
60 | | - } |
| 47 | + std::cerr << "Connection error: " << e.what() << std::endl; |
| 48 | + } catch (const pqxx::sql_error& e) { |
| 49 | + std::cerr << "SQL error: " << e.what() << std::endl; |
| 50 | + std::cerr << "Query was: " << e.query() << std::endl; |
| 51 | + } catch (const pqxx::usage_error& e) { |
| 52 | + std::cerr << "Usage error: " << e.what() << std::endl; |
| 53 | + } |
61 | 54 | } |
0 commit comments