Done. In backend/commands/define.c unused field is set to '-' for the

moment.

A patch for CVS is attached, and I have amended my BLOB dumping version
appropriately.

Philip Warner
This commit is contained in:
Bruce Momjian 2000-07-11 13:07:17 +00:00
parent 793704d71e
commit 0d32cdc38e
2 changed files with 215 additions and 199 deletions

View file

@ -1,193 +1,193 @@
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* pg_backup_archiver.h * pg_backup_archiver.h
* *
* Private interface to the pg_dump archiver routines. * Private interface to the pg_dump archiver routines.
* It is NOT intended that these routines be called by any * It is NOT intended that these routines be called by any
* dumper directly. * dumper directly.
* *
* See the headers to pg_restore for more details. * See the headers to pg_restore for more details.
* *
* Copyright (c) 2000, Philip Warner * Copyright (c) 2000, Philip Warner
* Rights are granted to use this software in any way so long * Rights are granted to use this software in any way so long
* as this notice is not removed. * as this notice is not removed.
* *
* The author is not responsible for loss or damages that may * The author is not responsible for loss or damages that may
* result from it's use. * result from it's use.
* *
* *
* IDENTIFICATION * IDENTIFICATION
* *
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
* *
* Initial version. * Initial version.
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef __PG_BACKUP_ARCHIVE__ #ifndef __PG_BACKUP_ARCHIVE__
#define __PG_BACKUP_ARCHIVE__ #define __PG_BACKUP_ARCHIVE__
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#include <zlib.h> #include <zlib.h>
#define GZCLOSE(fh) gzclose(fh) #define GZCLOSE(fh) gzclose(fh)
#define GZWRITE(p, s, n, fh) gzwrite(fh, p, n * s) #define GZWRITE(p, s, n, fh) gzwrite(fh, p, n * s)
#define GZREAD(p, s, n, fh) gzread(fh, p, n * s) #define GZREAD(p, s, n, fh) gzread(fh, p, n * s)
#else #else
#define GZCLOSE(fh) fclose(fh) #define GZCLOSE(fh) fclose(fh)
#define GZWRITE(p, s, n, fh) fwrite(p, s, n, fh) #define GZWRITE(p, s, n, fh) fwrite(p, s, n, fh)
#define GZREAD(p, s, n, fh) fread(p, s, n, fh) #define GZREAD(p, s, n, fh) fread(p, s, n, fh)
#define Z_DEFAULT_COMPRESSION -1 #define Z_DEFAULT_COMPRESSION -1
typedef struct _z_stream { typedef struct _z_stream {
void *next_in; void *next_in;
void *next_out; void *next_out;
int avail_in; int avail_in;
int avail_out; int avail_out;
} z_stream; } z_stream;
typedef z_stream *z_streamp; typedef z_stream *z_streamp;
#endif #endif
#include "pg_backup.h" #include "pg_backup.h"
#define K_VERS_MAJOR 1 #define K_VERS_MAJOR 1
#define K_VERS_MINOR 2 #define K_VERS_MINOR 2
#define K_VERS_REV 1 #define K_VERS_REV 2
/* Some important version numbers (checked in code) */ /* Some important version numbers (checked in code) */
#define K_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0) #define K_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0)
#define K_VERS_1_2 (( (1 * 256 + 2) * 256 + 0) * 256 + 0) #define K_VERS_1_2 (( (1 * 256 + 2) * 256 + 0) * 256 + 0)
#define K_VERS_MAX (( (1 * 256 + 2) * 256 + 255) * 256 + 0) #define K_VERS_MAX (( (1 * 256 + 2) * 256 + 255) * 256 + 0)
struct _archiveHandle; struct _archiveHandle;
struct _tocEntry; struct _tocEntry;
struct _restoreList; struct _restoreList;
typedef void (*ClosePtr) (struct _archiveHandle* AH); typedef void (*ClosePtr) (struct _archiveHandle* AH);
typedef void (*ArchiveEntryPtr) (struct _archiveHandle* AH, struct _tocEntry* te); typedef void (*ArchiveEntryPtr) (struct _archiveHandle* AH, struct _tocEntry* te);
typedef void (*StartDataPtr) (struct _archiveHandle* AH, struct _tocEntry* te); typedef void (*StartDataPtr) (struct _archiveHandle* AH, struct _tocEntry* te);
typedef int (*WriteDataPtr) (struct _archiveHandle* AH, const void* data, int dLen); typedef int (*WriteDataPtr) (struct _archiveHandle* AH, const void* data, int dLen);
typedef void (*EndDataPtr) (struct _archiveHandle* AH, struct _tocEntry* te); typedef void (*EndDataPtr) (struct _archiveHandle* AH, struct _tocEntry* te);
typedef int (*WriteBytePtr) (struct _archiveHandle* AH, const int i); typedef int (*WriteBytePtr) (struct _archiveHandle* AH, const int i);
typedef int (*ReadBytePtr) (struct _archiveHandle* AH); typedef int (*ReadBytePtr) (struct _archiveHandle* AH);
typedef int (*WriteBufPtr) (struct _archiveHandle* AH, const void* c, int len); typedef int (*WriteBufPtr) (struct _archiveHandle* AH, const void* c, int len);
typedef int (*ReadBufPtr) (struct _archiveHandle* AH, void* buf, int len); typedef int (*ReadBufPtr) (struct _archiveHandle* AH, void* buf, int len);
typedef void (*SaveArchivePtr) (struct _archiveHandle* AH); typedef void (*SaveArchivePtr) (struct _archiveHandle* AH);
typedef void (*WriteExtraTocPtr) (struct _archiveHandle* AH, struct _tocEntry* te); typedef void (*WriteExtraTocPtr) (struct _archiveHandle* AH, struct _tocEntry* te);
typedef void (*ReadExtraTocPtr) (struct _archiveHandle* AH, struct _tocEntry* te); typedef void (*ReadExtraTocPtr) (struct _archiveHandle* AH, struct _tocEntry* te);
typedef void (*PrintExtraTocPtr) (struct _archiveHandle* AH, struct _tocEntry* te); typedef void (*PrintExtraTocPtr) (struct _archiveHandle* AH, struct _tocEntry* te);
typedef void (*PrintTocDataPtr) (struct _archiveHandle* AH, struct _tocEntry* te, typedef void (*PrintTocDataPtr) (struct _archiveHandle* AH, struct _tocEntry* te,
RestoreOptions *ropt); RestoreOptions *ropt);
typedef int (*TocSortCompareFn) (const void* te1, const void *te2); typedef int (*TocSortCompareFn) (const void* te1, const void *te2);
typedef enum _archiveMode { typedef enum _archiveMode {
archModeWrite, archModeWrite,
archModeRead archModeRead
} ArchiveMode; } ArchiveMode;
typedef struct _outputContext { typedef struct _outputContext {
void *OF; void *OF;
int gzOut; int gzOut;
} OutputContext; } OutputContext;
typedef struct _archiveHandle { typedef struct _archiveHandle {
char vmaj; /* Version of file */ char vmaj; /* Version of file */
char vmin; char vmin;
char vrev; char vrev;
int version; /* Conveniently formatted version */ int version; /* Conveniently formatted version */
int intSize; /* Size of an integer in the archive */ int intSize; /* Size of an integer in the archive */
ArchiveFormat format; /* Archive format */ ArchiveFormat format; /* Archive format */
int readHeader; /* Used if file header has been read already */ int readHeader; /* Used if file header has been read already */
ArchiveEntryPtr ArchiveEntryPtr; /* Called for each metadata object */ ArchiveEntryPtr ArchiveEntryPtr; /* Called for each metadata object */
StartDataPtr StartDataPtr; /* Called when table data is about to be dumped */ StartDataPtr StartDataPtr; /* Called when table data is about to be dumped */
WriteDataPtr WriteDataPtr; /* Called to send some table data to the archive */ WriteDataPtr WriteDataPtr; /* Called to send some table data to the archive */
EndDataPtr EndDataPtr; /* Called when table data dump is finished */ EndDataPtr EndDataPtr; /* Called when table data dump is finished */
WriteBytePtr WriteBytePtr; /* Write a byte to output */ WriteBytePtr WriteBytePtr; /* Write a byte to output */
ReadBytePtr ReadBytePtr; /* */ ReadBytePtr ReadBytePtr; /* */
WriteBufPtr WriteBufPtr; WriteBufPtr WriteBufPtr;
ReadBufPtr ReadBufPtr; ReadBufPtr ReadBufPtr;
ClosePtr ClosePtr; /* Close the archive */ ClosePtr ClosePtr; /* Close the archive */
WriteExtraTocPtr WriteExtraTocPtr; /* Write extra TOC entry data associated with */ WriteExtraTocPtr WriteExtraTocPtr; /* Write extra TOC entry data associated with */
/* the current archive format */ /* the current archive format */
ReadExtraTocPtr ReadExtraTocPtr; /* Read extr info associated with archie format */ ReadExtraTocPtr ReadExtraTocPtr; /* Read extr info associated with archie format */
PrintExtraTocPtr PrintExtraTocPtr; /* Extra TOC info for format */ PrintExtraTocPtr PrintExtraTocPtr; /* Extra TOC info for format */
PrintTocDataPtr PrintTocDataPtr; PrintTocDataPtr PrintTocDataPtr;
int lastID; /* Last internal ID for a TOC entry */ int lastID; /* Last internal ID for a TOC entry */
char* fSpec; /* Archive File Spec */ char* fSpec; /* Archive File Spec */
FILE *FH; /* General purpose file handle */ FILE *FH; /* General purpose file handle */
void *OF; void *OF;
int gzOut; /* Output file */ int gzOut; /* Output file */
struct _tocEntry* toc; /* List of TOC entries */ struct _tocEntry* toc; /* List of TOC entries */
int tocCount; /* Number of TOC entries */ int tocCount; /* Number of TOC entries */
struct _tocEntry* currToc; /* Used when dumping data */ struct _tocEntry* currToc; /* Used when dumping data */
char *currUser; /* Restore: current username in script */ char *currUser; /* Restore: current username in script */
int compression; /* Compression requested on open */ int compression; /* Compression requested on open */
ArchiveMode mode; /* File mode - r or w */ ArchiveMode mode; /* File mode - r or w */
void* formatData; /* Header data specific to file format */ void* formatData; /* Header data specific to file format */
} ArchiveHandle; } ArchiveHandle;
typedef struct _tocEntry { typedef struct _tocEntry {
struct _tocEntry* prev; struct _tocEntry* prev;
struct _tocEntry* next; struct _tocEntry* next;
int id; int id;
int hadDumper; /* Archiver was passed a dumper routine (used in restore) */ int hadDumper; /* Archiver was passed a dumper routine (used in restore) */
char* oid; char* oid;
int oidVal; int oidVal;
char* name; char* name;
char* desc; char* desc;
char* defn; char* defn;
char* dropStmt; char* dropStmt;
char* owner; char* owner;
char** depOid; char** depOid;
int printed; /* Indicates if entry defn has been dumped */ int printed; /* Indicates if entry defn has been dumped */
DataDumperPtr dataDumper; /* Routine to dump data for object */ DataDumperPtr dataDumper; /* Routine to dump data for object */
void* dataDumperArg; /* Arg for above routine */ void* dataDumperArg; /* Arg for above routine */
void* formatData; /* TOC Entry data specific to file format */ void* formatData; /* TOC Entry data specific to file format */
int _moved; /* Marker used when rearranging TOC */ int _moved; /* Marker used when rearranging TOC */
} TocEntry; } TocEntry;
extern void die_horribly(const char *fmt, ...); extern void die_horribly(const char *fmt, ...);
extern void WriteTOC(ArchiveHandle* AH); extern void WriteTOC(ArchiveHandle* AH);
extern void ReadTOC(ArchiveHandle* AH); extern void ReadTOC(ArchiveHandle* AH);
extern void WriteHead(ArchiveHandle* AH); extern void WriteHead(ArchiveHandle* AH);
extern void ReadHead(ArchiveHandle* AH); extern void ReadHead(ArchiveHandle* AH);
extern void WriteToc(ArchiveHandle* AH); extern void WriteToc(ArchiveHandle* AH);
extern void ReadToc(ArchiveHandle* AH); extern void ReadToc(ArchiveHandle* AH);
extern void WriteDataChunks(ArchiveHandle* AH); extern void WriteDataChunks(ArchiveHandle* AH);
extern int TocIDRequired(ArchiveHandle* AH, int id, RestoreOptions *ropt); extern int TocIDRequired(ArchiveHandle* AH, int id, RestoreOptions *ropt);
/* /*
* Mandatory routines for each supported format * Mandatory routines for each supported format
*/ */
extern int WriteInt(ArchiveHandle* AH, int i); extern int WriteInt(ArchiveHandle* AH, int i);
extern int ReadInt(ArchiveHandle* AH); extern int ReadInt(ArchiveHandle* AH);
extern char* ReadStr(ArchiveHandle* AH); extern char* ReadStr(ArchiveHandle* AH);
extern int WriteStr(ArchiveHandle* AH, char* s); extern int WriteStr(ArchiveHandle* AH, char* s);
extern void InitArchiveFmt_Custom(ArchiveHandle* AH); extern void InitArchiveFmt_Custom(ArchiveHandle* AH);
extern void InitArchiveFmt_Files(ArchiveHandle* AH); extern void InitArchiveFmt_Files(ArchiveHandle* AH);
extern void InitArchiveFmt_PlainText(ArchiveHandle* AH); extern void InitArchiveFmt_PlainText(ArchiveHandle* AH);
extern OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression); extern OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression);
extern void ResetOutput(ArchiveHandle* AH, OutputContext savedContext); extern void ResetOutput(ArchiveHandle* AH, OutputContext savedContext);
int ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle* AH); int ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle* AH);
int ahprintf(ArchiveHandle* AH, const char *fmt, ...); int ahprintf(ArchiveHandle* AH, const char *fmt, ...);
#endif #endif

