1
- /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.25 2007/11/15 22:25:17 momjian Exp $ */
1
+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.26 2008/02/07 11:09:13 meskes Exp $ */
2
2
3
3
#define POSTGRES_ECPG_INTERNAL
4
4
#include "postgres_fe.h"
@@ -373,30 +373,26 @@ SearchStmtCache(const char *ecpgQuery)
373
373
* OR negative error code
374
374
*/
375
375
static int
376
- ecpg_freeStmtCacheEntry (int entNo ) /* entry # to free */
376
+ ecpg_freeStmtCacheEntry (int lineno , int compat , int entNo ) /* entry # to free */
377
377
{
378
378
stmtCacheEntry * entry ;
379
- PGresult * results ;
380
- char deallocText [100 ];
381
379
struct connection * con ;
380
+ struct prepared_statement * this , * prev ;
382
381
383
382
entry = & stmtCacheEntries [entNo ];
384
383
if (!entry -> stmtID [0 ]) /* return if the entry isn't in use */
385
384
return (0 );
386
385
387
386
con = ecpg_get_connection (entry -> connection );
388
- /* free the server resources for the statement */
389
- ecpg_log ("ecpg_freeStmtCacheEntry line %d: deallocate %s, cache entry #%d\n" , entry -> lineno , entry -> stmtID , entNo );
390
- sprintf (deallocText , "DEALLOCATE PREPARE %s" , entry -> stmtID );
391
- results = PQexec (con -> connection , deallocText );
392
387
393
- if (!ecpg_check_PQresult (results , entry -> lineno , con -> connection , ECPG_COMPAT_PGSQL ))
388
+ /* free the 'prepared_statement' list entry */
389
+ this = find_prepared_statement (entry -> stmtID , con , & prev );
390
+ if (this && !deallocate_one (lineno , compat , con , prev , this ))
394
391
return (-1 );
395
- PQclear (results );
396
392
397
393
entry -> stmtID [0 ] = '\0' ;
398
394
399
- /* free the memory used by the cache entry */
395
+ /* free the memory used by the cache entry */
400
396
if (entry -> ecpgQuery )
401
397
{
402
398
ecpg_free (entry -> ecpgQuery );
@@ -414,6 +410,7 @@ static int
414
410
AddStmtToCache (int lineno , /* line # of statement */
415
411
char * stmtID , /* statement ID */
416
412
const char * connection , /* connection */
413
+ int compat , /* compatibility level */
417
414
const char * ecpgQuery ) /* query */
418
415
{
419
416
int ix ,
@@ -444,7 +441,7 @@ AddStmtToCache(int lineno, /* line # of statement */
444
441
entNo = luEntNo ; /* re-use the 'least used' entry */
445
442
446
443
/* 'entNo' is the entry to use - make sure its free */
447
- if (ecpg_freeStmtCacheEntry (entNo ) < 0 )
444
+ if (ecpg_freeStmtCacheEntry (lineno , compat , entNo ) < 0 )
448
445
return (-1 );
449
446
450
447
/* add the query to the entry */
@@ -460,7 +457,7 @@ AddStmtToCache(int lineno, /* line # of statement */
460
457
461
458
/* handle cache and preparation of statments in auto-prepare mode */
462
459
bool
463
- ecpg_auto_prepare (int lineno , const char * connection_name , const int questionmarks , char * * name , const char * query )
460
+ ecpg_auto_prepare (int lineno , const char * connection_name , int compat , const int questionmarks , char * * name , const char * query )
464
461
{
465
462
int entNo ;
466
463
@@ -483,7 +480,7 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmar
483
480
484
481
if (!ECPGprepare (lineno , connection_name , questionmarks , ecpg_strdup (* name , lineno ), query ))
485
482
return (false);
486
- if (AddStmtToCache (lineno , * name , connection_name , query ) < 0 )
483
+ if (AddStmtToCache (lineno , * name , connection_name , compat , query ) < 0 )
487
484
return (false);
488
485
}
489
486
0 commit comments