@@ -18,13 +18,13 @@ typedef struct
1818int lineno ;
1919char stmtID [STMTID_SIZE ];
2020char * 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
2525static int nextStmtID = 1 ;
2626static const int stmtCacheNBuckets = 2039 ;/* # buckets - a prime # */
27- static const int stmtCacheEntPerBucket = 8 ;/* # entries/bucket */
27+ static const int stmtCacheEntPerBucket = 8 ;/* # entries/bucket */
2828static stmtCacheEntry stmtCacheEntries [16384 ]= {{0 , {0 },0 ,0 ,0 }};
2929
3030static bool deallocate_one (int lineno ,enum COMPAT_MODE c ,struct connection * con ,
@@ -64,9 +64,9 @@ replace_variables(char **text, int lineno)
6464ptr += 2 ;/* skip '::' */
6565else
6666{
67+ /* a rough guess of the size we need: */
68+ int buffersize = sizeof (int )* CHAR_BIT * 10 /3 ;
6769int len ;
68- int buffersize = sizeof (int )* CHAR_BIT * 10 /3 ;/* a rough guess of the
69- * size we need */
7070char * buffer ,
7171* newcopy ;
7272
@@ -75,7 +75,8 @@ replace_variables(char **text, int lineno)
7575
7676snprintf (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 */ ;
7980if (!(newcopy = (char * )ecpg_alloc (strlen (* text )- len + strlen (buffer )+ 1 ,lineno )))
8081{
8182ecpg_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 */
160161bool
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{
163165struct connection * con ;
164166struct prepared_statement * this ,
165167* prev ;
166168
167169(void )questionmarks ;/* quiet the compiler */
170+
168171con = ecpg_get_connection (connection_name );
169172
170173if (!ecpg_init (con ,connection_name ,lineno ))
@@ -185,7 +188,9 @@ ecpg_find_prepared_statement(const char *name,
185188struct 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{
190195if (strcmp (this -> name ,name )== 0 )
191196{
@@ -198,7 +203,8 @@ ecpg_find_prepared_statement(const char *name,
198203}
199204
200205static 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{
203209bool r = false;
204210
@@ -217,7 +223,9 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct pr
217223sprintf (text ,"deallocate \"%s\"" ,this -> name );
218224query = PQexec (this -> stmt -> connection -> connection ,text );
219225ecpg_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{
222230PQclear (query );
223231r = true;
@@ -288,7 +296,8 @@ ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
288296bool
289297ECPGdeallocate_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
294303char *
@@ -323,9 +332,9 @@ HashStmt(const char *ecpgQuery)
323332rotVal ;
324333
325334stmtLeng = 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
330339hashVal = 0 ;
331340for (stmtIx = 0 ;stmtIx < hashLeng ;++ stmtIx )
@@ -337,7 +346,7 @@ HashStmt(const char *ecpgQuery)
337346}
338347
339348bucketNo = hashVal %stmtCacheNBuckets ;
340- bucketNo += 1 ;/* don't use bucket # 0 */
349+ bucketNo += 1 ;/* don't use bucket # 0 */
341350
342351return (bucketNo * stmtCacheEntPerBucket );
343352}
@@ -353,21 +362,21 @@ SearchStmtCache(const char *ecpgQuery)
353362int entNo ,
354363entIx ;
355364
356- /* hash the statement */
365+ /* hash the statement */
357366entNo = HashStmt (ecpgQuery );
358367
359- /* search the cache */
368+ /* search the cache */
360369for (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{
364373if (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 */
371380if (entIx >=stmtCacheEntPerBucket )
372381entNo = 0 ;
373382
@@ -380,27 +389,28 @@ SearchStmtCache(const char *ecpgQuery)
380389 * OR negative error code
381390 */
382391static 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{
385395stmtCacheEntry * entry ;
386396struct connection * con ;
387397struct prepared_statement * this ,
388398* prev ;
389399
390400entry = & 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 */
392402return 0 ;
393403
394404con = ecpg_get_connection (entry -> connection );
395405
396- /* free the 'prepared_statement' list entry */
406+ /* free the 'prepared_statement' list entry */
397407this = ecpg_find_prepared_statement (entry -> stmtID ,con ,& prev );
398408if (this && !deallocate_one (lineno ,compat ,con ,prev ,this ))
399409return -1 ;
400410
401411entry -> stmtID [0 ]= '\0' ;
402412
403- /* free the memory used by the cache entry */
413+ /* free the memory used by the cache entry */
404414if (entry -> ecpgQuery )
405415{
406416ecpg_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 */
417427static 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 */
421431int compat ,/* compatibility level */
422- const char * ecpgQuery )/* query */
432+ const char * ecpgQuery )/* query */
423433{
424434int ix ,
425435initEntNo ,
426436luEntNo ,
427437entNo ;
428438stmtCacheEntry * entry ;
429439
430- /* hash the statement */
440+ /* hash the statement */
431441initEntNo = HashStmt (ecpgQuery );
432442
433- /* search for an unused entry */
443+ /* search for an unused entry */
434444entNo = 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 */
437447for (ix = 0 ;ix < stmtCacheEntPerBucket ;++ ix )
438448{
439449entry = & stmtCacheEntries [entNo ];
440- if (!entry -> stmtID [0 ])/* unused entry -use it */
450+ if (!entry -> stmtID [0 ])/* unused entry -use it */
441451break ;
442452if (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 */
452465if (ecpg_freeStmtCacheEntry (lineno ,compat ,entNo )< 0 )
453466return -1 ;
454467
455- /* add the query to the entry */
468+ /* add the query to the entry */
456469entry = & stmtCacheEntries [entNo ];
457470entry -> lineno = lineno ;
458471entry -> ecpgQuery = ecpg_strdup (ecpgQuery ,lineno );
@@ -469,10 +482,10 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
469482{
470483int entNo ;
471484
472- /* search the statement cache for this statement */
485+ /* search the statement cache for this statement */
473486entNo = SearchStmtCache (query );
474487
475- /* if not found - add the statement to the cache */
488+ /* if not found - add the statement to the cache */
476489if (entNo )
477490{
478491char * stmtID ;