View file

@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.157 2000/07/06 18:39:39 wieck Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.158 2000/07/11 13:07:17 momjian Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
@ -2684,8 +2684,8 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
PQExpBuffer fn = createPQExpBuffer(); PQExpBuffer fn = createPQExpBuffer();
PQExpBuffer delqry = createPQExpBuffer(); PQExpBuffer delqry = createPQExpBuffer();
PQExpBuffer fnlist = createPQExpBuffer(); PQExpBuffer fnlist = createPQExpBuffer();
PQExpBuffer asPart = createPQExpBuffer();
int j; int j;
char *func_def;
char func_lang[NAMEDATALEN + 1]; char func_lang[NAMEDATALEN + 1];
PGresult *res; PGresult *res;
int nlangs; int nlangs;
@ -2717,8 +2717,24 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
} }
i_lanname = PQfnumber(res, "lanname"); i_lanname = PQfnumber(res, "lanname");
func_def = finfo[i].prosrc; /*
* See backend/commands/define.c for details of how the 'AS' clause
* is used.
*/
if (strcmp(finfo[i].probin, "-") != 0)
{
if (strcmp(finfo[i].prosrc, "-") != 0)
appendPQExpBuffer(asPart, "AS '%s', '%s'", finfo[i].probin, finfo[i].prosrc);
else
appendPQExpBuffer(asPart, "AS '%s'", finfo[i].probin);
}
else
{
if (strcmp(finfo[i].prosrc, "-") != 0)
appendPQExpBuffer(asPart, "AS '%s'", finfo[i].prosrc);
}
strcpy(func_lang, PQgetvalue(res, 0, i_lanname)); strcpy(func_lang, PQgetvalue(res, 0, i_lanname));
PQclear(res); PQclear(res);
@ -2744,10 +2760,10 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "CREATE FUNCTION %s ", fn->data ); appendPQExpBuffer(q, "CREATE FUNCTION %s ", fn->data );
appendPQExpBuffer(q, "RETURNS %s%s AS '%s' LANGUAGE '%s';\n", appendPQExpBuffer(q, "RETURNS %s%s %s LANGUAGE '%s';\n",
(finfo[i].retset) ? " SETOF " : "", (finfo[i].retset) ? " SETOF " : "",
fmtId(findTypeByOid(tinfo, numTypes, finfo[i].prorettype), false), fmtId(findTypeByOid(tinfo, numTypes, finfo[i].prorettype), false),
func_def, func_lang); asPart->data, func_lang);
ArchiveEntry(fout, finfo[i].oid, fn->data, "FUNCTION", NULL, q->data, delqry->data, ArchiveEntry(fout, finfo[i].oid, fn->data, "FUNCTION", NULL, q->data, delqry->data,
finfo[i].usename, NULL, NULL); finfo[i].usename, NULL, NULL);