2000-07-21 13:43:26 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pg_backup_null.c
|
|
|
|
*
|
2001-03-22 05:01:46 +01:00
|
|
|
* Implementation of an archive that is never saved; it is used by
|
2002-05-11 00:36:27 +02:00
|
|
|
* pg_dump to output a plain text SQL script instead of save
|
2000-07-21 13:43:26 +02:00
|
|
|
* a real archive.
|
|
|
|
*
|
|
|
|
* See the headers to pg_restore for more details.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000, Philip Warner
|
2001-03-22 05:01:46 +01:00
|
|
|
* Rights are granted to use this software in any way so long
|
|
|
|
* as this notice is not removed.
|
2000-07-21 13:43:26 +02:00
|
|
|
*
|
|
|
|
* The author is not responsible for loss or damages that may
|
|
|
|
* result from it's use.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2002-08-20 19:54:45 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.10 2002/08/20 17:54:44 petere Exp $
|
2001-01-12 05:32:07 +01:00
|
|
|
*
|
2000-07-21 13:43:26 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2001-02-10 03:31:31 +01:00
|
|
|
#include "pg_backup.h"
|
|
|
|
#include "pg_backup_archiver.h"
|
|
|
|
|
2000-07-21 13:43:26 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-03-22 05:01:46 +01:00
|
|
|
#include <unistd.h> /* for dup */
|
2000-07-21 13:43:26 +02:00
|
|
|
|
2002-08-20 19:54:45 +02:00
|
|
|
static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen);
|
2001-03-22 05:01:46 +01:00
|
|
|
static void _EndData(ArchiveHandle *AH, TocEntry *te);
|
|
|
|
static int _WriteByte(ArchiveHandle *AH, const int i);
|
2002-08-20 19:54:45 +02:00
|
|
|
static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
|
2001-03-22 05:01:46 +01:00
|
|
|
static void _CloseArchive(ArchiveHandle *AH);
|
|
|
|
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
|
2000-07-21 13:43:26 +02:00
|
|
|
|
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* Initializer
|
2000-07-21 13:43:26 +02:00
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
void
|
|
|
|
InitArchiveFmt_Null(ArchiveHandle *AH)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
/* Assuming static functions, this can be copied for each format. */
|
|
|
|
AH->WriteDataPtr = _WriteData;
|
|
|
|
AH->EndDataPtr = _EndData;
|
|
|
|
AH->WriteBytePtr = _WriteByte;
|
|
|
|
AH->WriteBufPtr = _WriteBuf;
|
|
|
|
AH->ClosePtr = _CloseArchive;
|
|
|
|
AH->PrintTocDataPtr = _PrintTocData;
|
2000-07-21 13:43:26 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
/*
|
|
|
|
* Now prevent reading...
|
|
|
|
*/
|
|
|
|
if (AH->mode == archModeRead)
|
2001-06-27 23:21:37 +02:00
|
|
|
die_horribly(AH, NULL, "this format cannot be read\n");
|
2000-07-21 13:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* - Start a new TOC entry
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*------
|
2001-03-22 05:01:46 +01:00
|
|
|
* Called by dumper via archiver from within a data dump routine
|
2000-07-21 13:43:26 +02:00
|
|
|
* As at V1.3, this is only called for COPY FROM dfata, and BLOB data
|
|
|
|
*------
|
|
|
|
*/
|
2002-08-20 19:54:45 +02:00
|
|
|
static size_t
|
|
|
|
_WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
/* Just send it to output */
|
|
|
|
ahwrite(data, 1, dLen, AH);
|
|
|
|
return dLen;
|
2000-07-21 13:43:26 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static void
|
|
|
|
_EndData(ArchiveHandle *AH, TocEntry *te)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
ahprintf(AH, "\n\n");
|
2000-07-21 13:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------
|
|
|
|
* Called as part of a RestoreArchive call; for the NULL archive, this
|
|
|
|
* just sends the data for a given TOC entry to the output.
|
|
|
|
*------
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
static void
|
|
|
|
_PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
2001-03-25 00:11:14 +01:00
|
|
|
if (te->dataDumper)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
|
|
|
AH->currToc = te;
|
2001-03-22 05:01:46 +01:00
|
|
|
(*te->dataDumper) ((Archive *) AH, te->oid, te->dataDumperArg);
|
2000-07-21 13:43:26 +02:00
|
|
|
AH->currToc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static int
|
|
|
|
_WriteByte(ArchiveHandle *AH, const int i)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
/* Don't do anything */
|
|
|
|
return 0;
|
2000-07-21 13:43:26 +02:00
|
|
|
}
|
|
|
|
|
2002-08-20 19:54:45 +02:00
|
|
|
static size_t
|
|
|
|
_WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
/* Don't do anything */
|
|
|
|
return len;
|
2000-07-21 13:43:26 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static void
|
|
|
|
_CloseArchive(ArchiveHandle *AH)
|
2000-07-21 13:43:26 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
/* Nothing to do */
|
2000-07-21 13:43:26 +02:00
|
|
|
}
|