Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 92dff34

Browse filesBrowse files
committed
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.
1 parent 28d750c commit 92dff34
Copy full SHA for 92dff34

File tree

Expand file treeCollapse file tree

1 file changed

+56
-43
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+56
-43
lines changed

‎src/interfaces/ecpg/ecpglib/prepare.c

Copy file name to clipboardExpand all lines: src/interfaces/ecpg/ecpglib/prepare.c
+56-43Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ typedef struct
1818
int lineno;
1919
char stmtID[STMTID_SIZE];
2020
char *ecpgQuery;
21-
long execs; /* # of executions */
22-
const char *connection; /* connection for the statement */
21+
long execs; /* # of executions */
22+
const char *connection; /* connection for the statement */
2323
} stmtCacheEntry;
2424

2525
static int nextStmtID = 1;
2626
static const int stmtCacheNBuckets = 2039; /* # buckets - a prime # */
27-
static const int stmtCacheEntPerBucket = 8; /* # entries/bucket */
27+
static const int stmtCacheEntPerBucket = 8; /* # entries/bucket */
2828
static stmtCacheEntry stmtCacheEntries[16384] = {{0, {0}, 0, 0, 0}};
2929

3030
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con,
@@ -64,9 +64,9 @@ replace_variables(char **text, int lineno)
6464
ptr += 2; /* skip '::' */
6565
else
6666
{
67+
/* a rough guess of the size we need: */
68+
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3;
6769
int len;
68-
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
69-
* size we need */
7070
char *buffer,
7171
*newcopy;
7272

@@ -75,7 +75,8 @@ replace_variables(char **text, int lineno)
7575

7676
snprintf(buffer, buffersize, "$%d", counter++);
7777

78-
for (len = 1; (*text)[ptr + len] && isvarchar((*text)[ptr + len]); len++);
78+
for (len = 1; (*text)[ptr + len] && isvarchar((*text)[ptr + len]); len++)
79+
/* skip */ ;
7980
if (!(newcopy = (char *) ecpg_alloc(strlen(*text) -len + strlen(buffer) + 1, lineno)))
8081
{
8182
ecpg_free(buffer);
@@ -158,13 +159,15 @@ prepare_common(int lineno, struct connection *con, const char *name, const char
158159
/* handle the EXEC SQL PREPARE statement */
159160
/* questionmarks is not needed but remains in there for the time being to not change the API */
160161
bool
161-
ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
162+
ECPGprepare(int lineno, const char *connection_name, const bool questionmarks,
163+
const char *name, const char *variable)
162164
{
163165
struct connection *con;
164166
struct prepared_statement *this,
165167
*prev;
166168

167169
(void) questionmarks; /* quiet the compiler */
170+
168171
con = ecpg_get_connection(connection_name);
169172

170173
if (!ecpg_init(con, connection_name, lineno))
@@ -185,7 +188,9 @@ ecpg_find_prepared_statement(const char *name,
185188
struct prepared_statement *this,
186189
*prev;
187190

188-
for (this = con->prep_stmts, prev = NULL; this != NULL; prev = this, this = this->next)
191+
for (this = con->prep_stmts, prev = NULL;
192+
this != NULL;
193+
prev = this, this = this->next)
189194
{
190195
if (strcmp(this->name, name) == 0)
191196
{
@@ -198,7 +203,8 @@ ecpg_find_prepared_statement(const char *name,
198203
}
199204

200205
static bool
201-
deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
206+
deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con,
207+
struct prepared_statement *prev, struct prepared_statement *this)
202208
{
203209
bool r = false;
204210

@@ -217,7 +223,9 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct pr
217223
sprintf(text, "deallocate \"%s\"", this->name);
218224
query = PQexec(this->stmt->connection->connection, text);
219225
ecpg_free(text);
220-
if (ecpg_check_PQresult(query, lineno, this->stmt->connection->connection, this->stmt->compat))
226+
if (ecpg_check_PQresult(query, lineno,
227+
this->stmt->connection->connection,
228+
this->stmt->compat))
221229
{
222230
PQclear(query);
223231
r = true;
@@ -288,7 +296,8 @@ ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
288296
bool
289297
ECPGdeallocate_all(int lineno, int compat, const char *connection_name)
290298
{
291-
return ecpg_deallocate_all_conn(lineno, compat, ecpg_get_connection(connection_name));
299+
return ecpg_deallocate_all_conn(lineno, compat,
300+
ecpg_get_connection(connection_name));
292301
}
293302

294303
char *
@@ -323,9 +332,9 @@ HashStmt(const char *ecpgQuery)
323332
rotVal;
324333

325334
stmtLeng = strlen(ecpgQuery);
326-
hashLeng = 50; /* use 1st 50 characters of statement */
327-
if (hashLeng > stmtLeng) /* if the statement isn't that long */
328-
hashLeng = stmtLeng; /* use its actual length */
335+
hashLeng = 50; /* use 1st 50 characters of statement */
336+
if (hashLeng > stmtLeng) /* if the statement isn't that long */
337+
hashLeng = stmtLeng; /* use its actual length */
329338

330339
hashVal = 0;
331340
for (stmtIx = 0; stmtIx < hashLeng; ++stmtIx)
@@ -337,7 +346,7 @@ HashStmt(const char *ecpgQuery)
337346
}
338347

339348
bucketNo = hashVal % stmtCacheNBuckets;
340-
bucketNo += 1; /* don't use bucket # 0 */
349+
bucketNo += 1; /* don't use bucket # 0 */
341350

342351
return (bucketNo * stmtCacheEntPerBucket);
343352
}
@@ -353,21 +362,21 @@ SearchStmtCache(const char *ecpgQuery)
353362
int entNo,
354363
entIx;
355364

356-
/* hash the statement */
365+
/* hash the statement */
357366
entNo = HashStmt(ecpgQuery);
358367

359-
/* search the cache */
368+
/* search the cache */
360369
for (entIx = 0; entIx < stmtCacheEntPerBucket; ++entIx)
361370
{
362-
if (stmtCacheEntries[entNo].stmtID[0]) /* check if entry is in use */
371+
if (stmtCacheEntries[entNo].stmtID[0]) /* check if entry is in use */
363372
{
364373
if (strcmp(ecpgQuery, stmtCacheEntries[entNo].ecpgQuery) == 0)
365-
break; /* found it */
374+
break; /* found it */
366375
}
367-
++entNo; /* incr entry # */
376+
++entNo; /* incr entry # */
368377
}
369378

370-
/* if entry wasn't found - set entry # to zero */
379+
/* if entry wasn't found - set entry # to zero */
371380
if (entIx >= stmtCacheEntPerBucket)
372381
entNo = 0;
373382

@@ -380,27 +389,28 @@ SearchStmtCache(const char *ecpgQuery)
380389
* OR negative error code
381390
*/
382391
static int
383-
ecpg_freeStmtCacheEntry(int lineno, int compat, int entNo) /* entry # to free */
392+
ecpg_freeStmtCacheEntry(int lineno, int compat,
393+
int entNo) /* entry # to free */
384394
{
385395
stmtCacheEntry *entry;
386396
struct connection *con;
387397
struct prepared_statement *this,
388398
*prev;
389399

390400
entry = &stmtCacheEntries[entNo];
391-
if (!entry->stmtID[0]) /* return if the entry isn't in use */
401+
if (!entry->stmtID[0]) /* return if the entry isn't in use */
392402
return 0;
393403

394404
con = ecpg_get_connection(entry->connection);
395405

396-
/* free the 'prepared_statement' list entry */
406+
/* free the 'prepared_statement' list entry */
397407
this = ecpg_find_prepared_statement(entry->stmtID, con, &prev);
398408
if (this && !deallocate_one(lineno, compat, con, prev, this))
399409
return -1;
400410

401411
entry->stmtID[0] = '\0';
402412

403-
/* free the memory used by the cache entry */
413+
/* free the memory used by the cache entry */
404414
if (entry->ecpgQuery)
405415
{
406416
ecpg_free(entry->ecpgQuery);
@@ -415,44 +425,47 @@ ecpg_freeStmtCacheEntry(int lineno, int compat, int entNo) /* entry # to free */
415425
* returns entry # in cache used OR negative error code
416426
*/
417427
static int
418-
AddStmtToCache(int lineno, /* line # of statement */
419-
const char *stmtID, /* statement ID */
420-
const char *connection, /* connection */
428+
AddStmtToCache(int lineno, /* line # of statement */
429+
const char *stmtID, /* statement ID */
430+
const char *connection, /* connection */
421431
int compat, /* compatibility level */
422-
const char *ecpgQuery) /* query */
432+
const char *ecpgQuery) /* query */
423433
{
424434
int ix,
425435
initEntNo,
426436
luEntNo,
427437
entNo;
428438
stmtCacheEntry *entry;
429439

430-
/* hash the statement */
440+
/* hash the statement */
431441
initEntNo = HashStmt(ecpgQuery);
432442

433-
/* search for an unused entry */
443+
/* search for an unused entry */
434444
entNo = initEntNo; /* start with the initial entry # for the
435-
* bucket */
436-
luEntNo = initEntNo; /* use it as the initial 'least used' entry */
445+
* bucket */
446+
luEntNo = initEntNo; /* use it as the initial 'least used' entry */
437447
for (ix = 0; ix < stmtCacheEntPerBucket; ++ix)
438448
{
439449
entry = &stmtCacheEntries[entNo];
440-
if (!entry->stmtID[0]) /* unused entry - use it */
450+
if (!entry->stmtID[0]) /* unused entry - use it */
441451
break;
442452
if (entry->execs < stmtCacheEntries[luEntNo].execs)
443-
luEntNo = entNo; /* save new 'least used' entry */
444-
++entNo; /* increment entry # */
453+
luEntNo = entNo; /* save new 'least used' entry */
454+
++entNo; /* increment entry # */
445455
}
446456

447-
/* if no unused entries were found - use the 'least used' entry found in the bucket */
448-
if (ix >= stmtCacheEntPerBucket) /* if no unused entries were found */
449-
entNo = luEntNo; /* re-use the 'least used' entry */
457+
/*
458+
* if no unused entries were found, re-use the 'least used' entry found in
459+
* the bucket
460+
*/
461+
if (ix >= stmtCacheEntPerBucket)
462+
entNo = luEntNo;
450463

451-
/* 'entNo' is the entry to use - make sure its free */
464+
/* 'entNo' is the entry to use - make sure its free */
452465
if (ecpg_freeStmtCacheEntry(lineno, compat, entNo) < 0)
453466
return -1;
454467

455-
/* add the query to the entry */
468+
/* add the query to the entry */
456469
entry = &stmtCacheEntries[entNo];
457470
entry->lineno = lineno;
458471
entry->ecpgQuery = ecpg_strdup(ecpgQuery, lineno);
@@ -469,10 +482,10 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
469482
{
470483
int entNo;
471484

472-
/* search the statement cache for this statement */
485+
/* search the statement cache for this statement */
473486
entNo = SearchStmtCache(query);
474487

475-
/* if not found - add the statement to the cache */
488+
/* if not found - add the statement to the cache */
476489
if (entNo)
477490
{
478491
char *stmtID;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.