Skip to content

Commit 72a95f1

Browse files
fix PostgreSqlClient
1 parent 274b0a1 commit 72a95f1

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

include/database/PostgreSqlClient.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class PostgreSqlClient : public DatabaseBackend {
132132
void ReleaseConnection(PGconn* conn);
133133
PGconn* CreateNewConnection();
134134
void CloseConnection(PGconn* conn);
135-
bool TestConnection(PGconn* conn);
135+
bool TestConnection(PGconn* conn) const;
136136

137137
// Connection pool management
138138
void MaintainPool();

src/database/PostgreSqlClient.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ void PostgreSqlClient::CloseConnection(PGconn* conn) {
413413
}
414414
}
415415

416-
bool PostgreSqlClient::TestConnection(PGconn* conn) {
416+
bool PostgreSqlClient::TestConnection(PGconn* conn) const {
417417
if (!conn) {
418418
return false;
419419
}
@@ -612,15 +612,11 @@ nlohmann::json PostgreSqlClient::ExecuteQuery(PGconn* conn, const std::string& s
612612

613613
// Get last insert ID if applicable using safe conversion
614614
if (status == PGRES_COMMAND_OK && sql.find("INSERT") != std::string::npos) {
615-
const char* insertId = PQoidValue(result);
616-
if (insertId) {
617-
int64_t tempId;
618-
if (SafeStringToInt64(insertId, tempId)) {
619-
lastInsertId_ = tempId;
620-
} else {
621-
lastInsertId_ = 0;
622-
Logger::Warn("Failed to parse last insert ID: {}", insertId);
623-
}
615+
Oid insertId = PQoidValue(result);
616+
if (insertId != InvalidOid) {
617+
lastInsertId_ = static_cast<int64_t>(insertId);
618+
} else {
619+
lastInsertId_ = 0;
624620
}
625621

626622
const char* affected = PQcmdTuples(result);
@@ -687,15 +683,11 @@ bool PostgreSqlClient::ExecuteCommand(PGconn* conn, const std::string& sql,
687683

688684
// Get last insert ID if applicable using safe conversion
689685
if (status == PGRES_COMMAND_OK && sql.find("INSERT") != std::string::npos) {
690-
const char* insertId = PQoidValue(result);
691-
if (insertId) {
692-
int64_t tempId;
693-
if (SafeStringToInt64(insertId, tempId)) {
694-
lastInsertId_ = tempId;
695-
} else {
696-
lastInsertId_ = 0;
697-
Logger::Warn("Failed to parse last insert ID: {}", insertId);
698-
}
686+
Oid insertId = PQoidValue(result);
687+
if (insertId != InvalidOid) {
688+
lastInsertId_ = static_cast<int64_t>(insertId);
689+
} else {
690+
lastInsertId_ = 0;
699691
}
700692
}
701693

@@ -1521,4 +1513,4 @@ bool PostgreSqlClient::ShouldReconnect(PGconn* conn) const {
15211513
PQclear(result);
15221514

15231515
return execStatus != PGRES_TUPLES_OK;
1524-
}
1516+
}

0 commit comments

Comments
 (0)