#include "pg_backup_archiver.h"
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) |
PGresult * | ExecuteSqlQuery (Archive *AHX, const char *query, ExecStatusType status) |
void | EndDBCopyMode (ArchiveHandle *AH, struct _tocEntry *te) |
void | StartTransaction (ArchiveHandle *AH) |
void | CommitTransaction (ArchiveHandle *AH) |
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 | |||
) |
Definition at line 361 of file pg_backup_db.c.
References _archiveHandle::connection, die_on_query_failure(), modulename, PQexec(), and PQresultStatus().
Referenced by buildMatViewRefreshDependencies(), collectComments(), collectSecLabels(), createViewAsClause(), dumpBlobs(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpDatabase(), dumpEnumType(), dumpOpclass(), dumpOpfamily(), dumpRule(), dumpSequence(), dumpSequenceData(), dumpTable(), dumpTableData_copy(), dumpTableData_insert(), dumpTSConfig(), dumpUserMappings(), ExecuteSqlQueryForSingleRow(), expand_schema_name_patterns(), expand_table_name_patterns(), getAggregates(), getBlobs(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDependencies(), getDomainConstraints(), getEventTriggers(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getProcLangs(), getRules(), getTableAttrs(), getTables(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), and getTypes().
{ ArchiveHandle *AH = (ArchiveHandle *) AHX; PGresult *res; res = PQexec(AH->connection, query); if (PQresultStatus(res) != status) die_on_query_failure(AH, modulename, query); return res; }
void ExecuteSqlStatement | ( | Archive * | AHX, | |
const char * | query | |||
) |
Definition at line 349 of file pg_backup_db.c.
References _archiveHandle::connection, die_on_query_failure(), modulename, PGRES_COMMAND_OK, PQclear(), PQexec(), and PQresultStatus().
Referenced by dumpBlobs(), dumpTableData_insert(), getTables(), selectSourceSchema(), and setup_connection().
{ ArchiveHandle *AH = (ArchiveHandle *) AHX; PGresult *res; res = PQexec(AH->connection, query); if (PQresultStatus(res) != PGRES_COMMAND_OK) die_on_query_failure(AH, modulename, query); PQclear(res); }
void StartTransaction | ( | ArchiveHandle * | AH | ) |
Definition at line 572 of file pg_backup_db.c.
References ExecuteSqlCommand().
{ ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction"); }