You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-05 00:28:52 +02:00
Update db/postgres modules to recent coding standards.
Add const as appropriate and avoid initializing variables if the variable will definitely be set later on or is immediately returned.
This commit is contained in:
@ -40,7 +40,9 @@ pgClientFreeResource(THIS_VOID)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN PgClient *
|
||||
pgClientNew(const String *host, const unsigned int port, const String *database, const String *user, const TimeMSec timeout)
|
||||
pgClientNew(
|
||||
const String *const host, const unsigned int port, const String *const database, const String *const user,
|
||||
const TimeMSec timeout)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, host);
|
||||
@ -76,7 +78,7 @@ pgClientNew(const String *host, const unsigned int port, const String *database,
|
||||
Just ignore notices and warnings
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
pgClientNoticeProcessor(void *arg, const char *message)
|
||||
pgClientNoticeProcessor(void *const arg, const char *const message)
|
||||
{
|
||||
(void)arg;
|
||||
(void)message;
|
||||
@ -86,7 +88,7 @@ pgClientNoticeProcessor(void *arg, const char *message)
|
||||
Encode string to escape ' and \
|
||||
***********************************************************************************************************************************/
|
||||
static String *
|
||||
pgClientEscape(const String *string)
|
||||
pgClientEscape(const String *const string)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STRING, string);
|
||||
@ -94,7 +96,7 @@ pgClientEscape(const String *string)
|
||||
|
||||
ASSERT(string != NULL);
|
||||
|
||||
String *result = strCatZ(strNew(), "'");
|
||||
String *const result = strCatZ(strNew(), "'");
|
||||
|
||||
// Iterate all characters in the string
|
||||
for (unsigned stringIdx = 0; stringIdx < strSize(string); stringIdx++)
|
||||
@ -115,7 +117,7 @@ pgClientEscape(const String *string)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN PgClient *
|
||||
pgClientOpen(PgClient *this)
|
||||
pgClientOpen(PgClient *const this)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(PG_CLIENT, this);
|
||||
@ -127,7 +129,7 @@ pgClientOpen(PgClient *this)
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Base connection string
|
||||
String *connInfo = strCatFmt(
|
||||
String *const connInfo = strCatFmt(
|
||||
strNew(), "dbname=%s port=%u", strZ(pgClientEscape(pgClientDatabase(this))), pgClientPort(this));
|
||||
|
||||
// Add user if specified
|
||||
@ -188,7 +190,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
}
|
||||
|
||||
// Wait for a result
|
||||
Wait *wait = waitNew(pgClientTimeout(this));
|
||||
Wait *const wait = waitNew(pgClientTimeout(this));
|
||||
bool busy = false;
|
||||
|
||||
do
|
||||
@ -201,7 +203,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
// If the query is still busy after the timeout attempt to cancel
|
||||
if (busy)
|
||||
{
|
||||
PGcancel *cancel = PQgetCancel(this->connection);
|
||||
PGcancel *const cancel = PQgetCancel(this->connection);
|
||||
|
||||
// If cancel is NULL then more than likely the server process crashed or disconnected
|
||||
if (cancel == NULL)
|
||||
@ -222,7 +224,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
}
|
||||
|
||||
// Get the result (even if query was cancelled -- to prevent the connection being left in a bad state)
|
||||
PGresult *pgResult = PQgetResult(this->connection);
|
||||
PGresult *const pgResult = PQgetResult(this->connection);
|
||||
|
||||
TRY_BEGIN()
|
||||
{
|
||||
@ -231,7 +233,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
THROW_FMT(DbQueryError, "query '%s' timed out after %" PRIu64 "ms", strZ(query), pgClientTimeout(this));
|
||||
|
||||
// If this was a command that returned no results then we are done
|
||||
ExecStatusType resultStatus = PQresultStatus(pgResult);
|
||||
const ExecStatusType resultStatus = PQresultStatus(pgResult);
|
||||
|
||||
if (resultStatus == PGRES_COMMAND_OK)
|
||||
{
|
||||
@ -254,8 +256,8 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
// Fetch row and column values
|
||||
PackWrite *const pack = pckWriteNewP();
|
||||
|
||||
int rowTotal = PQntuples(pgResult);
|
||||
int columnTotal = PQnfields(pgResult);
|
||||
const int rowTotal = PQntuples(pgResult);
|
||||
const int columnTotal = PQnfields(pgResult);
|
||||
|
||||
if (resultType != pgClientQueryResultAny)
|
||||
{
|
||||
@ -267,7 +269,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
}
|
||||
|
||||
// Get column types
|
||||
Oid *columnType = memNew(sizeof(int) * (size_t)columnTotal);
|
||||
Oid *const columnType = memNew(sizeof(int) * (size_t)columnTotal);
|
||||
|
||||
for (int columnIdx = 0; columnIdx < columnTotal; columnIdx++)
|
||||
columnType[columnIdx] = PQftype(pgResult, columnIdx);
|
||||
@ -280,7 +282,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
|
||||
for (int columnIdx = 0; columnIdx < columnTotal; columnIdx++)
|
||||
{
|
||||
char *value = PQgetvalue(pgResult, rowIdx, columnIdx);
|
||||
const char *const value = PQgetvalue(pgResult, rowIdx, columnIdx);
|
||||
|
||||
// If value is zero-length then check if it is null
|
||||
if (value[0] == '\0' && PQgetisnull(pgResult, rowIdx, columnIdx))
|
||||
@ -354,7 +356,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
pgClientClose(PgClient *this)
|
||||
pgClientClose(PgClient *const this)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(PG_CLIENT, this);
|
||||
|
@ -102,7 +102,7 @@ typedef struct PgControlCommon
|
||||
Get the interface for a PostgreSQL version
|
||||
***********************************************************************************************************************************/
|
||||
static const PgInterface *
|
||||
pgInterfaceVersion(unsigned int pgVersion)
|
||||
pgInterfaceVersion(const unsigned int pgVersion)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
@ -169,7 +169,7 @@ pgDbIsSystemId(const unsigned int id)
|
||||
Check expected WAL segment size for older PostgreSQL versions
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
pgWalSegmentSizeCheck(unsigned int pgVersion, unsigned int walSegmentSize)
|
||||
pgWalSegmentSizeCheck(const unsigned int pgVersion, const unsigned int walSegmentSize)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
@ -278,7 +278,7 @@ pgControlCrcUpdate(Buffer *const controlFile, const unsigned int pgVersion, cons
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static PgControl
|
||||
pgControlFromBuffer(const Buffer *controlFile, const String *const pgVersionForce)
|
||||
pgControlFromBuffer(const Buffer *const controlFile, const String *const pgVersionForce)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(BUFFER, controlFile);
|
||||
@ -364,7 +364,7 @@ pgControlBufferFromFile(const Storage *const storage, const String *const pgVers
|
||||
|
||||
ASSERT(storage != NULL);
|
||||
|
||||
Buffer *result = NULL;
|
||||
Buffer *result;
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
@ -429,7 +429,7 @@ pgControlFromFile(const Storage *const storage, const String *const pgVersionFor
|
||||
ASSERT(storage != NULL);
|
||||
|
||||
Buffer *const buffer = pgControlBufferFromFile(storage, pgVersionForce);
|
||||
PgControl result = pgControlFromBuffer(buffer, pgVersionForce);
|
||||
const PgControl result = pgControlFromBuffer(buffer, pgVersionForce);
|
||||
|
||||
bufFree(buffer);
|
||||
|
||||
@ -459,7 +459,7 @@ pgControlCheckpointInvalidate(Buffer *const buffer, const String *const pgVersio
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN uint32_t
|
||||
pgControlVersion(unsigned int pgVersion)
|
||||
pgControlVersion(const unsigned int pgVersion)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
@ -482,7 +482,7 @@ typedef struct PgWalCommon
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN PgWal
|
||||
pgWalFromBuffer(const Buffer *walBuffer, const String *const pgVersionForce)
|
||||
pgWalFromBuffer(const Buffer *const walBuffer, const String *const pgVersionForce)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(BUFFER, walBuffer);
|
||||
@ -535,7 +535,7 @@ pgWalFromBuffer(const Buffer *walBuffer, const String *const pgVersionForce)
|
||||
}
|
||||
|
||||
FN_EXTERN PgWal
|
||||
pgWalFromFile(const String *walFile, const Storage *storage, const String *const pgVersionForce)
|
||||
pgWalFromFile(const String *const walFile, const Storage *const storage, const String *const pgVersionForce)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, walFile);
|
||||
@ -544,12 +544,12 @@ pgWalFromFile(const String *walFile, const Storage *storage, const String *const
|
||||
|
||||
ASSERT(walFile != NULL);
|
||||
|
||||
PgWal result = {0};
|
||||
PgWal result;
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Read WAL segment header
|
||||
Buffer *walBuffer = storageGetP(storageNewReadP(storage, walFile), .exactSize = PG_WAL_HEADER_SIZE);
|
||||
const Buffer *const walBuffer = storageGetP(storageNewReadP(storage, walFile), .exactSize = PG_WAL_HEADER_SIZE);
|
||||
|
||||
result = pgWalFromBuffer(walBuffer, pgVersionForce);
|
||||
}
|
||||
@ -560,18 +560,18 @@ pgWalFromFile(const String *walFile, const Storage *storage, const String *const
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN String *
|
||||
pgTablespaceId(unsigned int pgVersion, unsigned int pgCatalogVersion)
|
||||
pgTablespaceId(const unsigned int pgVersion, const unsigned int pgCatalogVersion)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
FUNCTION_TEST_PARAM(UINT, pgCatalogVersion);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
String *result = NULL;
|
||||
String *result;
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
String *pgVersionStr = pgVersionToStr(pgVersion);
|
||||
const String *const pgVersionStr = pgVersionToStr(pgVersion);
|
||||
|
||||
MEM_CONTEXT_PRIOR_BEGIN()
|
||||
{
|
||||
@ -596,7 +596,7 @@ pgLsnFromStr(const String *lsn)
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
StringList *lsnPart = strLstNewSplit(lsn, FSLASH_STR);
|
||||
const StringList *const lsnPart = strLstNewSplit(lsn, FSLASH_STR);
|
||||
|
||||
CHECK(FormatError, strLstSize(lsnPart) == 2, "lsn requires two parts");
|
||||
|
||||
@ -608,7 +608,7 @@ pgLsnFromStr(const String *lsn)
|
||||
}
|
||||
|
||||
FN_EXTERN String *
|
||||
pgLsnToStr(uint64_t lsn)
|
||||
pgLsnToStr(const uint64_t lsn)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT64, lsn);
|
||||
@ -619,7 +619,7 @@ pgLsnToStr(uint64_t lsn)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN String *
|
||||
pgLsnToWalSegment(uint32_t timeline, uint64_t lsn, unsigned int walSegmentSize)
|
||||
pgLsnToWalSegment(const uint32_t timeline, const uint64_t lsn, const unsigned int walSegmentSize)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, timeline);
|
||||
@ -697,7 +697,7 @@ pgLsnRangeToWalSegmentList(
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN const String *
|
||||
pgLsnName(unsigned int pgVersion)
|
||||
pgLsnName(const unsigned int pgVersion)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
@ -710,7 +710,7 @@ pgLsnName(unsigned int pgVersion)
|
||||
Get WAL name (wal/xlog) for a PostgreSQL version
|
||||
***********************************************************************************************************************************/
|
||||
FN_EXTERN const String *
|
||||
pgWalName(unsigned int pgVersion)
|
||||
pgWalName(const unsigned int pgVersion)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
@ -721,7 +721,7 @@ pgWalName(unsigned int pgVersion)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN const String *
|
||||
pgWalPath(unsigned int pgVersion)
|
||||
pgWalPath(const unsigned int pgVersion)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
@ -732,7 +732,7 @@ pgWalPath(unsigned int pgVersion)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN const String *
|
||||
pgXactPath(unsigned int pgVersion)
|
||||
pgXactPath(const unsigned int pgVersion)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgVersion);
|
||||
@ -767,7 +767,7 @@ pgVersionFromStr(const String *const version)
|
||||
}
|
||||
|
||||
FN_EXTERN String *
|
||||
pgVersionToStr(unsigned int version)
|
||||
pgVersionToStr(const unsigned int version)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, version);
|
||||
|
Reference in New Issue
Block a user