PostgreSQL Source Code  git master
pg_backup_null.c File Reference
#include "postgres_fe.h"
#include "fe_utils/string_utils.h"
#include "libpq/libpq-fs.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
Include dependency graph for pg_backup_null.c:

Go to the source code of this file.

Functions

static void _WriteData (ArchiveHandle *AH, const void *data, size_t dLen)
 
static void _WriteLOData (ArchiveHandle *AH, const void *data, size_t dLen)
 
static void _EndData (ArchiveHandle *AH, TocEntry *te)
 
static int _WriteByte (ArchiveHandle *AH, const int i)
 
static void _WriteBuf (ArchiveHandle *AH, const void *buf, size_t len)
 
static void _CloseArchive (ArchiveHandle *AH)
 
static void _PrintTocData (ArchiveHandle *AH, TocEntry *te)
 
static void _StartLOs (ArchiveHandle *AH, TocEntry *te)
 
static void _StartLO (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
static void _EndLO (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
static void _EndLOs (ArchiveHandle *AH, TocEntry *te)
 
void InitArchiveFmt_Null (ArchiveHandle *AH)
 

Function Documentation

◆ _CloseArchive()

static void _CloseArchive ( ArchiveHandle AH)
static

Definition at line 225 of file pg_backup_null.c.

226 {
227  /* Nothing to do */
228 }

Referenced by InitArchiveFmt_Null().

◆ _EndData()

static void _EndData ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 114 of file pg_backup_null.c.

115 {
116  ahprintf(AH, "\n\n");
117 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

References ahprintf().

Referenced by InitArchiveFmt_Null().

◆ _EndLO()

static void _EndLO ( ArchiveHandle AH,
TocEntry te,
Oid  oid 
)
static

Definition at line 169 of file pg_backup_null.c.

170 {
171  AH->WriteDataPtr = _WriteData;
172 
173  ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
174 }
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
WriteDataPtrType WriteDataPtr

References _WriteData(), ahprintf(), and _archiveHandle::WriteDataPtr.

Referenced by InitArchiveFmt_Null().

◆ _EndLOs()

static void _EndLOs ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 182 of file pg_backup_null.c.

183 {
184  ahprintf(AH, "COMMIT;\n\n");
185 }

References ahprintf().

Referenced by _PrintTocData(), and InitArchiveFmt_Null().

◆ _PrintTocData()

static void _PrintTocData ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 193 of file pg_backup_null.c.

194 {
195  if (te->dataDumper)
196  {
197  AH->currToc = te;
198 
199  if (strcmp(te->desc, "BLOBS") == 0)
200  _StartLOs(AH, te);
201 
202  te->dataDumper((Archive *) AH, te->dataDumperArg);
203 
204  if (strcmp(te->desc, "BLOBS") == 0)
205  _EndLOs(AH, te);
206 
207  AH->currToc = NULL;
208  }
209 }
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
struct _tocEntry * currToc
DataDumperPtr dataDumper
const void * dataDumperArg

References _EndLOs(), _StartLOs(), _archiveHandle::currToc, _tocEntry::dataDumper, _tocEntry::dataDumperArg, and _tocEntry::desc.

Referenced by InitArchiveFmt_Null().

◆ _StartLO()

static void _StartLO ( ArchiveHandle AH,
TocEntry te,
Oid  oid 
)
static

Definition at line 142 of file pg_backup_null.c.

143 {
144  bool old_lo_style = (AH->version < K_VERS_1_12);
145 
146  if (oid == 0)
147  pg_fatal("invalid OID for large object");
148 
149  /* With an old archive we must do drop and create logic here */
150  if (old_lo_style && AH->public.ropt->dropSchema)
151  DropLOIfExists(AH, oid);
152 
153  if (old_lo_style)
154  ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
155  oid, INV_WRITE);
156  else
157  ahprintf(AH, "SELECT pg_catalog.lo_open('%u', %d);\n",
158  oid, INV_WRITE);
159 
161 }
#define INV_WRITE
Definition: libpq-fs.h:21
void DropLOIfExists(ArchiveHandle *AH, Oid oid)
Definition: pg_backup_db.c:545
#define K_VERS_1_12
static void _WriteLOData(ArchiveHandle *AH, const void *data, size_t dLen)
#define pg_fatal(...)
RestoreOptions * ropt
Definition: pg_backup.h:213

References _WriteLOData(), ahprintf(), DropLOIfExists(), _restoreOptions::dropSchema, INV_WRITE, K_VERS_1_12, pg_fatal, _archiveHandle::public, Archive::ropt, _archiveHandle::version, and _archiveHandle::WriteDataPtr.

Referenced by InitArchiveFmt_Null().

◆ _StartLOs()

static void _StartLOs ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 129 of file pg_backup_null.c.

130 {
131  ahprintf(AH, "BEGIN;\n\n");
132 }

References ahprintf().

Referenced by _PrintTocData(), and InitArchiveFmt_Null().

◆ _WriteBuf()

static void _WriteBuf ( ArchiveHandle AH,
const void *  buf,
size_t  len 
)
static

Definition at line 219 of file pg_backup_null.c.

220 {
221  /* Don't do anything */
222 }

Referenced by InitArchiveFmt_Null().

◆ _WriteByte()

static int _WriteByte ( ArchiveHandle AH,
const int  i 
)
static

Definition at line 212 of file pg_backup_null.c.

213 {
214  /* Don't do anything */
215  return 0;
216 }

Referenced by InitArchiveFmt_Null().

◆ _WriteData()

static void _WriteData ( ArchiveHandle AH,
const void *  data,
size_t  dLen 
)
static

Definition at line 85 of file pg_backup_null.c.

86 {
87  /* Just send it to output, ahwrite() already errors on failure */
88  ahwrite(data, 1, dLen, AH);
89 }
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
const void * data

References ahwrite(), and data.

Referenced by _EndLO(), and InitArchiveFmt_Null().

◆ _WriteLOData()

static void _WriteLOData ( ArchiveHandle AH,
const void *  data,
size_t  dLen 
)
static

Definition at line 96 of file pg_backup_null.c.

97 {
98  if (dLen > 0)
99  {
101 
103  (const unsigned char *) data,
104  dLen,
105  AH);
106 
107  ahprintf(AH, "SELECT pg_catalog.lowrite(0, %s);\n", buf->data);
108 
110  }
111 }
#define appendByteaLiteralAHX(buf, str, len, AH)
static char * buf
Definition: pg_test_fsync.c:73
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114

References ahprintf(), appendByteaLiteralAHX, buf, createPQExpBuffer(), data, and destroyPQExpBuffer().

Referenced by _StartLO().

◆ InitArchiveFmt_Null()

void InitArchiveFmt_Null ( ArchiveHandle AH)

Definition at line 48 of file pg_backup_null.c.

49 {
50  /* Assuming static functions, this can be copied for each format. */
52  AH->EndDataPtr = _EndData;
54  AH->WriteBufPtr = _WriteBuf;
55  AH->ClosePtr = _CloseArchive;
56  AH->ReopenPtr = NULL;
58 
59  AH->StartLOsPtr = _StartLOs;
60  AH->StartLOPtr = _StartLO;
61  AH->EndLOPtr = _EndLO;
62  AH->EndLOsPtr = _EndLOs;
63  AH->ClonePtr = NULL;
64  AH->DeClonePtr = NULL;
65 
66  /* Initialize LO buffering */
67  AH->lo_buf_size = LOBBUFSIZE;
68  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
69 
70  /*
71  * Now prevent reading...
72  */
73  if (AH->mode == archModeRead)
74  pg_fatal("this format cannot be read");
75 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
@ archModeRead
Definition: pg_backup.h:52
#define LOBBUFSIZE
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
DeClonePtrType DeClonePtr
EndLOsPtrType EndLOsPtr
StartLOsPtrType StartLOsPtr
StartLOPtrType StartLOPtr
ClonePtrType ClonePtr
WriteBufPtrType WriteBufPtr
EndLOPtrType EndLOPtr
PrintTocDataPtrType PrintTocDataPtr
WriteBytePtrType WriteBytePtr
ReopenPtrType ReopenPtr
EndDataPtrType EndDataPtr
ClosePtrType ClosePtr

References _CloseArchive(), _EndData(), _EndLO(), _EndLOs(), _PrintTocData(), _StartLO(), _StartLOs(), _WriteBuf(), _WriteByte(), _WriteData(), archModeRead, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, _archiveHandle::mode, pg_fatal, pg_malloc(), _archiveHandle::PrintTocDataPtr, _archiveHandle::ReopenPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, and _archiveHandle::WriteDataPtr.

Referenced by _allocAH().