Formatting cleanup in ecpglib/prepare.c.

Looking at this code made my head hurt.  Format the comments more
like the way it's done elsewhere, break a few overly long lines.
No actual code changes in this commit.
This commit is contained in:
Tom Lane 2018-10-16 23:43:15 -04:00
parent 28d750c0cd
commit 92dff34116

View File

@ -64,9 +64,9 @@ replace_variables(char **text, int lineno)
ptr += 2; /* skip '::' */ ptr += 2; /* skip '::' */
else else
{ {
/* a rough guess of the size we need: */
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3;
int len; int len;
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
* size we need */
char *buffer, char *buffer,
*newcopy; *newcopy;
@ -75,7 +75,8 @@ replace_variables(char **text, int lineno)
snprintf(buffer, buffersize, "$%d", counter++); snprintf(buffer, buffersize, "$%d", counter++);
for (len = 1; (*text)[ptr + len] && isvarchar((*text)[ptr + len]); len++); for (len = 1; (*text)[ptr + len] && isvarchar((*text)[ptr + len]); len++)
/* skip */ ;
if (!(newcopy = (char *) ecpg_alloc(strlen(*text) -len + strlen(buffer) + 1, lineno))) if (!(newcopy = (char *) ecpg_alloc(strlen(*text) -len + strlen(buffer) + 1, lineno)))
{ {
ecpg_free(buffer); ecpg_free(buffer);
@ -158,13 +159,15 @@ prepare_common(int lineno, struct connection *con, const char *name, const char
/* handle the EXEC SQL PREPARE statement */ /* handle the EXEC SQL PREPARE statement */
/* questionmarks is not needed but remains in there for the time being to not change the API */ /* questionmarks is not needed but remains in there for the time being to not change the API */
bool bool
ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable) ECPGprepare(int lineno, const char *connection_name, const bool questionmarks,
const char *name, const char *variable)
{ {
struct connection *con; struct connection *con;
struct prepared_statement *this, struct prepared_statement *this,
*prev; *prev;
(void) questionmarks; /* quiet the compiler */ (void) questionmarks; /* quiet the compiler */
con = ecpg_get_connection(connection_name); con = ecpg_get_connection(connection_name);
if (!ecpg_init(con, connection_name, lineno)) if (!ecpg_init(con, connection_name, lineno))
@ -185,7 +188,9 @@ ecpg_find_prepared_statement(const char *name,
struct prepared_statement *this, struct prepared_statement *this,
*prev; *prev;
for (this = con->prep_stmts, prev = NULL; this != NULL; prev = this, this = this->next) for (this = con->prep_stmts, prev = NULL;
this != NULL;
prev = this, this = this->next)
{ {
if (strcmp(this->name, name) == 0) if (strcmp(this->name, name) == 0)
{ {
@ -198,7 +203,8 @@ ecpg_find_prepared_statement(const char *name,
} }
static bool static bool
deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this) deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con,
struct prepared_statement *prev, struct prepared_statement *this)
{ {
bool r = false; bool r = false;
@ -217,7 +223,9 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct pr
sprintf(text, "deallocate \"%s\"", this->name); sprintf(text, "deallocate \"%s\"", this->name);
query = PQexec(this->stmt->connection->connection, text); query = PQexec(this->stmt->connection->connection, text);
ecpg_free(text); ecpg_free(text);
if (ecpg_check_PQresult(query, lineno, this->stmt->connection->connection, this->stmt->compat)) if (ecpg_check_PQresult(query, lineno,
this->stmt->connection->connection,
this->stmt->compat))
{ {
PQclear(query); PQclear(query);
r = true; r = true;
@ -288,7 +296,8 @@ ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
bool bool
ECPGdeallocate_all(int lineno, int compat, const char *connection_name) ECPGdeallocate_all(int lineno, int compat, const char *connection_name)
{ {
return ecpg_deallocate_all_conn(lineno, compat, ecpg_get_connection(connection_name)); return ecpg_deallocate_all_conn(lineno, compat,
ecpg_get_connection(connection_name));
} }
char * char *
@ -380,7 +389,8 @@ SearchStmtCache(const char *ecpgQuery)
* OR negative error code * OR negative error code
*/ */
static int static int
ecpg_freeStmtCacheEntry(int lineno, int compat, int entNo) /* entry # to free */ ecpg_freeStmtCacheEntry(int lineno, int compat,
int entNo) /* entry # to free */
{ {
stmtCacheEntry *entry; stmtCacheEntry *entry;
struct connection *con; struct connection *con;
@ -444,9 +454,12 @@ AddStmtToCache(int lineno, /* line # of statement */
++entNo; /* increment entry # */ ++entNo; /* increment entry # */
} }
/* if no unused entries were found - use the 'least used' entry found in the bucket */ /*
if (ix >= stmtCacheEntPerBucket) /* if no unused entries were found */ * if no unused entries were found, re-use the 'least used' entry found in
entNo = luEntNo; /* re-use the 'least used' entry */ * the bucket
*/
if (ix >= stmtCacheEntPerBucket)
entNo = luEntNo;
/* 'entNo' is the entry to use - make sure its free */ /* 'entNo' is the entry to use - make sure its free */
if (ecpg_freeStmtCacheEntry(lineno, compat, entNo) < 0) if (ecpg_freeStmtCacheEntry(lineno, compat, entNo) < 0)