Brought in David Bennett's (dave@bensoft.com) changes to pg_dump

This commit is contained in:
Marc G. Fournier 1996-07-22 08:37:00 +00:00
parent 02bbd95a41
commit 672f6ece23
5 changed files with 85 additions and 14 deletions

View File

@ -7,7 +7,7 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.2 1996/07/12 05:39:30 scrappy Exp $
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.3 1996/07/22 08:36:57 scrappy Exp $
#
#-------------------------------------------------------------------------

View File

@ -1,3 +1,13 @@
version 1.13.dhb.2 README
---------------------------
* Fixed dumpTable output to output lengths for char and varchar types!
* Added single. quote to twin single quote expansion for 'insert' string
mode.
version 1.13.dhb README
-------------------------
This is a modified version of the pg_dump.c program that is distributed with
pg95 1.01. Modifications include:

View File

@ -7,7 +7,13 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.2 1996/07/12 05:39:33 scrappy Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
* - Fixed dumpTable output to output lengths for char and varchar types!
* - Added single. quote to twin single quote expansion for 'insert' string
* mode.
*
*-------------------------------------------------------------------------
*/
@ -41,7 +47,6 @@ dupstr(char *s)
return result;
}
/*
* findTypeByOid
* given an oid of a type, return its typename

View File

@ -20,15 +20,21 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.2 1996/07/12 05:39:35 scrappy Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
* Applied 'insert string' patch from "Marc G. Fournier" <scrappy@ki.net>
* Added '-t table' option
* Added '-a' option
* Added '-da' option
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
* - Fixed dumpTable output to output lengths for char and varchar types!
* - Added single. quote to twin single quote expansion for 'insert' string
* mode.
*
*-------------------------------------------------------------------------
*/
@ -66,6 +72,7 @@ char g_comment_end[10];
static void
usage(char* progname)
{
fprintf(stderr, "%s - version 1.13.dhb.2\n\n",progname);
fprintf(stderr, "usage: %s [options] [dbname]\n",progname);
fprintf(stderr, "\t -f filename \t\t script output filename\n");
fprintf(stderr, "\t -d[a] \t\t dump data as proper insert strings\n");
@ -745,6 +752,7 @@ getTableAttrs(TableInfo* tblinfo, int numTables)
char q[MAXQUERYLEN];
int i_attname;
int i_typname;
int i_attlen;
PGresult *res;
int ntups;
@ -764,7 +772,7 @@ if (g_verbose)
tblinfo[i].relname,
g_comment_end);
sprintf(q,"SELECT a.attnum, a.attname, t.typname from pg_attribute a, pg_type t where a.attrelid = '%s'::oid and a.atttypid = t.oid and a.attnum > 0 order by attnum",tblinfo[i].oid);
sprintf(q,"SELECT a.attnum, a.attname, t.typname, a.attlen from pg_attribute a, pg_type t where a.attrelid = '%s'::oid and a.atttypid = t.oid and a.attnum > 0 order by attnum",tblinfo[i].oid);
res = PQexec(g_conn, q);
if (!res ||
PQresultStatus(res) != PGRES_TUPLES_OK) {
@ -776,16 +784,21 @@ if (g_verbose)
i_attname = PQfnumber(res,"attname");
i_typname = PQfnumber(res,"typname");
i_attlen = PQfnumber(res,"attlen");
tblinfo[i].numatts = ntups;
tblinfo[i].attnames = (char**) malloc( ntups * sizeof(char*));
tblinfo[i].typnames = (char**) malloc( ntups * sizeof(char*));
tblinfo[i].attlen = (int*) malloc(ntups * sizeof(int));
tblinfo[i].inhAttrs = (int*) malloc (ntups * sizeof(int));
tblinfo[i].parentRels = NULL;
tblinfo[i].numParents = 0;
for (j=0;j<ntups;j++) {
tblinfo[i].attnames[j] = dupstr(PQgetvalue(res,j,i_attname));
tblinfo[i].typnames[j] = dupstr(PQgetvalue(res,j,i_typname));
tblinfo[i].attlen[j] = atoi(PQgetvalue(res,j,i_attlen));
if (tblinfo[i].attlen[j] > 0)
tblinfo[i].attlen[j] = tblinfo[i].attlen[j] - 4;
tblinfo[i].inhAttrs[j] = 0; /* this flag is set in flagInhAttrs()*/
}
PQclear(res);
@ -1194,6 +1207,26 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
actual_atts = 0;
for (j=0;j<tblinfo[i].numatts;j++) {
if (tblinfo[i].inhAttrs[j] == 0) {
/* Show lengths on bpchar and varchar */
if (!strcmp(tblinfo[i].typnames[j],"bpchar")) {
sprintf(q, "%s%s%s char(%d)",
q,
(actual_atts > 0) ? ", " : "",
tblinfo[i].attnames[j],
tblinfo[i].attlen[j]);
actual_atts++;
}
else if (!strcmp(tblinfo[i].typnames[j],"varchar")) {
sprintf(q, "%s%s%s %s(%d)",
q,
(actual_atts > 0) ? ", " : "",
tblinfo[i].attnames[j],
tblinfo[i].typnames[j],
tblinfo[i].attlen[j]);
actual_atts++;
}
else {
sprintf(q, "%s%s%s %s",
q,
(actual_atts > 0) ? ", " : "",
@ -1202,6 +1235,7 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
actual_atts++;
}
}
}
strcat(q,")");
@ -1309,6 +1343,8 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable)
char query[255];
#define COPYBUFSIZ 8192
char copybuf[COPYBUFSIZ];
char expandbuf[COPYBUFSIZ];
char *expsrc,*expdest;
char q[MAXQUERYLEN];
PGresult *res;
int i,j;
@ -1397,7 +1433,21 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable)
fprintf(fout, "%s", PQgetvalue(res,tuple,field));
break;
default:
fprintf(fout, "'%s'", PQgetvalue(res,tuple,field));
/* Before outputing string value, expand all
single quotes to twin single quotes -
dhb - 6/11/96 */
expsrc=PQgetvalue(res,tuple,field);
expdest=expandbuf;
while (*expsrc) {
*expdest++=*expsrc;
if (*expsrc == (char)0x27) /*sing. quote*/
*expdest++ = *expsrc;
expsrc++;
}
*expdest=*expsrc; /* null term. */
fprintf(fout, "'%s'", expandbuf);
break;
}
field++;

View File

@ -5,8 +5,13 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_dump.h,v 1.2 1996/07/12 05:39:39 scrappy Exp $
* $Id: pg_dump.h,v 1.3 1996/07/22 08:37:00 scrappy Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
* - Fixed dumpTable output to output lengths for char and varchar types!
* - Added single. quote to twin single quote expansion for 'insert' string
* mode.
*-------------------------------------------------------------------------
*/
@ -65,6 +70,7 @@ typedef struct _tableInfo {
this is needed because the SQL tables will
not have the same order of attributes as
the POSTQUEL tables */
int *attlen; /* attribute lengths */
} TableInfo;