Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 232d8fa

Browse files
committed
- Get view OID based on rule OID not base table OID
- Fix crash due to null string pointer in some tar files with some libs
1 parent 83c94a8 commit 232d8fa

File tree

5 files changed

+52
-24
lines changed

5 files changed

+52
-24
lines changed

src/bin/pg_dump/pg_backup_archiver.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.23 2001/04/01 05:42:50 pjw Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.24 2001/04/14 13:11:03 pjw Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -73,7 +73,7 @@ static int _tocSortCompareByOIDNum(const void *p1, const void *p2);
7373
static int _tocSortCompareByIDNum(const void *p1, const void *p2);
7474
static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
7575
const int compression, ArchiveMode mode);
76-
static int _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
76+
static int _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData);
7777

7878
static void _reconnectAsOwner(ArchiveHandle *AH, const char *dbname, TocEntry *te);
7979
static void _reconnectAsUser(ArchiveHandle *AH, const char *dbname, char *user);
@@ -266,7 +266,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
266266
_reconnectAsOwner(AH, "-", te);
267267

268268
ahlog(AH, 1, "Creating %s %s\n", te->desc, te->name);
269-
_printTocEntry(AH, te, ropt);
269+
_printTocEntry(AH, te, ropt, false);
270270

271271
/* If we created a DB, connect to it... */
272272
if (strcmp(te->desc, "DATABASE") == 0)
@@ -286,8 +286,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
286286
die_horribly(AH, "%s: Unable to restore data from a compressed archive\n", progname);
287287
#endif
288288

289-
ahprintf(AH, "--\n-- Data for TOC Entry ID %d (OID %s) %s %s\n--\n\n",
290-
te->id, te->oid, te->desc, te->name);
289+
_printTocEntry(AH, te, ropt, true);
291290

292291
/*
293292
* Maybe we can't do BLOBS, so check if this node is for BLOBS
@@ -1869,10 +1868,19 @@ _reconnectAsOwner(ArchiveHandle *AH, const char *dbname, TocEntry *te)
18691868
}
18701869

18711870
static int
1872-
_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
1871+
_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData)
18731872
{
1874-
ahprintf(AH, "--\n-- TOC Entry ID %d (OID %s)\n--\n-- Name: %s Type: %s Owner: %s\n",
1875-
te->id, te->oid, te->name, te->desc, te->owner);
1873+
char *pfx;
1874+
1875+
if (isData)
1876+
{
1877+
pfx = "Data for ";
1878+
} else {
1879+
pfx = "";
1880+
}
1881+
1882+
ahprintf(AH, "--\n-- %sTOC Entry ID %d (OID %s)\n--\n-- Name: %s Type: %s Owner: %s\n",
1883+
pfx, te->id, te->oid, te->name, te->desc, te->owner);
18761884
if (AH->PrintExtraTocPtr !=NULL)
18771885
(*AH->PrintExtraTocPtr) (AH, te);
18781886
ahprintf(AH, "--\n\n");

src/bin/pg_dump/pg_backup_archiver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.30 2001/04/04 06:47:30 pjw Exp $
20+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.31 2001/04/14 13:11:03 pjw Exp $
2121
*
2222
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2323
* - Initial version.
@@ -68,7 +68,7 @@ typedef z_stream *z_streamp;
6868

6969
#define K_VERS_MAJOR 1
7070
#define K_VERS_MINOR 5
71-
#define K_VERS_REV 2
71+
#define K_VERS_REV 3
7272

7373
/* Data block types */
7474
#define BLK_DATA 1

src/bin/pg_dump/pg_backup_tar.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.13 2001/04/01 05:42:51 pjw Exp $
19+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.14 2001/04/14 13:11:03 pjw Exp $
2020
*
2121
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2222
*
@@ -246,7 +246,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
246246
char fn[K_STD_BUF_SIZE];
247247

248248
ctx = (lclTocEntry *) malloc(sizeof(lclTocEntry));
249-
if (te->dataDumper)
249+
if (te->dataDumper != NULL)
250250
{
251251
#ifdef HAVE_LIBZ
252252
if (AH->compression == 0)
@@ -302,7 +302,8 @@ _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
302302
{
303303
lclTocEntry *ctx = (lclTocEntry *) te->formatData;
304304

305-
ahprintf(AH, "-- File: %s\n", ctx->filename);
305+
if (ctx->filename != NULL)
306+
ahprintf(AH, "-- File: %s\n", ctx->filename);
306307
}
307308

308309
static void

src/bin/pg_dump/pg_dump.c

+24-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.201 2001/04/05 02:50:01 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.202 2001/04/14 13:11:03 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -2035,9 +2035,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
20352035
PGresult *res2;
20362036

20372037
resetPQExpBuffer(query);
2038-
appendPQExpBuffer(query, "SELECT pg_get_viewdef(");
2038+
appendPQExpBuffer(query, "SELECT definition as viewdef, ");
2039+
/* XXX 7.2 - replace with att from pg_views or some other generic source */
2040+
appendPQExpBuffer(query, "(select oid from pg_rewrite where rulename='_RET'"
2041+
" || viewname) as view_oid from pg_views"
2042+
" where viewname = ");
20392043
formatStringLiteral(query, tblinfo[i].relname, CONV_ALL);
2040-
appendPQExpBuffer(query, ") as viewdef");
2044+
appendPQExpBuffer(query, ";");
2045+
20412046
res2 = PQexec(g_conn, query->data);
20422047
if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
20432048
{
@@ -2051,18 +2056,26 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
20512056
{
20522057
if (PQntuples(res2) < 1)
20532058
{
2054-
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned no definitions",
2059+
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned no definitions\n",
20552060
tblinfo[i].relname);
20562061
}
20572062
else
20582063
{
2059-
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned more than 1 definition",
2064+
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned more than 1 definition\n",
20602065
tblinfo[i].relname);
20612066
}
20622067
exit_nicely(g_conn);
20632068
}
20642069

2070+
if (PQgetisnull(res2, 0, 1))
2071+
{
2072+
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned NULL oid\n", tblinfo[i].relname);
2073+
fprintf(stderr, "SELECT was: %s\n", query->data);
2074+
exit_nicely(g_conn);
2075+
}
2076+
20652077
tblinfo[i].viewdef = strdup(PQgetvalue(res2, 0, 0));
2078+
tblinfo[i].viewoid = strdup(PQgetvalue(res2, 0, 1));
20662079

20672080
if (strlen(tblinfo[i].viewdef) == 0)
20682081
{
@@ -3739,6 +3752,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
37393752
int numParents;
37403753
int actual_atts; /* number of attrs in this CREATE statment */
37413754
char *reltypename;
3755+
char *objoid;
37423756

37433757
/* First - dump SEQUENCEs */
37443758
if (tablename && strlen(tablename) > 0)
@@ -3778,15 +3792,15 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
37783792
if (tblinfo[i].viewdef != NULL)
37793793
{
37803794
reltypename = "VIEW";
3781-
3795+
objoid = tblinfo[i].viewoid;
37823796
appendPQExpBuffer(delq, "DROP VIEW %s;\n", fmtId(tblinfo[i].relname, force_quotes));
3783-
appendPQExpBuffer(q, "CREATE VIEW %s as %s", fmtId(tblinfo[i].relname, force_quotes), tblinfo[i].viewdef);
3797+
appendPQExpBuffer(q, "CREATE VIEW %s as %s\n", fmtId(tblinfo[i].relname, force_quotes), tblinfo[i].viewdef);
37843798

37853799
}
37863800
else
37873801
{
37883802
reltypename = "TABLE";
3789-
3803+
objoid = tblinfo[i].oid;
37903804
parentRels = tblinfo[i].parentRels;
37913805
numParents = tblinfo[i].numParents;
37923806

@@ -3883,7 +3897,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
38833897
if (!dataOnly)
38843898
{
38853899

3886-
ArchiveEntry(fout, tblinfo[i].oid, tblinfo[i].relname,
3900+
ArchiveEntry(fout, objoid, tblinfo[i].relname,
38873901
reltypename, NULL, q->data, delq->data, "", tblinfo[i].usename,
38883902
NULL, NULL);
38893903

@@ -4323,7 +4337,7 @@ findLastBuiltinOid(const char *dbname)
43234337
if (res == NULL ||
43244338
PQresultStatus(res) != PGRES_TUPLES_OK)
43254339
{
4326-
fprintf(stderr, "pg_dump: error in finding the last system OID");
4340+
fprintf(stderr, "pg_dump: error in finding the last system OID. ");
43274341
fprintf(stderr, "Explanation from backend: '%s'.\n", PQerrorMessage(g_conn));
43284342
exit_nicely(g_conn);
43294343
}

src/bin/pg_dump/pg_dump.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_dump.h,v 1.61 2001/04/03 08:52:59 pjw Exp $
9+
* $Id: pg_dump.h,v 1.62 2001/04/14 13:11:03 pjw Exp $
1010
*
1111
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1212
*
@@ -88,6 +88,11 @@ typedef struct _tableInfo
8888
char *relname;
8989
char *relacl;
9090
char *viewdef;
91+
char *viewoid; /* OID of view - should be >= oid of table
92+
* important because views may be constructed
93+
* manually from rules, and rule may ref things
94+
* created after the base table was created.
95+
*/
9196
bool sequence;
9297
int numatts; /* number of attributes */
9398
int *inhAttrs; /* an array of flags, one for each

0 commit comments

Comments
 (0)