Skip to content

Commit

Permalink
cats: dird: refactoring of unnecessary return variable
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Jan 28, 2022
1 parent fe1159f commit 22d6c7f
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 279 deletions.
15 changes: 5 additions & 10 deletions core/src/cats/postgresql.cc
Expand Up @@ -296,27 +296,24 @@ void BareosDbPostgresql::CloseDatabase(JobControlRecord* jcr)

bool BareosDbPostgresql::ValidateConnection(void)
{
bool retval = false;

// Perform a null query to see if the connection is still valid.
DbLocker _{this};
if (!SqlQueryWithoutHandler("SELECT 1", true)) {
// Try resetting the connection.
PQreset(db_handle_);
if (PQstatus(db_handle_) != CONNECTION_OK) { return retval; }
if (PQstatus(db_handle_) != CONNECTION_OK) { return false; }

SqlQueryWithoutHandler("SET datestyle TO 'ISO, YMD'");
SqlQueryWithoutHandler("SET cursor_tuple_fraction=1");
SqlQueryWithoutHandler("SET standard_conforming_strings=on");

// Retry the null query.
if (!SqlQueryWithoutHandler("SELECT 1", true)) { return retval; }
if (!SqlQueryWithoutHandler("SELECT 1", true)) { return false; }
}

SqlFreeResult();
retval = true;

return retval;
return true;
}

/**
Expand Down Expand Up @@ -549,16 +546,14 @@ bool BareosDbPostgresql::SqlQueryWithHandler(const char* query,
void* ctx)
{
SQL_ROW row;
bool retval = true;

Dmsg1(500, "SqlQueryWithHandler starts with '%s'\n", query);

DbLocker _{this};
if (!SqlQueryWithoutHandler(query, QF_STORE_RESULT)) {
Mmsg(errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror());
Dmsg0(500, "SqlQueryWithHandler failed\n");
retval = false;
return retval;
return false;
}

Dmsg0(500, "SqlQueryWithHandler succeeded. checking handler\n");
Expand All @@ -574,7 +569,7 @@ bool BareosDbPostgresql::SqlQueryWithHandler(const char* query,

Dmsg0(500, "SqlQueryWithHandler finished\n");

return retval;
return true;
}

/**
Expand Down

0 comments on commit 22d6c7f

Please sign in to comment.