55 *Implements the basic DB functions used by the archiver.
66 *
77 * IDENTIFICATION
8- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.79 2008/04/13 03:49:22 tgl Exp $
8+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.80 2008/08/16 02:25:06 tgl Exp $
99 *
1010 *-------------------------------------------------------------------------
1111 */
@@ -266,27 +266,31 @@ notice_processor(void *arg, const char *message)
266266
267267/* Public interface */
268268/* Convenience function to send a query. Monitors result to handle COPY statements */
269- static int
270- ExecuteSqlCommand (ArchiveHandle * AH ,PQExpBuffer qry ,char * desc )
269+ static void
270+ ExecuteSqlCommand (ArchiveHandle * AH ,const char * qry ,const char * desc )
271271{
272272PGconn * conn = AH -> connection ;
273273PGresult * res ;
274274char errStmt [DB_MAX_ERR_STMT ];
275275
276- /* fprintf(stderr, "Executing: '%s'\n\n", qry->data); */
277- res = PQexec ( conn , qry -> data );
278- if (! res )
279- die_horribly ( AH , modulename , "%s: no result from server\n" , desc );
276+ #ifdef NOT_USED
277+ fprintf ( stderr , "Executing: '%s'\n\n" , qry );
278+ #endif
279+ res = PQexec ( conn , qry );
280280
281- if (PQresultStatus (res )!= PGRES_COMMAND_OK && PQresultStatus ( res ) != PGRES_TUPLES_OK )
281+ switch (PQresultStatus (res ))
282282{
283- if (PQresultStatus (res )== PGRES_COPY_IN )
284- {
283+ case PGRES_COMMAND_OK :
284+ case PGRES_TUPLES_OK :
285+ /* A-OK */
286+ break ;
287+ case PGRES_COPY_IN :
288+ /* Assume this is an expected result */
285289AH -> pgCopyIn = true;
286- }
287- else
288- {
289- strncpy (errStmt ,qry -> data ,DB_MAX_ERR_STMT );
290+ break ;
291+ default :
292+ /* trouble */
293+ strncpy (errStmt ,qry ,DB_MAX_ERR_STMT );
290294if (errStmt [DB_MAX_ERR_STMT - 1 ]!= '\0' )
291295{
292296errStmt [DB_MAX_ERR_STMT - 4 ]= '.' ;
@@ -295,14 +299,11 @@ ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc)
295299errStmt [DB_MAX_ERR_STMT - 1 ]= '\0' ;
296300}
297301warn_or_die_horribly (AH ,modulename ,"%s: %s Command was: %s\n" ,
298- desc ,PQerrorMessage (AH -> connection ),
299- errStmt );
300- }
302+ desc ,PQerrorMessage (conn ),errStmt );
303+ break ;
301304}
302305
303306PQclear (res );
304-
305- return strlen (qry -> data );
306307}
307308
308309/*
@@ -427,7 +428,7 @@ _sendSQLLine(ArchiveHandle *AH, char *qry, char *eos)
427428 * the buffer.
428429 */
429430appendPQExpBufferChar (AH -> sqlBuf ,';' );/* inessential */
430- ExecuteSqlCommand (AH ,AH -> sqlBuf ,
431+ ExecuteSqlCommand (AH ,AH -> sqlBuf -> data ,
431432"could not execute query" );
432433resetPQExpBuffer (AH -> sqlBuf );
433434AH -> sqlparse .lastChar = '\0' ;
@@ -626,25 +627,13 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, size_t bufLen)
626627void
627628StartTransaction (ArchiveHandle * AH )
628629{
629- PQExpBuffer qry = createPQExpBuffer ();
630-
631- appendPQExpBuffer (qry ,"BEGIN" );
632-
633- ExecuteSqlCommand (AH ,qry ,"could not start database transaction" );
634-
635- destroyPQExpBuffer (qry );
630+ ExecuteSqlCommand (AH ,"BEGIN" ,"could not start database transaction" );
636631}
637632
638633void
639634CommitTransaction (ArchiveHandle * AH )
640635{
641- PQExpBuffer qry = createPQExpBuffer ();
642-
643- appendPQExpBuffer (qry ,"COMMIT" );
644-
645- ExecuteSqlCommand (AH ,qry ,"could not commit database transaction" );
646-
647- destroyPQExpBuffer (qry );
636+ ExecuteSqlCommand (AH ,"COMMIT" ,"could not commit database transaction" );
648637}
649638
650639static bool