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

Commit 8eb18d8

Browse files
committed
Fix pg_dump to use the same maximum-query-size constant as
the backend does. Remove unnecessary limitation on field size in dumpClasses_dumpData (ie, -d or -D case).
1 parent 26fb87d commit 8eb18d8

File tree

3 files changed

+90
-95
lines changed

3 files changed

+90
-95
lines changed

src/bin/pg_dump/common.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.30 1999/05/25 16:13:05 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.31 1999/05/26 21:51:13 tgl Exp $
1111
*
1212
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1313
*
@@ -502,7 +502,7 @@ const char *
502502
fmtId(const char *rawid, bool force_quotes)
503503
{
504504
const char *cp;
505-
static char id[MAXQUERYLEN];
505+
static char id[MAX_QUERY_SIZE];
506506

507507
if (!force_quotes)
508508
for (cp = rawid; *cp != '\0'; cp++)

src/bin/pg_dump/pg_dump.c

+86-86
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.111 1999/05/26 19:45:53 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.112 1999/05/26 21:51:12 tgl Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -188,7 +188,7 @@ isViewRule(char *relname)
188188
{
189189
PGresult *res;
190190
int ntups;
191-
char query[MAXQUERYLEN];
191+
char query[MAX_QUERY_SIZE];
192192

193193
res = PQexec(g_conn, "begin");
194194
if (!res ||
@@ -319,11 +319,10 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
319319
const TableInfo tblinfo, bool oids)
320320
{
321321
PGresult *res;
322-
char q[MAXQUERYLEN];
322+
char q[MAX_QUERY_SIZE];
323323
int tuple;
324324
int field;
325325
char *expsrc;
326-
char *expdest;
327326

328327
sprintf(q, "SELECT * FROM %s", fmtId(classname, force_quotes));
329328
res = PQexec(g_conn, q);
@@ -348,60 +347,58 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
348347
strcat(q, ") ");
349348
fprintf(fout, "%s", q);
350349
}
351-
fprintf(fout, "values (");
350+
fprintf(fout, "VALUES (");
352351
for (field = 0; field < PQnfields(res); field++)
353352
{
354353
if (field > 0)
355354
fprintf(fout, ",");
356355
if (PQgetisnull(res, tuple, field))
356+
{
357357
fprintf(fout, "NULL");
358-
else
358+
continue;
359+
}
360+
switch (PQftype(res, field))
359361
{
360-
switch (PQftype(res, field))
361-
{
362-
case INT2OID:
363-
case INT4OID:
364-
case OIDOID: /* int types */
365-
case FLOAT4OID:
366-
case FLOAT8OID: /* float types */
367-
/* These types are printed without quotes */
368-
fprintf(fout, "%s",
369-
PQgetvalue(res, tuple, field));
370-
break;
371-
default:
372-
373-
/*
374-
* All other types are printed as string literals,
375-
* with appropriate escaping of special
376-
* characters. Quote mark ' goes to '' per SQL
377-
* standard, other stuff goes to \ sequences.
378-
*/
379-
expsrc = PQgetvalue(res, tuple, field);
380-
expdest = q;
381-
for (; *expsrc; expsrc++)
362+
case INT2OID:
363+
case INT4OID:
364+
case OIDOID: /* int types */
365+
case FLOAT4OID:
366+
case FLOAT8OID: /* float types */
367+
/* These types are printed without quotes */
368+
fprintf(fout, "%s",
369+
PQgetvalue(res, tuple, field));
370+
break;
371+
default:
372+
/*
373+
* All other types are printed as string literals,
374+
* with appropriate escaping of special
375+
* characters. Quote mark ' goes to '' per SQL
376+
* standard, other stuff goes to \ sequences.
377+
*/
378+
putc('\'', fout);
379+
expsrc = PQgetvalue(res, tuple, field);
380+
while (*expsrc)
381+
{
382+
char ch = *expsrc++;
383+
384+
if (ch == '\\' || ch == '\'')
382385
{
383-
char ch = *expsrc;
384-
385-
if (ch == '\\' || ch == '\'')
386-
{
387-
*expdest++ = ch; /* double it */
388-
*expdest++ = ch;
389-
}
390-
else if (ch < '\040')
391-
{
392-
/* generate octal escape for control chars */
393-
*expdest++ = '\\';
394-
*expdest++ = ((ch >> 6) & 3) + '0';
395-
*expdest++ = ((ch >> 3) & 7) + '0';
396-
*expdest++ = (ch & 7) + '0';
397-
}
398-
else
399-
*expdest++ = ch;
386+
putc(ch, fout); /* double these */
387+
putc(ch, fout);
400388
}
401-
*expdest = '\0';
402-
fprintf(fout, "'%s'", q);
403-
break;
404-
}
389+
else if (ch < '\040')
390+
{
391+
/* generate octal escape for control chars */
392+
putc('\\', fout);
393+
putc(((ch >> 6) & 3) + '0', fout);
394+
putc(((ch >> 3) & 7) + '0', fout);
395+
putc((ch & 7) + '0', fout);
396+
}
397+
else
398+
putc(ch, fout);
399+
}
400+
putc('\'', fout);
401+
break;
405402
}
406403
}
407404
fprintf(fout, ");\n");
@@ -746,7 +743,9 @@ main(int argc, char **argv)
746743
}
747744

748745
fflush(g_fout);
749-
fclose(g_fout);
746+
if (g_fout != stdout)
747+
fclose(g_fout);
748+
750749
clearTableInfo(tblinfo, numTables);
751750
PQfinish(g_conn);
752751
exit(0);
@@ -766,7 +765,7 @@ getTypes(int *numTypes)
766765
PGresult *res;
767766
int ntups;
768767
int i;
769-
char query[MAXQUERYLEN];
768+
char query[MAX_QUERY_SIZE];
770769
TypeInfo *tinfo;
771770

772771
int i_oid;
@@ -895,7 +894,7 @@ getOperators(int *numOprs)
895894
PGresult *res;
896895
int ntups;
897896
int i;
898-
char query[MAXQUERYLEN];
897+
char query[MAX_QUERY_SIZE];
899898

900899
OprInfo *oprinfo;
901900

@@ -1238,7 +1237,7 @@ getAggregates(int *numAggs)
12381237
PGresult *res;
12391238
int ntups;
12401239
int i;
1241-
char query[MAXQUERYLEN];
1240+
char query[MAX_QUERY_SIZE];
12421241
AggInfo *agginfo;
12431242

12441243
int i_oid;
@@ -1332,7 +1331,7 @@ getFuncs(int *numFuncs)
13321331
PGresult *res;
13331332
int ntups;
13341333
int i;
1335-
char query[MAXQUERYLEN];
1334+
char query[MAX_QUERY_SIZE];
13361335
FuncInfo *finfo;
13371336

13381337
int i_oid;
@@ -1432,7 +1431,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14321431
PGresult *res;
14331432
int ntups;
14341433
int i;
1435-
char query[MAXQUERYLEN];
1434+
char query[MAX_QUERY_SIZE];
14361435
TableInfo *tblinfo;
14371436

14381437
int i_oid;
@@ -1651,7 +1650,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16511650
int tgnargs = atoi(PQgetvalue(res2, i2, i_tgnargs));
16521651
char *tgargs = PQgetvalue(res2, i2, i_tgargs);
16531652
char *p;
1654-
char farg[MAXQUERYLEN];
1653+
char farg[MAX_QUERY_SIZE];
16551654
int findx;
16561655

16571656
for (findx = 0; findx < numFuncs; findx++)
@@ -1778,7 +1777,7 @@ getInherits(int *numInherits)
17781777
PGresult *res;
17791778
int ntups;
17801779
int i;
1781-
char query[MAXQUERYLEN];
1780+
char query[MAX_QUERY_SIZE];
17821781
InhInfo *inhinfo;
17831782

17841783
int i_inhrel;
@@ -1840,7 +1839,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
18401839
{
18411840
int i,
18421841
j;
1843-
char q[MAXQUERYLEN];
1842+
char q[MAX_QUERY_SIZE];
18441843
int i_attname;
18451844
int i_typname;
18461845
int i_atttypmod;
@@ -1951,7 +1950,7 @@ IndInfo *
19511950
getIndices(int *numIndices)
19521951
{
19531952
int i;
1954-
char query[MAXQUERYLEN];
1953+
char query[MAX_QUERY_SIZE];
19551954
PGresult *res;
19561955
int ntups;
19571956
IndInfo *indinfo;
@@ -2042,7 +2041,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
20422041
TypeInfo *tinfo, int numTypes)
20432042
{
20442043
int i;
2045-
char q[MAXQUERYLEN];
2044+
char q[MAX_QUERY_SIZE];
20462045
int funcInd;
20472046

20482047
for (i = 0; i < numTypes; i++)
@@ -2122,7 +2121,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
21222121
TypeInfo *tinfo, int numTypes)
21232122
{
21242123
PGresult *res;
2125-
char query[MAXQUERYLEN];
2124+
char query[MAX_QUERY_SIZE];
21262125
int ntups;
21272126
int i_lanname;
21282127
int i_lanpltrusted;
@@ -2224,7 +2223,7 @@ static void
22242223
dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
22252224
TypeInfo *tinfo, int numTypes)
22262225
{
2227-
char q[MAXQUERYLEN];
2226+
char q[MAX_QUERY_SIZE];
22282227
int j;
22292228
char *func_def;
22302229
char func_lang[NAMEDATALEN + 1];
@@ -2344,15 +2343,15 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
23442343
TypeInfo *tinfo, int numTypes)
23452344
{
23462345
int i;
2347-
char q[MAXQUERYLEN];
2348-
char leftarg[MAXQUERYLEN];
2349-
char rightarg[MAXQUERYLEN];
2350-
char commutator[MAXQUERYLEN];
2351-
char negator[MAXQUERYLEN];
2352-
char restrictor[MAXQUERYLEN];
2353-
char join[MAXQUERYLEN];
2354-
char sort1[MAXQUERYLEN];
2355-
char sort2[MAXQUERYLEN];
2346+
char q[MAX_QUERY_SIZE];
2347+
char leftarg[MAX_QUERY_SIZE/8];
2348+
char rightarg[MAX_QUERY_SIZE/8];
2349+
char commutator[MAX_QUERY_SIZE/8];
2350+
char negator[MAX_QUERY_SIZE/8];
2351+
char restrictor[MAX_QUERY_SIZE/8];
2352+
char join[MAX_QUERY_SIZE/8];
2353+
char sort1[MAX_QUERY_SIZE/8];
2354+
char sort2[MAX_QUERY_SIZE/8];
23562355

23572356
for (i = 0; i < numOperators; i++)
23582357
{
@@ -2460,11 +2459,11 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
24602459
TypeInfo *tinfo, int numTypes)
24612460
{
24622461
int i;
2463-
char q[MAXQUERYLEN];
2464-
char sfunc1[MAXQUERYLEN];
2465-
char sfunc2[MAXQUERYLEN];
2466-
char basetype[MAXQUERYLEN];
2467-
char finalfunc[MAXQUERYLEN];
2462+
char q[MAX_QUERY_SIZE];
2463+
char sfunc1[MAX_QUERY_SIZE];
2464+
char sfunc2[MAX_QUERY_SIZE];
2465+
char basetype[MAX_QUERY_SIZE];
2466+
char finalfunc[MAX_QUERY_SIZE];
24682467
char comma1[2],
24692468
comma2[2];
24702469

@@ -2667,10 +2666,11 @@ dumpACL(FILE *fout, TableInfo tbinfo)
26672666
else
26682667
{
26692668
*eqpos = '\0'; /* it's ok to clobber aclbuf */
2670-
if (strncmp(tok, "group ",strlen("group ")) == 0)
2671-
fprintf(fout, "GROUP %s;\n",
2672-
fmtId(tok + sizeof("group ") - 1, force_quotes));
2673-
else fprintf(fout, "%s;\n", fmtId(tok, force_quotes));
2669+
if (strncmp(tok, "group ", strlen("group ")) == 0)
2670+
fprintf(fout, "GROUP %s;\n",
2671+
fmtId(tok + strlen("group "), force_quotes));
2672+
else
2673+
fprintf(fout, "%s;\n", fmtId(tok, force_quotes));
26742674
}
26752675
}
26762676
free(priv);
@@ -2694,7 +2694,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
26942694
int i,
26952695
j,
26962696
k;
2697-
char q[MAXQUERYLEN];
2697+
char q[MAX_QUERY_SIZE];
26982698
char *serialSeq = NULL; /* implicit sequence name created
26992699
* by SERIAL datatype */
27002700
const char *serialSeqSuffix = "_id_seq"; /* suffix for implicit
@@ -2873,9 +2873,9 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
28732873
indclass;
28742874
int nclass;
28752875

2876-
char q[MAXQUERYLEN],
2877-
id1[MAXQUERYLEN],
2878-
id2[MAXQUERYLEN];
2876+
char q[MAX_QUERY_SIZE],
2877+
id1[MAX_QUERY_SIZE],
2878+
id2[MAX_QUERY_SIZE];
28792879
PGresult *res;
28802880

28812881
for (i = 0; i < numIndices; i++)
@@ -3213,7 +3213,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
32133213
char cycled,
32143214
called,
32153215
*t;
3216-
char query[MAXQUERYLEN];
3216+
char query[MAX_QUERY_SIZE];
32173217

32183218
sprintf(query,
32193219
"SELECT sequence_name, last_value, increment_by, max_value, "
@@ -3310,7 +3310,7 @@ dumpRules(FILE *fout, const char *tablename,
33103310
int nrules;
33113311
int i,
33123312
t;
3313-
char query[MAXQUERYLEN];
3313+
char query[MAX_QUERY_SIZE];
33143314

33153315
int i_definition;
33163316

src/bin/pg_dump/pg_dump.h

+2-7
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.38 1999/05/25 16:13:09 momjian Exp $
8+
* $Id: pg_dump.h,v 1.39 1999/05/26 21:51:11 tgl Exp $
99
*
1010
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1111
*
@@ -224,9 +224,4 @@ extern void dumpTables(FILE *fout, TableInfo *tbinfo, int numTables,
224224
const bool acls);
225225
extern void dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
226226
TableInfo *tbinfo, int numTables, const char *tablename);
227-
228-
extern const char *
229-
fmtId(const char *identifier, bool force_quotes);
230-
231-
/* largest query string size */
232-
#define MAXQUERYLEN 5000
227+
extern const char *fmtId(const char *identifier, bool force_quotes);

0 commit comments

Comments
 (0)