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 $ */
22
33#define POSTGRES_ECPG_INTERNAL
44#include "postgres_fe.h"
@@ -373,30 +373,26 @@ SearchStmtCache(const char *ecpgQuery)
373373 * OR negative error code
374374 */
375375static int
376- ecpg_freeStmtCacheEntry (int entNo ) /* entry # to free */
376+ ecpg_freeStmtCacheEntry (int lineno , int compat , int entNo ) /* entry # to free */
377377{
378378 stmtCacheEntry * entry ;
379- PGresult * results ;
380- char deallocText [100 ];
381379 struct connection * con ;
380+ struct prepared_statement * this , * prev ;
382381
383382 entry = & stmtCacheEntries [entNo ];
384383 if (!entry -> stmtID [0 ]) /* return if the entry isn't in use */
385384 return (0 );
386385
387386 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 );
392387
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 ))
394391 return (-1 );
395- PQclear (results );
396392
397393 entry -> stmtID [0 ] = '\0' ;
398394
399- /* free the memory used by the cache entry */
395+ /* free the memory used by the cache entry */
400396 if (entry -> ecpgQuery )
401397 {
402398 ecpg_free (entry -> ecpgQuery );
@@ -414,6 +410,7 @@ static int
414410AddStmtToCache (int lineno , /* line # of statement */
415411 char * stmtID , /* statement ID */
416412 const char * connection , /* connection */
413+ int compat , /* compatibility level */
417414 const char * ecpgQuery ) /* query */
418415{
419416 int ix ,
@@ -444,7 +441,7 @@ AddStmtToCache(int lineno, /* line # of statement */
444441 entNo = luEntNo ; /* re-use the 'least used' entry */
445442
446443/* 'entNo' is the entry to use - make sure its free */
447- if (ecpg_freeStmtCacheEntry (entNo ) < 0 )
444+ if (ecpg_freeStmtCacheEntry (lineno , compat , entNo ) < 0 )
448445 return (-1 );
449446
450447/* add the query to the entry */
@@ -460,7 +457,7 @@ AddStmtToCache(int lineno, /* line # of statement */
460457
461458/* handle cache and preparation of statments in auto-prepare mode */
462459bool
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 )
464461{
465462 int entNo ;
466463
@@ -483,7 +480,7 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmar
483480
484481 if (!ECPGprepare (lineno , connection_name , questionmarks , ecpg_strdup (* name , lineno ), query ))
485482 return (false);
486- if (AddStmtToCache (lineno , * name , connection_name , query ) < 0 )
483+ if (AddStmtToCache (lineno , * name , connection_name , compat , query ) < 0 )
487484 return (false);
488485 }
489486
0 commit comments