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

Commit4cd086c

Browse files
committed
Fix quoting bugs and incorrect trigger argument printout.
1 parente1cce4d commit4cd086c

File tree

2 files changed

+77
-62
lines changed

2 files changed

+77
-62
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 29 additions & 18 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.37 2000/01/16 03:54:58 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.38 2000/01/18 07:29:58 tgl Exp $
1111
*
1212
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1313
*
@@ -39,8 +39,6 @@ static void flagInhAttrs(TableInfo *tbinfo, int numTables,
3939
InhInfo*inhinfo,intnumInherits);
4040
staticintstrInArray(constchar*pattern,char**arr,intarr_size);
4141

42-
PQExpBufferid_return;
43-
4442
/*
4543
* findTypeByOid
4644
* given an oid of a type, return its typename
@@ -65,7 +63,7 @@ findTypeByOid(TypeInfo *tinfo, int numTypes, const char *oid)
6563
}
6664

6765
/* should never get here */
68-
fprintf(stderr,"failed sanity check,type with oid %s was not found\n",
66+
fprintf(stderr,"failed sanity check, type with oid %s was not found\n",
6967
oid);
7068
exit(2);
7169
}
@@ -90,7 +88,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
9088
}
9189

9290
/* should never get here */
93-
fprintf(stderr,"failed sanity check,opr with oid %s was not found\n",
91+
fprintf(stderr,"failed sanity check, opr with oid %s was not found\n",
9492
oid);
9593
exit(2);
9694
}
@@ -505,27 +503,40 @@ findFuncByName(FuncInfo *finfo, int numFuncs, const char *name)
505503
constchar*
506504
fmtId(constchar*rawid,boolforce_quotes)
507505
{
506+
staticPQExpBufferid_return=NULL;
508507
constchar*cp;
508+
509+
if (!force_quotes)
510+
{
511+
if (!islower(*rawid))
512+
force_quotes= true;
513+
else
514+
for (cp=rawid;*cp;cp++)
515+
{
516+
if (! (islower(*cp)||isdigit(*cp)|| (*cp=='_')))
517+
{
518+
force_quotes= true;
519+
break;
520+
}
521+
}
522+
}
523+
524+
if (!force_quotes)
525+
returnrawid;/* no quoting needed */
509526

510527
if (id_return)
511528
resetPQExpBuffer(id_return);
512529
else
513530
id_return=createPQExpBuffer();
514-
515-
if (!force_quotes)
516-
for (cp=rawid;*cp!='\0';cp++)
517-
if (!(islower(*cp)||isdigit(*cp)|| (*cp=='_')))
518-
break;
519531

520-
if (force_quotes|| (*cp!='\0'))
532+
appendPQExpBufferChar(id_return,'\"');
533+
for (cp=rawid;*cp;cp++)
521534
{
522-
appendPQExpBuffer(id_return,"\"");
523-
appendPQExpBuffer(id_return,rawid);
524-
appendPQExpBuffer(id_return,"\"");
535+
if (*cp=='\"')
536+
appendPQExpBufferChar(id_return,'\\');
537+
appendPQExpBufferChar(id_return,*cp);
525538
}
526-
else
527-
appendPQExpBuffer(id_return,rawid);
539+
appendPQExpBufferChar(id_return,'\"');
528540

529-
cp=id_return->data;
530-
returncp;
541+
returnid_return->data;
531542
}/* fmtId() */

‎src/bin/pg_dump/pg_dump.c

Lines changed: 48 additions & 44 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.133 2000/01/1800:03:37 petere Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.134 2000/01/1807:29:58 tgl Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -643,7 +643,8 @@ main(int argc, char **argv)
643643
force_quotes= true;
644644
break;
645645
case'o':
646-
fprintf(stderr,"%s: The -o option for dumping oids is deprecated. Please use -O.");
646+
fprintf(stderr,"%s: The -o option for dumping oids is deprecated. Please use -O.\n",progname);
647+
/* FALLTHRU */
647648
case'O':/* Dump oids */
648649
oids= true;
649650
break;
@@ -1632,13 +1633,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16321633

16331634
resetPQExpBuffer(query);
16341635
if (name[0]!='$') {
1635-
appendPQExpBuffer(query,"CONSTRAINT ");
1636-
appendPQExpBuffer(query,fmtId(name,force_quotes));
1637-
appendPQExpBufferChar(query,' ');
1636+
appendPQExpBuffer(query,"CONSTRAINT %s ",
1637+
fmtId(name,force_quotes));
16381638
}
1639-
appendPQExpBuffer(query,"CHECK (");
1640-
appendPQExpBuffer(query,expr);
1641-
appendPQExpBuffer(query,")");
1639+
appendPQExpBuffer(query,"CHECK (%s)",expr);
16421640
tblinfo[i].check_expr[i2]=strdup(query->data);
16431641
}
16441642
PQclear(res2);
@@ -1647,11 +1645,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16471645
tblinfo[i].check_expr=NULL;
16481646

16491647
/* Get primary key */
1650-
if (strcmp(PQgetvalue(res,i,i_relhasindex),"t")==0)
1651-
{
1652-
PGresult*res2;
1653-
charstr[INDEX_MAX_KEYS*NAMEDATALEN+3]="";
1654-
intj;
1648+
if (strcmp(PQgetvalue(res,i,i_relhasindex),"t")==0)
1649+
{
1650+
PGresult*res2;
1651+
charstr[INDEX_MAX_KEYS*(NAMEDATALEN*2+4)+1];
1652+
intj;
16551653

16561654
resetPQExpBuffer(query);
16571655
appendPQExpBuffer(query,
@@ -1661,33 +1659,34 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16611659
" AND i.indexrelid = c.oid AND a.attnum > 0 AND a.attrelid = c.oid "
16621660
"ORDER BY a.attnum ",
16631661
tblinfo[i].oid);
1664-
res2=PQexec(g_conn,query->data);
1662+
res2=PQexec(g_conn,query->data);
16651663
if (!res2||PQresultStatus(res2)!=PGRES_TUPLES_OK)
16661664
{
16671665
fprintf(stderr,"getTables(): SELECT (for PRIMARY KEY) failed. Explanation from backend: %s",
16681666
PQerrorMessage(g_conn));
16691667
exit_nicely(g_conn);
16701668
}
16711669

1672-
for (j=0;j<PQntuples(res2);j++)
1673-
{
1674-
if (strlen(str)>0)
1675-
strcat(str,", ");
1676-
strcat(str,fmtId(PQgetvalue(res2,j,0),force_quotes));
1677-
}
1670+
str[0]='\0';
1671+
for (j=0;j<PQntuples(res2);j++)
1672+
{
1673+
if (strlen(str)>0)
1674+
strcat(str,", ");
1675+
strcat(str,fmtId(PQgetvalue(res2,j,0),force_quotes));
1676+
}
16781677

1679-
if (strlen(str)>0) {
1680-
tblinfo[i].primary_key=strdup(str);
1681-
if (tblinfo[i].primary_key==NULL) {
1682-
perror("strdup");
1683-
exit(1);
1678+
if (strlen(str)>0) {
1679+
tblinfo[i].primary_key=strdup(str);
1680+
if (tblinfo[i].primary_key==NULL) {
1681+
perror("strdup");
1682+
exit(1);
1683+
}
1684+
}
1685+
else
1686+
tblinfo[i].primary_key=NULL;
16841687
}
1685-
}
1686-
else
1687-
tblinfo[i].primary_key=NULL;
1688-
}
1689-
else
1690-
tblinfo[i].primary_key=NULL;
1688+
else
1689+
tblinfo[i].primary_key=NULL;
16911690

16921691
/* Get Triggers */
16931692
if (tblinfo[i].ntrig>0)
@@ -1740,7 +1739,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
17401739
inttgnargs=atoi(PQgetvalue(res2,i2,i_tgnargs));
17411740
constchar*tgargs=PQgetvalue(res2,i2,i_tgargs);
17421741
constchar*p;
1743-
PQExpBufferfarg=createPQExpBuffer();
17441742
intfindx;
17451743

17461744
for (findx=0;findx<numFuncs;findx++)
@@ -1763,9 +1761,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
17631761
if (dropSchema)
17641762
{
17651763
resetPQExpBuffer(query);
1766-
appendPQExpBuffer(query,"DROP TRIGGER %s ON %s;\n",
1767-
fmtId(PQgetvalue(res2,i2,i_tgname),force_quotes),
1768-
fmtId(tblinfo[i].relname,force_quotes));
1764+
appendPQExpBuffer(query,"DROP TRIGGER %s ",
1765+
fmtId(PQgetvalue(res2,i2,i_tgname),
1766+
force_quotes));
1767+
appendPQExpBuffer(query,"ON %s;\n",
1768+
fmtId(tblinfo[i].relname,force_quotes));
17691769
fputs(query->data,fout);
17701770
}
17711771
#endif
@@ -1800,8 +1800,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
18001800
else
18011801
appendPQExpBuffer(query," UPDATE");
18021802
}
1803-
appendPQExpBuffer(query," ON %s FOR EACH ROW EXECUTE PROCEDURE %s (",
1804-
fmtId(tblinfo[i].relname,force_quotes),tgfunc);
1803+
appendPQExpBuffer(query," ON %s FOR EACH ROW",
1804+
fmtId(tblinfo[i].relname,force_quotes));
1805+
appendPQExpBuffer(query," EXECUTE PROCEDURE %s (",
1806+
fmtId(tgfunc,force_quotes));
18051807
for (findx=0;findx<tgnargs;findx++)
18061808
{
18071809
constchar*s;
@@ -1827,15 +1829,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
18271829
break;
18281830
}
18291831
p--;
1832+
appendPQExpBufferChar(query,'\'');
18301833
for (s=tgargs;s<p;)
18311834
{
18321835
if (*s=='\'')
1833-
appendPQExpBufferChar(farg,'\\');
1834-
appendPQExpBufferChar(farg,*s++);
1836+
appendPQExpBufferChar(query,'\\');
1837+
appendPQExpBufferChar(query,*s++);
18351838
}
18361839
appendPQExpBufferChar(query,'\'');
1837-
appendPQExpBuffer(query,farg->data);
1838-
appendPQExpBufferChar(query,'\'');
18391840
appendPQExpBuffer(query, (findx<tgnargs-1) ?", " :"");
18401841
tgargs=p+4;
18411842
}
@@ -2476,9 +2477,12 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
24762477
if (dropSchema)
24772478
{
24782479
resetPQExpBuffer(q);
2479-
appendPQExpBuffer(q,"DROP OPERATOR %s (%s, %s);\n",oprinfo[i].oprname,
2480-
fmtId(findTypeByOid(tinfo,numTypes,oprinfo[i].oprleft), false),
2481-
fmtId(findTypeByOid(tinfo,numTypes,oprinfo[i].oprright), false));
2480+
appendPQExpBuffer(q,"DROP OPERATOR %s (%s",oprinfo[i].oprname,
2481+
fmtId(findTypeByOid(tinfo,numTypes,oprinfo[i].oprleft),
2482+
false));
2483+
appendPQExpBuffer(q,", %s);\n",
2484+
fmtId(findTypeByOid(tinfo,numTypes,oprinfo[i].oprright),
2485+
false));
24822486
fputs(q->data,fout);
24832487
}
24842488

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp