Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7ed6f8

Browse files
committed
Hi all
Is it too late to add a feature to pg_dump for 6.4??I just spent most of the day learning pg_dump and modifing it so itwoulddump views also.This is the first time I have ever contributed any code changes, so I'mnot sure of how to submit it.The diff's and a readme as a tgz file are attached.ThanksTerry Mackintosh <terry@terrym.com>http://www.terrym.com
1 parente1ebac3 commitb7ed6f8

File tree

3 files changed

+122
-79
lines changed

3 files changed

+122
-79
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 115 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.88 1998/10/02 16:43:40 thomas Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.89 1998/10/06 03:08:59 momjian Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -1383,7 +1383,7 @@ getFuncs(int *numFuncs)
13831383
TableInfo*
13841384
getTables(int*numTables,FuncInfo*finfo,intnumFuncs)
13851385
{
1386-
PGresult*res;
1386+
PGresult*res,*viewres;
13871387
intntups;
13881388
inti;
13891389
charquery[MAXQUERYLEN];
@@ -1414,6 +1414,8 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14141414
}
14151415
PQclear(res);
14161416

1417+
/* NOTE, when outer joins are here, change this query to get the
1418+
view definition all in one go. */
14171419
sprintf(query,
14181420
"SELECT pg_class.oid, relname, relkind, relacl, usename, "
14191421
"relchecks, reltriggers "
@@ -1454,6 +1456,39 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14541456
tblinfo[i].ncheck=atoi(PQgetvalue(res,i,i_relchecks));
14551457
tblinfo[i].ntrig=atoi(PQgetvalue(res,i,i_reltriggers));
14561458

1459+
/* NOTE that at such time as left outer joins become avaliable,
1460+
then this will no longer be needed, and can be done in the
1461+
above query. */
1462+
1463+
sprintf(query,
1464+
"select definition from pg_views where viewname = '%s';",
1465+
tblinfo[i].relname);
1466+
1467+
viewres=PQexec(g_conn,query);
1468+
if (!viewres||
1469+
PQresultStatus(res)!=PGRES_TUPLES_OK)
1470+
{
1471+
fprintf(stderr,"getTables(): SELECT for views failed\n");
1472+
exit_nicely(g_conn);
1473+
}
1474+
1475+
/* NOTE: Tryed to use isViewRule here, but it does it's own
1476+
BEGIN and END so messed things up.
1477+
This also needs redone should we ever get outer joins.
1478+
*/
1479+
if (PQntuples(viewres)>0 )
1480+
{
1481+
if (PQntuples(viewres)!=1 )
1482+
{
1483+
fprintf(stderr,"getTables(): failed to get view definition.\n");
1484+
exit_nicely(g_conn);
1485+
}
1486+
1487+
tblinfo[i].viewdef=strdup(PQgetvalue(viewres,0,0));
1488+
}
1489+
1490+
PQclear(viewres);
1491+
14571492
/* Get CHECK constraints */
14581493
if (tblinfo[i].ncheck>0)
14591494
{
@@ -2468,95 +2503,102 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
24682503
if (!tablename|| (!strcmp(tblinfo[i].relname,tablename)))
24692504
{
24702505

2471-
/*Skip VIEW relations */
2506+
/*Dump VIEW relations also !-) */
24722507
if (isViewRule(tblinfo[i].relname))
2473-
continue;
2474-
2475-
parentRels=tblinfo[i].parentRels;
2476-
numParents=tblinfo[i].numParents;
2477-
2478-
becomeUser(fout,tblinfo[i].usename);
2508+
{
2509+
becomeUser(fout,tblinfo[i].usename);
24792510

2480-
sprintf(q,"CREATE TABLE %s (",fmtId(tblinfo[i].relname));
2481-
actual_atts=0;
2482-
for (j=0;j<tblinfo[i].numatts;j++)
2511+
sprintf(q,"CREATE VIEW %s AS %s\n",
2512+
fmtId(tblinfo[i].relname),
2513+
tblinfo[i].viewdef);
2514+
}
2515+
else
24832516
{
2484-
if (tblinfo[i].inhAttrs[j]==0)
2485-
{
2517+
parentRels=tblinfo[i].parentRels;
2518+
numParents=tblinfo[i].numParents;
24862519

2487-
/* Show lengths on bpchar and varchar */
2488-
if (!strcmp(tblinfo[i].typnames[j],"bpchar"))
2489-
{
2490-
sprintf(q,"%s%s%s char",
2491-
q,
2492-
(actual_atts>0) ?", " :"",
2493-
fmtId(tblinfo[i].attnames[j]));
2520+
becomeUser(fout,tblinfo[i].usename);
24942521

2495-
sprintf(q,"%s(%d)",
2496-
q,
2497-
tblinfo[i].atttypmod[j]-VARHDRSZ);
2498-
actual_atts++;
2499-
}
2500-
elseif (!strcmp(tblinfo[i].typnames[j],"varchar"))
2522+
sprintf(q,"CREATE TABLE %s (",fmtId(tblinfo[i].relname));
2523+
actual_atts=0;
2524+
for (j=0;j<tblinfo[i].numatts;j++)
2525+
{
2526+
if (tblinfo[i].inhAttrs[j]==0)
25012527
{
2502-
sprintf(q,"%s%s%s %s",
2503-
q,
2504-
(actual_atts>0) ?", " :"",
2505-
fmtId(tblinfo[i].attnames[j]),
2506-
tblinfo[i].typnames[j]);
25072528

2508-
sprintf(q,"%s(%d)",
2509-
q,
2510-
tblinfo[i].atttypmod[j]-VARHDRSZ);
2511-
actual_atts++;
2512-
}
2513-
else
2514-
{
2515-
strcpy(id1,fmtId(tblinfo[i].attnames[j]));
2516-
strcpy(id2,fmtId(tblinfo[i].typnames[j]));
2517-
sprintf(q,"%s%s%s %s",
2518-
q,
2519-
(actual_atts>0) ?", " :"",
2520-
id1,
2521-
id2);
2522-
actual_atts++;
2529+
/* Show lengths on bpchar and varchar */
2530+
if (!strcmp(tblinfo[i].typnames[j],"bpchar"))
2531+
{
2532+
sprintf(q,"%s%s%s char",
2533+
q,
2534+
(actual_atts>0) ?", " :"",
2535+
fmtId(tblinfo[i].attnames[j]));
2536+
2537+
sprintf(q,"%s(%d)",
2538+
q,
2539+
tblinfo[i].atttypmod[j]-VARHDRSZ);
2540+
actual_atts++;
2541+
}
2542+
elseif (!strcmp(tblinfo[i].typnames[j],"varchar"))
2543+
{
2544+
sprintf(q,"%s%s%s %s",
2545+
q,
2546+
(actual_atts>0) ?", " :"",
2547+
fmtId(tblinfo[i].attnames[j]),
2548+
tblinfo[i].typnames[j]);
2549+
2550+
sprintf(q,"%s(%d)",
2551+
q,
2552+
tblinfo[i].atttypmod[j]-VARHDRSZ);
2553+
actual_atts++;
2554+
}
2555+
else
2556+
{
2557+
strcpy(id1,fmtId(tblinfo[i].attnames[j]));
2558+
strcpy(id2,fmtId(tblinfo[i].typnames[j]));
2559+
sprintf(q,"%s%s%s %s",
2560+
q,
2561+
(actual_atts>0) ?", " :"",
2562+
id1,
2563+
id2);
2564+
actual_atts++;
2565+
}
2566+
if (tblinfo[i].adef_expr[j]!=NULL)
2567+
sprintf(q,"%s DEFAULT %s",q,tblinfo[i].adef_expr[j]);
2568+
if (tblinfo[i].notnull[j])
2569+
sprintf(q,"%s NOT NULL",q);
25232570
}
2524-
if (tblinfo[i].adef_expr[j]!=NULL)
2525-
sprintf(q,"%s DEFAULT %s",q,tblinfo[i].adef_expr[j]);
2526-
if (tblinfo[i].notnull[j])
2527-
sprintf(q,"%s NOT NULL",q);
25282571
}
2529-
}
25302572

2531-
/* put the CONSTRAINTS inside the table def */
2532-
for (k=0;k<tblinfo[i].ncheck;k++)
2533-
{
2534-
sprintf(q,"%s%s %s",
2535-
q,
2536-
(actual_atts+k>0) ?", " :"",
2537-
tblinfo[i].check_expr[k]);
2538-
}
2539-
2540-
strcat(q,")");
2541-
2542-
if (numParents>0)
2543-
{
2544-
sprintf(q,"%s inherits ( ",q);
2545-
for (k=0;k<numParents;k++)
2573+
/* put the CONSTRAINTS inside the table def */
2574+
for (k=0;k<tblinfo[i].ncheck;k++)
25462575
{
2547-
sprintf(q,"%s%s%s",
2576+
sprintf(q,"%s%s%s",
25482577
q,
2549-
(k>0) ?", " :"",
2550-
fmtId(parentRels[k]));
2578+
(actual_atts+k>0) ?", " :"",
2579+
tblinfo[i].check_expr[k]);
25512580
}
2581+
25522582
strcat(q,")");
2553-
}
25542583

2555-
strcat(q,";\n");
2584+
if (numParents>0)
2585+
{
2586+
sprintf(q,"%s inherits ( ",q);
2587+
for (k=0;k<numParents;k++)
2588+
{
2589+
sprintf(q,"%s%s%s",
2590+
q,
2591+
(k>0) ?", " :"",
2592+
fmtId(parentRels[k]));
2593+
}
2594+
strcat(q,")");
2595+
}
2596+
strcat(q,";\n");
2597+
}/* end of if view ... else .... */
2598+
25562599
fputs(q,fout);
25572600
if (acls)
25582601
dumpACL(fout,tblinfo[i]);
2559-
25602602
}
25612603
}
25622604
}

‎src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pg_dump.h,v 1.33 1998/10/02 16:43:41 thomas Exp $
8+
* $Id: pg_dump.h,v 1.34 1998/10/06 03:09:01 momjian Exp $
99
*
1010
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1111
*
@@ -66,6 +66,7 @@ typedef struct _tableInfo
6666
{
6767
char*oid;
6868
char*relname;
69+
char*viewdef;
6970
char*relacl;
7071
boolsequence;
7172
intnumatts;/* number of attributes */

‎src/man/pg_dump.1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/pg_dump.1,v 1.12 1998/07/19 05:24:51 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/pg_dump.1,v 1.13 1998/10/06 03:09:02 momjian Exp $
44
.TH PG_DUMP UNIX 7/15/98 PostgreSQL PostgreSQL
55
.SH NAME
66
pg_dump - dumps out a Postgres database into a script file
@@ -112,10 +112,10 @@ The limitations mostly stem from
112112
difficulty in extracting certain meta-information from the system
113113
catalogs.
114114
.TP
115-
.BR"rules and views"
116-
pg_dump does not understand user-defined rules andviews and
117-
will failto dump them properly. (This is due to the fact that
118-
rules are stored as plans in the catalogs and not textually)
115+
.BR"rules"
116+
pg_dump does not understand user-defined rules andwill fail
117+
to dump them properly. (This is due to the fact that
118+
rules are stored as plans in the catalogs and not textually.)
119119
.TP
120120
.BR"partial indices"
121121
pg_dump does not understand partial indices. (The reason is

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp