Brought in David Bennett's (dave@bensoft.com) changes to pg_dump
This commit is contained in:
parent
02bbd95a41
commit
672f6ece23
@ -7,7 +7,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
# IDENTIFICATION
|
# 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 $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -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
|
This is a modified version of the pg_dump.c program that is distributed with
|
||||||
pg95 1.01. Modifications include:
|
pg95 1.01. Modifications include:
|
||||||
|
@ -7,7 +7,13 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* findTypeByOid
|
* findTypeByOid
|
||||||
* given an oid of a type, return its typename
|
* given an oid of a type, return its typename
|
||||||
|
@ -20,15 +20,21 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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>
|
* Applied 'insert string' patch from "Marc G. Fournier" <scrappy@ki.net>
|
||||||
* Added '-t table' option
|
* Added '-t table' option
|
||||||
* Added '-a' option
|
* Added '-a' option
|
||||||
* Added '-da' 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
|
static void
|
||||||
usage(char* progname)
|
usage(char* progname)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "%s - version 1.13.dhb.2\n\n",progname);
|
||||||
fprintf(stderr, "usage: %s [options] [dbname]\n",progname);
|
fprintf(stderr, "usage: %s [options] [dbname]\n",progname);
|
||||||
fprintf(stderr, "\t -f filename \t\t script output filename\n");
|
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");
|
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];
|
char q[MAXQUERYLEN];
|
||||||
int i_attname;
|
int i_attname;
|
||||||
int i_typname;
|
int i_typname;
|
||||||
|
int i_attlen;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
int ntups;
|
int ntups;
|
||||||
|
|
||||||
@ -764,7 +772,7 @@ if (g_verbose)
|
|||||||
tblinfo[i].relname,
|
tblinfo[i].relname,
|
||||||
g_comment_end);
|
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);
|
res = PQexec(g_conn, q);
|
||||||
if (!res ||
|
if (!res ||
|
||||||
PQresultStatus(res) != PGRES_TUPLES_OK) {
|
PQresultStatus(res) != PGRES_TUPLES_OK) {
|
||||||
@ -776,16 +784,21 @@ if (g_verbose)
|
|||||||
|
|
||||||
i_attname = PQfnumber(res,"attname");
|
i_attname = PQfnumber(res,"attname");
|
||||||
i_typname = PQfnumber(res,"typname");
|
i_typname = PQfnumber(res,"typname");
|
||||||
|
i_attlen = PQfnumber(res,"attlen");
|
||||||
|
|
||||||
tblinfo[i].numatts = ntups;
|
tblinfo[i].numatts = ntups;
|
||||||
tblinfo[i].attnames = (char**) malloc( ntups * sizeof(char*));
|
tblinfo[i].attnames = (char**) malloc( ntups * sizeof(char*));
|
||||||
tblinfo[i].typnames = (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].inhAttrs = (int*) malloc (ntups * sizeof(int));
|
||||||
tblinfo[i].parentRels = NULL;
|
tblinfo[i].parentRels = NULL;
|
||||||
tblinfo[i].numParents = 0;
|
tblinfo[i].numParents = 0;
|
||||||
for (j=0;j<ntups;j++) {
|
for (j=0;j<ntups;j++) {
|
||||||
tblinfo[i].attnames[j] = dupstr(PQgetvalue(res,j,i_attname));
|
tblinfo[i].attnames[j] = dupstr(PQgetvalue(res,j,i_attname));
|
||||||
tblinfo[i].typnames[j] = dupstr(PQgetvalue(res,j,i_typname));
|
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()*/
|
tblinfo[i].inhAttrs[j] = 0; /* this flag is set in flagInhAttrs()*/
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@ -1194,12 +1207,33 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
|
|||||||
actual_atts = 0;
|
actual_atts = 0;
|
||||||
for (j=0;j<tblinfo[i].numatts;j++) {
|
for (j=0;j<tblinfo[i].numatts;j++) {
|
||||||
if (tblinfo[i].inhAttrs[j] == 0) {
|
if (tblinfo[i].inhAttrs[j] == 0) {
|
||||||
sprintf(q, "%s%s%s %s",
|
|
||||||
q,
|
/* Show lengths on bpchar and varchar */
|
||||||
(actual_atts > 0) ? ", " : "",
|
if (!strcmp(tblinfo[i].typnames[j],"bpchar")) {
|
||||||
tblinfo[i].attnames[j],
|
sprintf(q, "%s%s%s char(%d)",
|
||||||
tblinfo[i].typnames[j]);
|
q,
|
||||||
actual_atts++;
|
(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) ? ", " : "",
|
||||||
|
tblinfo[i].attnames[j],
|
||||||
|
tblinfo[i].typnames[j]);
|
||||||
|
actual_atts++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1309,6 +1343,8 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable)
|
|||||||
char query[255];
|
char query[255];
|
||||||
#define COPYBUFSIZ 8192
|
#define COPYBUFSIZ 8192
|
||||||
char copybuf[COPYBUFSIZ];
|
char copybuf[COPYBUFSIZ];
|
||||||
|
char expandbuf[COPYBUFSIZ];
|
||||||
|
char *expsrc,*expdest;
|
||||||
char q[MAXQUERYLEN];
|
char q[MAXQUERYLEN];
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
int i,j;
|
int i,j;
|
||||||
@ -1397,7 +1433,21 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable)
|
|||||||
fprintf(fout, "%s", PQgetvalue(res,tuple,field));
|
fprintf(fout, "%s", PQgetvalue(res,tuple,field));
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
field++;
|
field++;
|
||||||
|
@ -5,8 +5,13 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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
|
this is needed because the SQL tables will
|
||||||
not have the same order of attributes as
|
not have the same order of attributes as
|
||||||
the POSTQUEL tables */
|
the POSTQUEL tables */
|
||||||
|
int *attlen; /* attribute lengths */
|
||||||
|
|
||||||
} TableInfo;
|
} TableInfo;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user