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

Commit0dd7381

Browse files
author
Thomas G. Lockhart
committed
Support SQL92 delimited identifiers by checking some attribute names
for mixed-case and surrounding with double quotes.
1 parentcc1b420 commit0dd7381

File tree

3 files changed

+59
-29
lines changed

3 files changed

+59
-29
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 28 additions & 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/common.c,v 1.17 1997/10/02 13:57:03 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.18 1997/10/30 16:47:57 thomas Exp $
1111
*
1212
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1313
*
@@ -22,6 +22,7 @@
2222
#include<stdlib.h>
2323
#include<stdio.h>
2424
#include<string.h>
25+
#include<ctype.h>
2526
#include<sys/param.h>/* for MAXHOSTNAMELEN on most */
2627
#ifdefsparc_solaris
2728
#include<netdb.h>/* for MAXHOSTNAMELEN on some */
@@ -478,3 +479,29 @@ isArchiveName(const char *relname)
478479
{
479480
return (strlen(relname)>1&&relname[1]==',');
480481
}
482+
483+
/*
484+
* fmtId
485+
*
486+
*checks input string for non-lowercase characters
487+
*returns pointer to input string or string surrounded by double quotes
488+
*/
489+
constchar*
490+
fmtId(constchar*rawid)
491+
{
492+
constchar*cp;
493+
staticcharid[MAXQUERYLEN];
494+
495+
for (cp=rawid;*cp!='\0';cp++)
496+
if (! (islower(*cp)||isdigit(*cp)|| (*cp=='_')))break;
497+
498+
if (*cp!='\0') {
499+
strcpy(id,"\"");
500+
strcat(id,rawid);
501+
strcat(id,"\"");
502+
cp=id;
503+
}else {
504+
cp=rawid;
505+
}
506+
return(cp);
507+
}/* fmtId() */

‎src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 27 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.51 1997/10/3003:59:46 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.52 1997/10/3016:47:59 thomas Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -205,14 +205,14 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
205205
if (oids)
206206
{
207207
fprintf(fout,"COPY %s WITH OIDS FROM stdin;\n",
208-
classname);
208+
fmtId(classname));
209209
sprintf(query,"COPY %s WITH OIDS TO stdout;\n",
210-
classname);
210+
fmtId(classname));
211211
}
212212
else
213213
{
214-
fprintf(fout,"COPY %s FROM stdin;\n",classname);
215-
sprintf(query,"COPY %s TO stdout;\n",classname);
214+
fprintf(fout,"COPY %s FROM stdin;\n",fmtId(classname));
215+
sprintf(query,"COPY %s TO stdout;\n",fmtId(classname));
216216
}
217217
res=PQexec(g_conn,query);
218218
if (!res)
@@ -309,7 +309,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
309309
tuple=0;
310310
while (tuple<PQntuples(res))
311311
{
312-
fprintf(fout,"insert into %s ",classname);
312+
fprintf(fout,"insert into %s ",fmtId(classname));
313313
if (attrNames)
314314
{
315315
intj;
@@ -323,7 +323,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
323323
sprintf(q,"%s%s%s",
324324
q,
325325
(actual_atts>0) ?"," :"",
326-
tblinfo.attnames[j]);
326+
fmtId(tblinfo.attnames[j]));
327327
actual_atts++;
328328
}
329329
}
@@ -1944,12 +1944,12 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
19441944
sprintf(q,"%s%s%s",
19451945
q,
19461946
(j>0) ?"," :"",
1947-
typname);
1947+
fmtId(typname));
19481948
}
19491949
sprintf(q,"%s ) RETURNS %s%s AS '%s' LANGUAGE '%s';\n",
19501950
q,
19511951
(finfo[i].retset) ?" SETOF " :"",
1952-
findTypeByOid(tinfo,numTypes,finfo[i].prorettype),
1952+
fmtId(findTypeByOid(tinfo,numTypes,finfo[i].prorettype)),
19531953
(finfo[i].lang==INTERNALlanguageId) ?finfo[i].prosrc :
19541954
(finfo[i].lang==ClanguageId) ?finfo[i].probin :
19551955
(finfo[i].lang==SQLlanguageId) ?finfo[i].prosrc :"unknown",
@@ -2005,13 +2005,13 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
20052005
strcmp(oprinfo[i].oprkind,"b")==0)
20062006
{
20072007
sprintf(leftarg,", LEFTARG = %s ",
2008-
findTypeByOid(tinfo,numTypes,oprinfo[i].oprleft));
2008+
fmtId(findTypeByOid(tinfo,numTypes,oprinfo[i].oprleft)));
20092009
}
20102010
if (strcmp(oprinfo[i].oprkind,"l")==0||
20112011
strcmp(oprinfo[i].oprkind,"b")==0)
20122012
{
20132013
sprintf(rightarg,", RIGHTARG = %s ",
2014-
findTypeByOid(tinfo,numTypes,oprinfo[i].oprright));
2014+
fmtId(findTypeByOid(tinfo,numTypes,oprinfo[i].oprright)));
20152015
}
20162016
if (strcmp(oprinfo[i].oprcom,"0")==0)
20172017
commutator[0]='\0';
@@ -2094,7 +2094,7 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
20942094

20952095
sprintf(basetype,
20962096
"BASETYPE = %s, ",
2097-
findTypeByOid(tinfo,numTypes,agginfo[i].aggbasetype));
2097+
fmtId(findTypeByOid(tinfo,numTypes,agginfo[i].aggbasetype)));
20982098

20992099
if (strcmp(agginfo[i].aggtransfn1,"-")==0)
21002100
sfunc1[0]='\0';
@@ -2103,7 +2103,7 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
21032103
sprintf(sfunc1,
21042104
"SFUNC1 = %s, STYPE1 = %s",
21052105
agginfo[i].aggtransfn1,
2106-
findTypeByOid(tinfo,numTypes,agginfo[i].aggtranstype1));
2106+
fmtId(findTypeByOid(tinfo,numTypes,agginfo[i].aggtranstype1)));
21072107
if (agginfo[i].agginitval1)
21082108
sprintf(sfunc1,"%s, INITCOND1 = '%s'",
21092109
sfunc1,agginfo[i].agginitval1);
@@ -2117,7 +2117,7 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
21172117
sprintf(sfunc2,
21182118
"SFUNC2 = %s, STYPE2 = %s",
21192119
agginfo[i].aggtransfn2,
2120-
findTypeByOid(tinfo,numTypes,agginfo[i].aggtranstype2));
2120+
fmtId(findTypeByOid(tinfo,numTypes,agginfo[i].aggtranstype2)));
21212121
if (agginfo[i].agginitval2)
21222122
sprintf(sfunc2,"%s, INITCOND2 = '%s'",
21232123
sfunc2,agginfo[i].agginitval2);
@@ -2213,7 +2213,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
22132213

22142214
fprintf(fout,"\\connect - %s\n",tblinfo[i].usename);
22152215

2216-
sprintf(q,"CREATE TABLE %s (",tblinfo[i].relname);
2216+
sprintf(q,"CREATE TABLE %s (",fmtId(tblinfo[i].relname));
22172217
actual_atts=0;
22182218
for (j=0;j<tblinfo[i].numatts;j++)
22192219
{
@@ -2226,7 +2226,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
22262226
sprintf(q,"%s%s%s char",
22272227
q,
22282228
(actual_atts>0) ?", " :"",
2229-
tblinfo[i].attnames[j]);
2229+
fmtId(tblinfo[i].attnames[j]));
22302230

22312231
/* stored length can be -1 (variable) */
22322232
if (tblinfo[i].attlen[j]>0)
@@ -2240,7 +2240,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
22402240
sprintf(q,"%s%s%s %s",
22412241
q,
22422242
(actual_atts>0) ?", " :"",
2243-
tblinfo[i].attnames[j],
2243+
fmtId(tblinfo[i].attnames[j]),
22442244
tblinfo[i].typnames[j]);
22452245

22462246
/* stored length can be -1 (variable) */
@@ -2255,8 +2255,8 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
22552255
sprintf(q,"%s%s%s %s",
22562256
q,
22572257
(actual_atts>0) ?", " :"",
2258-
tblinfo[i].attnames[j],
2259-
tblinfo[i].typnames[j]);
2258+
fmtId(tblinfo[i].attnames[j]),
2259+
fmtId(tblinfo[i].typnames[j]));
22602260
actual_atts++;
22612261
}
22622262
if (tblinfo[i].adef_expr[j]!=NULL)
@@ -2347,7 +2347,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
23472347
for (i=0;i<numIndices;i++)
23482348
{
23492349
tableInd=findTableByName(tblinfo,numTables,
2350-
indinfo[i].indrelname);
2350+
fmtId(indinfo[i].indrelname));
23512351

23522352
if (strcmp(indinfo[i].indproc,"0")==0)
23532353
{
@@ -2420,7 +2420,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
24202420
attname=tblinfo[tableInd].attnames[indkey];
24212421
if (funcname)
24222422
sprintf(attlist+strlen(attlist),"%s%s",
2423-
(k==0) ?"" :", ",attname);
2423+
(k==0) ?"" :", ",fmtId(attname));
24242424
else
24252425
{
24262426
if (k >=nclass)
@@ -2431,7 +2431,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
24312431
exit_nicely(g_conn);
24322432
}
24332433
sprintf(attlist+strlen(attlist),"%s%s %s",
2434-
(k==0) ?"" :", ",attname,classname[k]);
2434+
(k==0) ?"" :", ",fmtId(attname),fmtId(classname[k]));
24352435
free(classname[k]);
24362436
}
24372437
}
@@ -2441,13 +2441,13 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
24412441

24422442
sprintf(q,"CREATE %s INDEX %s on %s using %s (",
24432443
(strcmp(indinfo[i].indisunique,"t")==0) ?"UNIQUE" :"",
2444-
indinfo[i].indexrelname,
2445-
indinfo[i].indrelname,
2444+
fmtId(indinfo[i].indexrelname),
2445+
fmtId(indinfo[i].indrelname),
24462446
indinfo[i].indamname);
24472447
if (funcname)
24482448
{
24492449
sprintf(q,"%s %s (%s) %s );\n",
2450-
q,funcname,attlist,classname[0]);
2450+
q,funcname,attlist,fmtId(classname[0]));
24512451
free(funcname);
24522452
free(classname[0]);
24532453
}
@@ -2666,7 +2666,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
26662666
sprintf(query,
26672667
"SELECT sequence_name, last_value, increment_by, max_value, "
26682668
"min_value, cache_value, is_cycled, is_called from %s",
2669-
tbinfo.relname);
2669+
fmtId(tbinfo.relname));
26702670

26712671
res=PQexec(g_conn,query);
26722672
if (!res||PQresultStatus(res)!=PGRES_TUPLES_OK)
@@ -2706,7 +2706,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
27062706
sprintf(query,
27072707
"CREATE SEQUENCE %s start %d increment %d maxvalue %d "
27082708
"minvalue %d cache %d %s;\n",
2709-
tbinfo.relname,last,incby,maxv,minv,cache,
2709+
fmtId(tbinfo.relname),last,incby,maxv,minv,cache,
27102710
(cycled=='t') ?"cycle" :"");
27112711

27122712
fputs(query,fout);

‎src/bin/pg_dump/pg_dump.h

Lines changed: 4 additions & 1 deletion
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.25 1997/10/02 13:57:07 vadim Exp $
8+
* $Id: pg_dump.h,v 1.26 1997/10/30 16:48:03 thomas Exp $
99
*
1010
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1111
*
@@ -233,5 +233,8 @@ extern void
233233
dumpIndices(FILE*fout,IndInfo*indinfo,intnumIndices,
234234
TableInfo*tbinfo,intnumTables,constchar*tablename);
235235

236+
externconstchar*
237+
fmtId(constchar*identifier);
238+
236239
/* largest query string size */
237240
#defineMAXQUERYLEN 5000

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp