Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

pg_backup_db.h File Reference

#include "pg_backup_archiver.h"
Include dependency graph for pg_backup_db.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int ExecuteSqlCommandBuf (ArchiveHandle *AH, const char *buf, size_t bufLen)
void ExecuteSqlStatement (Archive *AHX, const char *query)
PGresultExecuteSqlQuery (Archive *AHX, const char *query, ExecStatusType status)
void EndDBCopyMode (ArchiveHandle *AH, struct _tocEntry *te)
void StartTransaction (ArchiveHandle *AH)
void CommitTransaction (ArchiveHandle *AH)

Function Documentation

void CommitTransaction ( ArchiveHandle AH  ) 

Definition at line 578 of file pg_backup_db.c.

References ExecuteSqlCommand().

{
    ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction");
}

void EndDBCopyMode ( ArchiveHandle AH,
struct _tocEntry te 
)

Definition at line 550 of file pg_backup_db.c.

References _archiveHandle::connection, exit_horribly(), modulename, NULL, _archiveHandle::pgCopyIn, PGRES_COMMAND_OK, PQclear(), PQerrorMessage(), PQgetResult(), PQputCopyEnd(), PQresultStatus(), _tocEntry::tag, and warn_or_exit_horribly().

Referenced by restore_toc_entry().

{
    if (AH->pgCopyIn)
    {
        PGresult   *res;

        if (PQputCopyEnd(AH->connection, NULL) <= 0)
            exit_horribly(modulename, "error returned by PQputCopyEnd: %s",
                          PQerrorMessage(AH->connection));

        /* Check command status and return to normal libpq state */
        res = PQgetResult(AH->connection);
        if (PQresultStatus(res) != PGRES_COMMAND_OK)
            warn_or_exit_horribly(AH, modulename, "COPY failed for table \"%s\": %s",
                                  te->tag, PQerrorMessage(AH->connection));
        PQclear(res);

        AH->pgCopyIn = false;
    }
}

int ExecuteSqlCommandBuf ( ArchiveHandle AH,
const char *  buf,
size_t  bufLen 
)

Definition at line 498 of file pg_backup_db.c.

References _archiveHandle::connection, ExecuteInsertCommands(), ExecuteSqlCommand(), exit_horribly(), free, modulename, OUTPUT_COPYDATA, OUTPUT_OTHERDATA, _archiveHandle::outputKind, pg_malloc(), _archiveHandle::pgCopyIn, PQerrorMessage(), and PQputCopyData().

Referenced by ahwrite().

{
    if (AH->outputKind == OUTPUT_COPYDATA)
    {
        /*
         * COPY data.
         *
         * We drop the data on the floor if libpq has failed to enter COPY
         * mode; this allows us to behave reasonably when trying to continue
         * after an error in a COPY command.
         */
        if (AH->pgCopyIn &&
            PQputCopyData(AH->connection, buf, bufLen) <= 0)
            exit_horribly(modulename, "error returned by PQputCopyData: %s",
                          PQerrorMessage(AH->connection));
    }
    else if (AH->outputKind == OUTPUT_OTHERDATA)
    {
        /*
         * Table data expressed as INSERT commands.
         */
        ExecuteInsertCommands(AH, buf, bufLen);
    }
    else
    {
        /*
         * General SQL commands; we assume that commands will not be split
         * across calls.
         *
         * In most cases the data passed to us will be a null-terminated
         * string, but if it's not, we have to add a trailing null.
         */
        if (buf[bufLen] == '\0')
            ExecuteSqlCommand(AH, buf, "could not execute query");
        else
        {
            char       *str = (char *) pg_malloc(bufLen + 1);

            memcpy(str, buf, bufLen);
            str[bufLen] = '\0';
            ExecuteSqlCommand(AH, str, "could not execute query");
            free(str);
        }
    }

    return 1;
}

PGresult* ExecuteSqlQuery ( Archive AHX,
const char *  query,
ExecStatusType  status 
)
void ExecuteSqlStatement ( Archive AHX,
const char *  query 
)
void StartTransaction ( ArchiveHandle AH  ) 

Definition at line 572 of file pg_backup_db.c.

References ExecuteSqlCommand().

{
    ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction");
}