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

Commit8eb18d8

Browse files
committed
Fix pg_dump to use the same maximum-query-size constant as
the backend does. Remove unnecessary limitation on field size indumpClasses_dumpData (ie, -d or -D case).
1 parent26fb87d commit8eb18d8

File tree

3 files changed

+90
-95
lines changed

3 files changed

+90
-95
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 2 additions & 2 deletions
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(constchar*rawid,boolforce_quotes)
503503
{
504504
constchar*cp;
505-
staticcharid[MAXQUERYLEN];
505+
staticcharid[MAX_QUERY_SIZE];
506506

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

‎src/bin/pg_dump/pg_dump.c

Lines changed: 86 additions & 86 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.111 1999/05/2619:45:53 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.112 1999/05/2621: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
intntups;
191-
charquery[MAXQUERYLEN];
191+
charquery[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
constTableInfotblinfo,booloids)
320320
{
321321
PGresult*res;
322-
charq[MAXQUERYLEN];
322+
charq[MAX_QUERY_SIZE];
323323
inttuple;
324324
intfield;
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-
caseINT2OID:
363-
caseINT4OID:
364-
caseOIDOID:/* int types */
365-
caseFLOAT4OID:
366-
caseFLOAT8OID:/* 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+
caseINT2OID:
363+
caseINT4OID:
364+
caseOIDOID:/* int types */
365+
caseFLOAT4OID:
366+
caseFLOAT8OID:/* 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+
charch=*expsrc++;
383+
384+
if (ch=='\\'||ch=='\'')
382385
{
383-
charch=*expsrc;
384-
385-
if (ch=='\\'||ch=='\'')
386-
{
387-
*expdest++=ch;/* double it */
388-
*expdest++=ch;
389-
}
390-
elseif (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+
elseif (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
intntups;
768767
inti;
769-
charquery[MAXQUERYLEN];
768+
charquery[MAX_QUERY_SIZE];
770769
TypeInfo*tinfo;
771770

772771
inti_oid;
@@ -895,7 +894,7 @@ getOperators(int *numOprs)
895894
PGresult*res;
896895
intntups;
897896
inti;
898-
charquery[MAXQUERYLEN];
897+
charquery[MAX_QUERY_SIZE];
899898

900899
OprInfo*oprinfo;
901900

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

12441243
inti_oid;
@@ -1332,7 +1331,7 @@ getFuncs(int *numFuncs)
13321331
PGresult*res;
13331332
intntups;
13341333
inti;
1335-
charquery[MAXQUERYLEN];
1334+
charquery[MAX_QUERY_SIZE];
13361335
FuncInfo*finfo;
13371336

13381337
inti_oid;
@@ -1432,7 +1431,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14321431
PGresult*res;
14331432
intntups;
14341433
inti;
1435-
charquery[MAXQUERYLEN];
1434+
charquery[MAX_QUERY_SIZE];
14361435
TableInfo*tblinfo;
14371436

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

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

17841783
inti_inhrel;
@@ -1840,7 +1839,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
18401839
{
18411840
inti,
18421841
j;
1843-
charq[MAXQUERYLEN];
1842+
charq[MAX_QUERY_SIZE];
18441843
inti_attname;
18451844
inti_typname;
18461845
inti_atttypmod;
@@ -1951,7 +1950,7 @@ IndInfo *
19511950
getIndices(int*numIndices)
19521951
{
19531952
inti;
1954-
charquery[MAXQUERYLEN];
1953+
charquery[MAX_QUERY_SIZE];
19551954
PGresult*res;
19561955
intntups;
19571956
IndInfo*indinfo;
@@ -2042,7 +2041,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
20422041
TypeInfo*tinfo,intnumTypes)
20432042
{
20442043
inti;
2045-
charq[MAXQUERYLEN];
2044+
charq[MAX_QUERY_SIZE];
20462045
intfuncInd;
20472046

20482047
for (i=0;i<numTypes;i++)
@@ -2122,7 +2121,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
21222121
TypeInfo*tinfo,intnumTypes)
21232122
{
21242123
PGresult*res;
2125-
charquery[MAXQUERYLEN];
2124+
charquery[MAX_QUERY_SIZE];
21262125
intntups;
21272126
inti_lanname;
21282127
inti_lanpltrusted;
@@ -2224,7 +2223,7 @@ static void
22242223
dumpOneFunc(FILE*fout,FuncInfo*finfo,inti,
22252224
TypeInfo*tinfo,intnumTypes)
22262225
{
2227-
charq[MAXQUERYLEN];
2226+
charq[MAX_QUERY_SIZE];
22282227
intj;
22292228
char*func_def;
22302229
charfunc_lang[NAMEDATALEN+1];
@@ -2344,15 +2343,15 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
23442343
TypeInfo*tinfo,intnumTypes)
23452344
{
23462345
inti;
2347-
charq[MAXQUERYLEN];
2348-
charleftarg[MAXQUERYLEN];
2349-
charrightarg[MAXQUERYLEN];
2350-
charcommutator[MAXQUERYLEN];
2351-
charnegator[MAXQUERYLEN];
2352-
charrestrictor[MAXQUERYLEN];
2353-
charjoin[MAXQUERYLEN];
2354-
charsort1[MAXQUERYLEN];
2355-
charsort2[MAXQUERYLEN];
2346+
charq[MAX_QUERY_SIZE];
2347+
charleftarg[MAX_QUERY_SIZE/8];
2348+
charrightarg[MAX_QUERY_SIZE/8];
2349+
charcommutator[MAX_QUERY_SIZE/8];
2350+
charnegator[MAX_QUERY_SIZE/8];
2351+
charrestrictor[MAX_QUERY_SIZE/8];
2352+
charjoin[MAX_QUERY_SIZE/8];
2353+
charsort1[MAX_QUERY_SIZE/8];
2354+
charsort2[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,intnumTypes)
24612460
{
24622461
inti;
2463-
charq[MAXQUERYLEN];
2464-
charsfunc1[MAXQUERYLEN];
2465-
charsfunc2[MAXQUERYLEN];
2466-
charbasetype[MAXQUERYLEN];
2467-
charfinalfunc[MAXQUERYLEN];
2462+
charq[MAX_QUERY_SIZE];
2463+
charsfunc1[MAX_QUERY_SIZE];
2464+
charsfunc2[MAX_QUERY_SIZE];
2465+
charbasetype[MAX_QUERY_SIZE];
2466+
charfinalfunc[MAX_QUERY_SIZE];
24682467
charcomma1[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-
elsefprintf(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
inti,
26952695
j,
26962696
k;
2697-
charq[MAXQUERYLEN];
2697+
charq[MAX_QUERY_SIZE];
26982698
char*serialSeq=NULL;/* implicit sequence name created
26992699
* by SERIAL datatype */
27002700
constchar*serialSeqSuffix="_id_seq";/* suffix for implicit
@@ -2873,9 +2873,9 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
28732873
indclass;
28742874
intnclass;
28752875

2876-
charq[MAXQUERYLEN],
2877-
id1[MAXQUERYLEN],
2878-
id2[MAXQUERYLEN];
2876+
charq[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
charcycled,
32143214
called,
32153215
*t;
3216-
charquery[MAXQUERYLEN];
3216+
charquery[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
intnrules;
33113311
inti,
33123312
t;
3313-
charquery[MAXQUERYLEN];
3313+
charquery[MAX_QUERY_SIZE];
33143314

33153315
inti_definition;
33163316

‎src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 7 deletions
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
constboolacls);
225225
externvoiddumpIndices(FILE*fout,IndInfo*indinfo,intnumIndices,
226226
TableInfo*tbinfo,intnumTables,constchar*tablename);
227-
228-
externconstchar*
229-
fmtId(constchar*identifier,boolforce_quotes);
230-
231-
/* largest query string size */
232-
#defineMAXQUERYLEN 5000
227+
externconstchar*fmtId(constchar*identifier,boolforce_quotes);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp