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

Commit8bf6182

Browse files
author
Thomas G. Lockhart
committed
Surround table and column names with double-quotes
in generated SQL code to preserve case (SQL92 syntax).
1 parente2ba4ee commit8bf6182

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 42 additions & 42 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.76 1998/06/20 02:49:38 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.77 1998/07/08 14:33:19 thomas Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -128,7 +128,7 @@ usage(const char *progname)
128128
fprintf(stderr,
129129
"\t -d \t\t dump data as proper insert strings\n");
130130
fprintf(stderr,
131-
"\t -D \t\t dump data as inserts with attribute names\n");
131+
"\t -D \t\t dump data as inserts with attribute names\n");
132132
fprintf(stderr,
133133
"\t -f filename \t\t script output filename\n");
134134
fprintf(stderr,
@@ -219,21 +219,21 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
219219

220220
if (oids)
221221
{
222-
fprintf(fout,"COPY%s WITH OIDS FROM stdin;\n",
222+
fprintf(fout,"COPY\"%s\" WITH OIDS FROM stdin;\n",
223223
fmtId(classname));
224-
sprintf(query,"COPY%s WITH OIDS TO stdout;\n",
224+
sprintf(query,"COPY\"%s\" WITH OIDS TO stdout;\n",
225225
fmtId(classname));
226226
}
227227
else
228228
{
229-
fprintf(fout,"COPY%s FROM stdin;\n",fmtId(classname));
230-
sprintf(query,"COPY%s TO stdout;\n",fmtId(classname));
229+
fprintf(fout,"COPY\"%s\" FROM stdin;\n",fmtId(classname));
230+
sprintf(query,"COPY\"%s\" TO stdout;\n",fmtId(classname));
231231
}
232232
res=PQexec(g_conn,query);
233233
if (!res||
234234
PQresultStatus(res)==PGRES_FATAL_ERROR)
235235
{
236-
fprintf(stderr,"SQL query to dump the contents of Table%s "
236+
fprintf(stderr,"SQL query to dump the contents of Table'%s' "
237237
"did not execute. Explanation from backend: '%s'.\n"
238238
"The query was: '%s'.\n",
239239
classname,PQerrorMessage(g_conn),query);
@@ -243,7 +243,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
243243
{
244244
if (PQresultStatus(res)!=PGRES_COPY_OUT)
245245
{
246-
fprintf(stderr,"SQL query to dump the contents of Table%s "
246+
fprintf(stderr,"SQL query to dump the contents of Table'%s' "
247247
"executed abnormally.\n"
248248
"PQexec() returned status %d when %d was expected.\n"
249249
"The query was: '%s'.\n",
@@ -284,7 +284,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
284284
ret=PQendcopy(res->conn);
285285
if (ret!=0)
286286
{
287-
fprintf(stderr,"SQL query to dump the contents of Table%s "
287+
fprintf(stderr,"SQL query to dump the contents of Table'%s' "
288288
"did not execute correctly. After we read all the "
289289
"table contents from the backend, PQendcopy() failed. "
290290
"Explanation from backend: '%s'.\n"
@@ -314,7 +314,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
314314
inttuple;
315315
intfield;
316316

317-
sprintf(query,"select *from %s",classname);
317+
sprintf(query,"SELECT *FROM \"%s\"",classname);
318318
res=PQexec(g_conn,query);
319319
if (!res||
320320
PQresultStatus(res)!=PGRES_TUPLES_OK)
@@ -325,7 +325,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
325325
tuple=0;
326326
while (tuple<PQntuples(res))
327327
{
328-
fprintf(fout,"insert into %s ",fmtId(classname));
328+
fprintf(fout,"INSERT INTO \"%s\" ",fmtId(classname));
329329
if (attrNames)
330330
{
331331
intj;
@@ -336,7 +336,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
336336
{
337337
if (tblinfo.inhAttrs[j]==0)
338338
{
339-
sprintf(q,"%s%s%s",
339+
sprintf(q,"%s%s\"%s\"",
340340
q,
341341
(actual_atts>0) ?"," :"",
342342
fmtId(tblinfo.attnames[j]));
@@ -433,7 +433,7 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
433433
if (!onlytable|| (!strcmp(tblinfo[i].relname,onlytable)))
434434
{
435435
if (g_verbose)
436-
fprintf(stderr,"%s dumping out schema of sequence%s %s\n",
436+
fprintf(stderr,"%s dumping out schema of sequence'%s' %s\n",
437437
g_comment_start,tblinfo[i].relname,g_comment_end);
438438
fprintf(fout,"\\connect - %s\n",tblinfo[i].usename);
439439
dumpSequence(fout,tblinfo[i]);
@@ -455,7 +455,7 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
455455
if (!onlytable|| (!strcmp(classname,onlytable)))
456456
{
457457
if (g_verbose)
458-
fprintf(stderr,"%s dumping out the contents of Table%s %s\n",
458+
fprintf(stderr,"%s dumping out the contents of Table'%s' %s\n",
459459
g_comment_start,classname,g_comment_end);
460460

461461
if (!dumpData)
@@ -1459,7 +1459,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14591459
inti2;
14601460

14611461
if (g_verbose)
1462-
fprintf(stderr,"%s finding CHECK constraints for relation:%s %s\n",
1462+
fprintf(stderr,"%s finding CHECK constraints for relation:'%s' %s\n",
14631463
g_comment_start,
14641464
tblinfo[i].relname,
14651465
g_comment_end);
@@ -1477,7 +1477,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14771477
ntups2=PQntuples(res2);
14781478
if (ntups2!=tblinfo[i].ncheck)
14791479
{
1480-
fprintf(stderr,"getTables(): relation%s: %d CHECKs were expected, but got %d\n",
1480+
fprintf(stderr,"getTables(): relation'%s': %d CHECKs were expected, but got %d\n",
14811481
tblinfo[i].relname,tblinfo[i].ncheck,ntups2);
14821482
exit_nicely(g_conn);
14831483
}
@@ -1513,7 +1513,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
15131513
inti2;
15141514

15151515
if (g_verbose)
1516-
fprintf(stderr,"%s finding Triggers for relation:%s %s\n",
1516+
fprintf(stderr,"%s finding Triggers for relation:'%s' %s\n",
15171517
g_comment_start,
15181518
tblinfo[i].relname,
15191519
g_comment_end);
@@ -1532,7 +1532,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
15321532
ntups2=PQntuples(res2);
15331533
if (ntups2!=tblinfo[i].ntrig)
15341534
{
1535-
fprintf(stderr,"getTables(): relation%s: %d Triggers were expected, but got %d\n",
1535+
fprintf(stderr,"getTables(): relation'%s': %d Triggers were expected, but got %d\n",
15361536
tblinfo[i].relname,tblinfo[i].ntrig,ntups2);
15371537
exit_nicely(g_conn);
15381538
}
@@ -1562,12 +1562,12 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
15621562
}
15631563
if (findx==numFuncs)
15641564
{
1565-
fprintf(stderr,"getTables(): relation%s: cannot find function with oid %s for trigger %s\n",
1565+
fprintf(stderr,"getTables(): relation'%s': cannot find function with oid %s for trigger %s\n",
15661566
tblinfo[i].relname,tgfunc,PQgetvalue(res2,i2,i_tgname));
15671567
exit_nicely(g_conn);
15681568
}
15691569
tgfunc=finfo[findx].proname;
1570-
sprintf(query,"CREATE TRIGGER%s ",PQgetvalue(res2,i2,i_tgname));
1570+
sprintf(query,"CREATE TRIGGER\"%s\" ",PQgetvalue(res2,i2,i_tgname));
15711571
/* Trigger type */
15721572
findx=0;
15731573
if (TRIGGER_FOR_BEFORE(tgtype))
@@ -1594,7 +1594,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
15941594
else
15951595
strcat(query," UPDATE");
15961596
}
1597-
sprintf(query,"%s ON%s FOR EACH ROW EXECUTE PROCEDURE %s (",
1597+
sprintf(query,"%s ON\"%s\" FOR EACH ROW EXECUTE PROCEDURE %s (",
15981598
query,tblinfo[i].relname,tgfunc);
15991599
for (findx=0;findx<tgnargs;findx++)
16001600
{
@@ -1606,7 +1606,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16061606
p=strchr(p,'\\');
16071607
if (p==NULL)
16081608
{
1609-
fprintf(stderr,"getTables(): relation%s: bad argument string (%s) for trigger%s\n",
1609+
fprintf(stderr,"getTables(): relation'%s': bad argument string (%s) for trigger'%s'\n",
16101610
tblinfo[i].relname,
16111611
PQgetvalue(res2,i2,i_tgargs),
16121612
PQgetvalue(res2,i2,i_tgname));
@@ -1750,7 +1750,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
17501750
* later
17511751
*/
17521752
if (g_verbose)
1753-
fprintf(stderr,"%s finding the attrs and types for table:%s %s\n",
1753+
fprintf(stderr,"%s finding the attrs and types for table:'%s' %s\n",
17541754
g_comment_start,
17551755
tblinfo[i].relname,
17561756
g_comment_end);
@@ -1799,7 +1799,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
17991799
PGresult*res2;
18001800

18011801
if (g_verbose)
1802-
fprintf(stderr,"%s finding DEFAULT expression for attr:%s %s\n",
1802+
fprintf(stderr,"%s finding DEFAULT expression for attr:'%s' %s\n",
18031803
g_comment_start,
18041804
tblinfo[i].attnames[j],
18051805
g_comment_end);
@@ -1964,7 +1964,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
19641964
fprintf(fout,"\\connect - %s\n",tinfo[i].usename);
19651965

19661966
sprintf(q,
1967-
"CREATE TYPE%s "
1967+
"CREATE TYPE\"%s\" "
19681968
"( internallength = %s, externallength = %s, input = %s, "
19691969
"output = %s, send = %s, receive = %s, default = '%s'",
19701970
tinfo[i].typname,
@@ -2030,13 +2030,13 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
20302030

20312031
fprintf(fout,"\\connect - %s\n",finfo[i].usename);
20322032

2033-
sprintf(q,"CREATE FUNCTION%s (",finfo[i].proname);
2033+
sprintf(q,"CREATE FUNCTION\"%s\" (",finfo[i].proname);
20342034
for (j=0;j<finfo[i].nargs;j++)
20352035
{
20362036
char*typname;
20372037

20382038
typname=findTypeByOid(tinfo,numTypes,finfo[i].argtypes[j]);
2039-
sprintf(q,"%s%s%s",
2039+
sprintf(q,"%s%s\"%s\"",
20402040
q,
20412041
(j>0) ?"," :"",
20422042
fmtId(typname));
@@ -2155,7 +2155,7 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
21552155
commutator,
21562156
negator,
21572157
restrictor,
2158-
(strcmp(oprinfo[i].oprcanhash,"t")) ?", HASHES" :"",
2158+
(strcmp(oprinfo[i].oprcanhash,"t")==0) ?", HASHES" :"",
21592159
join,
21602160
sortop);
21612161

@@ -2390,21 +2390,21 @@ dumpACL(FILE *fout, TableInfo tbinfo)
23902390
return;
23912391
else
23922392
{
2393-
fprintf(stderr,"Could not parse ACL list for%s...Exiting!\n",
2393+
fprintf(stderr,"Could not parse ACL list for'%s'...Exiting!\n",
23942394
tbinfo.relname);
23952395
exit_nicely(g_conn);
23962396
}
23972397

23982398
/* Revoke Default permissions for PUBLIC */
23992399
fprintf(fout,
2400-
"REVOKE ALL on%s from PUBLIC;\n",
2400+
"REVOKE ALL on'%s' from PUBLIC;\n",
24012401
tbinfo.relname);
24022402

24032403
for (k=0;k<l;k++)
24042404
{
24052405
if (ACLlist[k].privledges!= (char*)NULL)
24062406
fprintf(fout,
2407-
"GRANT %s on%s to%s;\n",
2407+
"GRANT %s on\"%s\" to\"%s\";\n",
24082408
ACLlist[k].privledges,tbinfo.relname,
24092409
ACLlist[k].user);
24102410
}
@@ -2461,7 +2461,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
24612461

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

2464-
sprintf(q,"CREATE TABLE%s (",fmtId(tblinfo[i].relname));
2464+
sprintf(q,"CREATE TABLE\"%s\" (",fmtId(tblinfo[i].relname));
24652465
actual_atts=0;
24662466
for (j=0;j<tblinfo[i].numatts;j++)
24672467
{
@@ -2471,7 +2471,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
24712471
/* Show lengths on bpchar and varchar */
24722472
if (!strcmp(tblinfo[i].typnames[j],"bpchar"))
24732473
{
2474-
sprintf(q,"%s%s%s char",
2474+
sprintf(q,"%s%s\"%s\" char",
24752475
q,
24762476
(actual_atts>0) ?", " :"",
24772477
fmtId(tblinfo[i].attnames[j]));
@@ -2483,7 +2483,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
24832483
}
24842484
elseif (!strcmp(tblinfo[i].typnames[j],"varchar"))
24852485
{
2486-
sprintf(q,"%s%s%s %s",
2486+
sprintf(q,"%s%s\"%s\" %s",
24872487
q,
24882488
(actual_atts>0) ?", " :"",
24892489
fmtId(tblinfo[i].attnames[j]),
@@ -2496,7 +2496,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
24962496
}
24972497
else
24982498
{
2499-
sprintf(q,"%s%s%s %s",
2499+
sprintf(q,"%s%s\"%s\" %s",
25002500
q,
25012501
(actual_atts>0) ?", " :"",
25022502
fmtId(tblinfo[i].attnames[j]),
@@ -2638,18 +2638,18 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
26382638
else
26392639
attname=tblinfo[tableInd].attnames[indkey];
26402640
if (funcname)
2641-
sprintf(attlist+strlen(attlist),"%s%s",
2641+
sprintf(attlist+strlen(attlist),"%s\"%s\"",
26422642
(k==0) ?"" :", ",fmtId(attname));
26432643
else
26442644
{
26452645
if (k >=nclass)
26462646
{
26472647
fprintf(stderr,"dumpIndices(): OpClass not found for "
2648-
"attribute%s of index%s\n",
2648+
"attribute'%s' of index'%s'\n",
26492649
attname,indinfo[i].indexrelname);
26502650
exit_nicely(g_conn);
26512651
}
2652-
sprintf(attlist+strlen(attlist),"%s%s %s",
2652+
sprintf(attlist+strlen(attlist),"%s\"%s\" \"%s\"",
26532653
(k==0) ?"" :", ",fmtId(attname),fmtId(classname[k]));
26542654
free(classname[k]);
26552655
}
@@ -2658,14 +2658,14 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
26582658
if (!tablename|| (!strcmp(indinfo[i].indrelname,tablename)))
26592659
{
26602660

2661-
sprintf(q,"CREATE %s INDEX%s on%s using %s (",
2661+
sprintf(q,"CREATE %s INDEX\"%s\" on\"%s\" using %s (",
26622662
(strcmp(indinfo[i].indisunique,"t")==0) ?"UNIQUE" :"",
26632663
fmtId(indinfo[i].indexrelname),
26642664
fmtId(indinfo[i].indrelname),
26652665
indinfo[i].indamname);
26662666
if (funcname)
26672667
{
2668-
sprintf(q,"%s %s (%s)%s );\n",
2668+
sprintf(q,"%s %s (%s)\"%s\" );\n",
26692669
q,funcname,attlist,fmtId(classname[0]));
26702670
free(funcname);
26712671
free(classname[0]);
@@ -2882,7 +2882,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
28822882

28832883
sprintf(query,
28842884
"SELECT sequence_name, last_value, increment_by, max_value, "
2885-
"min_value, cache_value, is_cycled, is_called from%s",
2885+
"min_value, cache_value, is_cycled, is_called from\"%s\"",
28862886
fmtId(tbinfo.relname));
28872887

28882888
res=PQexec(g_conn,query);
@@ -2921,7 +2921,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
29212921
PQclear(res);
29222922

29232923
sprintf(query,
2924-
"CREATE SEQUENCE%s start %d increment %d maxvalue %d "
2924+
"CREATE SEQUENCE\"%s\" start %d increment %d maxvalue %d "
29252925
"minvalue %d cache %d %s;\n",
29262926
fmtId(tbinfo.relname),last,incby,maxv,minv,cache,
29272927
(cycled=='t') ?"cycle" :"");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp