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

Commit 672f6ec

Browse files
committed
Brought in David Bennett's (dave@bensoft.com) changes to pg_dump
1 parent 02bbd95 commit 672f6ec

File tree

5 files changed

+85
-14
lines changed

5 files changed

+85
-14
lines changed

src/bin/pg_dump/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.2 1996/07/12 05:39:30 scrappy Exp $
10+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.3 1996/07/22 08:36:57 scrappy Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

src/bin/pg_dump/README.dhb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
version 1.13.dhb.2 README
2+
---------------------------
3+
4+
* Fixed dumpTable output to output lengths for char and varchar types!
5+
6+
* Added single. quote to twin single quote expansion for 'insert' string
7+
mode.
8+
9+
version 1.13.dhb README
10+
-------------------------
111

212
This is a modified version of the pg_dump.c program that is distributed with
313
pg95 1.01. Modifications include:

src/bin/pg_dump/common.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.2 1996/07/12 05:39:33 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $
11+
*
12+
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
13+
*
14+
* - Fixed dumpTable output to output lengths for char and varchar types!
15+
* - Added single. quote to twin single quote expansion for 'insert' string
16+
* mode.
1117
*
1218
*-------------------------------------------------------------------------
1319
*/
@@ -41,7 +47,6 @@ dupstr(char *s)
4147
return result;
4248
}
4349

44-
4550
/*
4651
* findTypeByOid
4752
* given an oid of a type, return its typename

src/bin/pg_dump/pg_dump.c

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@
2020
*
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.2 1996/07/12 05:39:35 scrappy Exp $
23+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $
2424
*
25-
* Modifications - 6/10/96 - dave@bensoft.com
25+
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2626
*
2727
* Applied 'insert string' patch from "Marc G. Fournier" <scrappy@ki.net>
2828
* Added '-t table' option
2929
* Added '-a' option
3030
* Added '-da' option
3131
*
32+
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
33+
*
34+
* - Fixed dumpTable output to output lengths for char and varchar types!
35+
* - Added single. quote to twin single quote expansion for 'insert' string
36+
* mode.
37+
*
3238
*-------------------------------------------------------------------------
3339
*/
3440

@@ -66,6 +72,7 @@ char g_comment_end[10];
6672
static void
6773
usage(char* progname)
6874
{
75+
fprintf(stderr, "%s - version 1.13.dhb.2\n\n",progname);
6976
fprintf(stderr, "usage: %s [options] [dbname]\n",progname);
7077
fprintf(stderr, "\t -f filename \t\t script output filename\n");
7178
fprintf(stderr, "\t -d[a] \t\t dump data as proper insert strings\n");
@@ -745,6 +752,7 @@ getTableAttrs(TableInfo* tblinfo, int numTables)
745752
char q[MAXQUERYLEN];
746753
int i_attname;
747754
int i_typname;
755+
int i_attlen;
748756
PGresult *res;
749757
int ntups;
750758

@@ -764,7 +772,7 @@ if (g_verbose)
764772
tblinfo[i].relname,
765773
g_comment_end);
766774

767-
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);
775+
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);
768776
res = PQexec(g_conn, q);
769777
if (!res ||
770778
PQresultStatus(res) != PGRES_TUPLES_OK) {
@@ -776,16 +784,21 @@ if (g_verbose)
776784

777785
i_attname = PQfnumber(res,"attname");
778786
i_typname = PQfnumber(res,"typname");
787+
i_attlen = PQfnumber(res,"attlen");
779788

780789
tblinfo[i].numatts = ntups;
781790
tblinfo[i].attnames = (char**) malloc( ntups * sizeof(char*));
782791
tblinfo[i].typnames = (char**) malloc( ntups * sizeof(char*));
792+
tblinfo[i].attlen = (int*) malloc(ntups * sizeof(int));
783793
tblinfo[i].inhAttrs = (int*) malloc (ntups * sizeof(int));
784794
tblinfo[i].parentRels = NULL;
785795
tblinfo[i].numParents = 0;
786796
for (j=0;j<ntups;j++) {
787797
tblinfo[i].attnames[j] = dupstr(PQgetvalue(res,j,i_attname));
788798
tblinfo[i].typnames[j] = dupstr(PQgetvalue(res,j,i_typname));
799+
tblinfo[i].attlen[j] = atoi(PQgetvalue(res,j,i_attlen));
800+
if (tblinfo[i].attlen[j] > 0)
801+
tblinfo[i].attlen[j] = tblinfo[i].attlen[j] - 4;
789802
tblinfo[i].inhAttrs[j] = 0; /* this flag is set in flagInhAttrs()*/
790803
}
791804
PQclear(res);
@@ -1194,12 +1207,33 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
11941207
actual_atts = 0;
11951208
for (j=0;j<tblinfo[i].numatts;j++) {
11961209
if (tblinfo[i].inhAttrs[j] == 0) {
1197-
sprintf(q, "%s%s%s %s",
1198-
q,
1199-
(actual_atts > 0) ? ", " : "",
1200-
tblinfo[i].attnames[j],
1201-
tblinfo[i].typnames[j]);
1202-
actual_atts++;
1210+
1211+
/* Show lengths on bpchar and varchar */
1212+
if (!strcmp(tblinfo[i].typnames[j],"bpchar")) {
1213+
sprintf(q, "%s%s%s char(%d)",
1214+
q,
1215+
(actual_atts > 0) ? ", " : "",
1216+
tblinfo[i].attnames[j],
1217+
tblinfo[i].attlen[j]);
1218+
actual_atts++;
1219+
}
1220+
else if (!strcmp(tblinfo[i].typnames[j],"varchar")) {
1221+
sprintf(q, "%s%s%s %s(%d)",
1222+
q,
1223+
(actual_atts > 0) ? ", " : "",
1224+
tblinfo[i].attnames[j],
1225+
tblinfo[i].typnames[j],
1226+
tblinfo[i].attlen[j]);
1227+
actual_atts++;
1228+
}
1229+
else {
1230+
sprintf(q, "%s%s%s %s",
1231+
q,
1232+
(actual_atts > 0) ? ", " : "",
1233+
tblinfo[i].attnames[j],
1234+
tblinfo[i].typnames[j]);
1235+
actual_atts++;
1236+
}
12031237
}
12041238
}
12051239

@@ -1309,6 +1343,8 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable)
13091343
char query[255];
13101344
#define COPYBUFSIZ 8192
13111345
char copybuf[COPYBUFSIZ];
1346+
char expandbuf[COPYBUFSIZ];
1347+
char *expsrc,*expdest;
13121348
char q[MAXQUERYLEN];
13131349
PGresult *res;
13141350
int i,j;
@@ -1397,7 +1433,21 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable)
13971433
fprintf(fout, "%s", PQgetvalue(res,tuple,field));
13981434
break;
13991435
default:
1400-
fprintf(fout, "'%s'", PQgetvalue(res,tuple,field));
1436+
1437+
/* Before outputing string value, expand all
1438+
single quotes to twin single quotes -
1439+
dhb - 6/11/96 */
1440+
expsrc=PQgetvalue(res,tuple,field);
1441+
expdest=expandbuf;
1442+
while (*expsrc) {
1443+
*expdest++=*expsrc;
1444+
if (*expsrc == (char)0x27) /*sing. quote*/
1445+
*expdest++ = *expsrc;
1446+
expsrc++;
1447+
}
1448+
*expdest=*expsrc; /* null term. */
1449+
1450+
fprintf(fout, "'%s'", expandbuf);
14011451
break;
14021452
}
14031453
field++;

src/bin/pg_dump/pg_dump.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pg_dump.h,v 1.2 1996/07/12 05:39:39 scrappy Exp $
8+
* $Id: pg_dump.h,v 1.3 1996/07/22 08:37:00 scrappy Exp $
99
*
10+
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
11+
*
12+
* - Fixed dumpTable output to output lengths for char and varchar types!
13+
* - Added single. quote to twin single quote expansion for 'insert' string
14+
* mode.
1015
*-------------------------------------------------------------------------
1116
*/
1217

@@ -65,6 +70,7 @@ typedef struct _tableInfo {
6570
this is needed because the SQL tables will
6671
not have the same order of attributes as
6772
the POSTQUEL tables */
73+
int *attlen; /* attribute lengths */
6874

6975
} TableInfo;
7076

0 commit comments

Comments
 (0)