21
21
*
22
22
*
23
23
* 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 $
25
25
*
26
26
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
27
27
*
@@ -128,7 +128,7 @@ usage(const char *progname)
128
128
fprintf (stderr ,
129
129
"\t -d \t\t dump data as proper insert strings\n" );
130
130
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" );
132
132
fprintf (stderr ,
133
133
"\t -f filename \t\t script output filename\n" );
134
134
fprintf (stderr ,
@@ -219,21 +219,21 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
219
219
220
220
if (oids )
221
221
{
222
- fprintf (fout , "COPY %s WITH OIDS FROM stdin;\n" ,
222
+ fprintf (fout , "COPY \"%s\" WITH OIDS FROM stdin;\n" ,
223
223
fmtId (classname ));
224
- sprintf (query , "COPY %s WITH OIDS TO stdout;\n" ,
224
+ sprintf (query , "COPY \"%s\" WITH OIDS TO stdout;\n" ,
225
225
fmtId (classname ));
226
226
}
227
227
else
228
228
{
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 ));
231
231
}
232
232
res = PQexec (g_conn , query );
233
233
if (!res ||
234
234
PQresultStatus (res ) == PGRES_FATAL_ERROR )
235
235
{
236
- fprintf (stderr , "SQL query to dump the contents of Table %s "
236
+ fprintf (stderr , "SQL query to dump the contents of Table '%s' "
237
237
"did not execute. Explanation from backend: '%s'.\n"
238
238
"The query was: '%s'.\n" ,
239
239
classname , PQerrorMessage (g_conn ), query );
@@ -243,7 +243,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
243
243
{
244
244
if (PQresultStatus (res ) != PGRES_COPY_OUT )
245
245
{
246
- fprintf (stderr , "SQL query to dump the contents of Table %s "
246
+ fprintf (stderr , "SQL query to dump the contents of Table '%s' "
247
247
"executed abnormally.\n"
248
248
"PQexec() returned status %d when %d was expected.\n"
249
249
"The query was: '%s'.\n" ,
@@ -284,7 +284,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
284
284
ret = PQendcopy (res -> conn );
285
285
if (ret != 0 )
286
286
{
287
- fprintf (stderr , "SQL query to dump the contents of Table %s "
287
+ fprintf (stderr , "SQL query to dump the contents of Table '%s' "
288
288
"did not execute correctly. After we read all the "
289
289
"table contents from the backend, PQendcopy() failed. "
290
290
"Explanation from backend: '%s'.\n"
@@ -314,7 +314,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
314
314
int tuple ;
315
315
int field ;
316
316
317
- sprintf (query , "select * from %s " , classname );
317
+ sprintf (query , "SELECT * FROM \"%s\" " , classname );
318
318
res = PQexec (g_conn , query );
319
319
if (!res ||
320
320
PQresultStatus (res ) != PGRES_TUPLES_OK )
@@ -325,7 +325,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
325
325
tuple = 0 ;
326
326
while (tuple < PQntuples (res ))
327
327
{
328
- fprintf (fout , "insert into %s " , fmtId (classname ));
328
+ fprintf (fout , "INSERT INTO \"%s\" " , fmtId (classname ));
329
329
if (attrNames )
330
330
{
331
331
int j ;
@@ -336,7 +336,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
336
336
{
337
337
if (tblinfo .inhAttrs [j ] == 0 )
338
338
{
339
- sprintf (q , "%s%s%s " ,
339
+ sprintf (q , "%s%s\"%s\" " ,
340
340
q ,
341
341
(actual_atts > 0 ) ? "," : "" ,
342
342
fmtId (tblinfo .attnames [j ]));
@@ -433,7 +433,7 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
433
433
if (!onlytable || (!strcmp (tblinfo [i ].relname , onlytable )))
434
434
{
435
435
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" ,
437
437
g_comment_start , tblinfo [i ].relname , g_comment_end );
438
438
fprintf (fout , "\\connect - %s\n" , tblinfo [i ].usename );
439
439
dumpSequence (fout , tblinfo [i ]);
@@ -455,7 +455,7 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
455
455
if (!onlytable || (!strcmp (classname , onlytable )))
456
456
{
457
457
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" ,
459
459
g_comment_start , classname , g_comment_end );
460
460
461
461
if (!dumpData )
@@ -1459,7 +1459,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1459
1459
int i2 ;
1460
1460
1461
1461
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" ,
1463
1463
g_comment_start ,
1464
1464
tblinfo [i ].relname ,
1465
1465
g_comment_end );
@@ -1477,7 +1477,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1477
1477
ntups2 = PQntuples (res2 );
1478
1478
if (ntups2 != tblinfo [i ].ncheck )
1479
1479
{
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" ,
1481
1481
tblinfo [i ].relname , tblinfo [i ].ncheck , ntups2 );
1482
1482
exit_nicely (g_conn );
1483
1483
}
@@ -1513,7 +1513,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1513
1513
int i2 ;
1514
1514
1515
1515
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" ,
1517
1517
g_comment_start ,
1518
1518
tblinfo [i ].relname ,
1519
1519
g_comment_end );
@@ -1532,7 +1532,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1532
1532
ntups2 = PQntuples (res2 );
1533
1533
if (ntups2 != tblinfo [i ].ntrig )
1534
1534
{
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" ,
1536
1536
tblinfo [i ].relname , tblinfo [i ].ntrig , ntups2 );
1537
1537
exit_nicely (g_conn );
1538
1538
}
@@ -1562,12 +1562,12 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1562
1562
}
1563
1563
if (findx == numFuncs )
1564
1564
{
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" ,
1566
1566
tblinfo [i ].relname , tgfunc , PQgetvalue (res2 , i2 , i_tgname ));
1567
1567
exit_nicely (g_conn );
1568
1568
}
1569
1569
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 ));
1571
1571
/* Trigger type */
1572
1572
findx = 0 ;
1573
1573
if (TRIGGER_FOR_BEFORE (tgtype ))
@@ -1594,7 +1594,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1594
1594
else
1595
1595
strcat (query , " UPDATE" );
1596
1596
}
1597
- sprintf (query , "%s ON %s FOR EACH ROW EXECUTE PROCEDURE %s (" ,
1597
+ sprintf (query , "%s ON \"%s\" FOR EACH ROW EXECUTE PROCEDURE %s (" ,
1598
1598
query , tblinfo [i ].relname , tgfunc );
1599
1599
for (findx = 0 ; findx < tgnargs ; findx ++ )
1600
1600
{
@@ -1606,7 +1606,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1606
1606
p = strchr (p , '\\' );
1607
1607
if (p == NULL )
1608
1608
{
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" ,
1610
1610
tblinfo [i ].relname ,
1611
1611
PQgetvalue (res2 , i2 , i_tgargs ),
1612
1612
PQgetvalue (res2 , i2 , i_tgname ));
@@ -1750,7 +1750,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
1750
1750
* later
1751
1751
*/
1752
1752
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" ,
1754
1754
g_comment_start ,
1755
1755
tblinfo [i ].relname ,
1756
1756
g_comment_end );
@@ -1799,7 +1799,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
1799
1799
PGresult * res2 ;
1800
1800
1801
1801
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" ,
1803
1803
g_comment_start ,
1804
1804
tblinfo [i ].attnames [j ],
1805
1805
g_comment_end );
@@ -1964,7 +1964,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
1964
1964
fprintf (fout , "\\connect - %s\n" , tinfo [i ].usename );
1965
1965
1966
1966
sprintf (q ,
1967
- "CREATE TYPE %s "
1967
+ "CREATE TYPE \"%s\" "
1968
1968
"( internallength = %s, externallength = %s, input = %s, "
1969
1969
"output = %s, send = %s, receive = %s, default = '%s'" ,
1970
1970
tinfo [i ].typname ,
@@ -2030,13 +2030,13 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
2030
2030
2031
2031
fprintf (fout , "\\connect - %s\n" , finfo [i ].usename );
2032
2032
2033
- sprintf (q , "CREATE FUNCTION %s (" , finfo [i ].proname );
2033
+ sprintf (q , "CREATE FUNCTION \"%s\" (" , finfo [i ].proname );
2034
2034
for (j = 0 ; j < finfo [i ].nargs ; j ++ )
2035
2035
{
2036
2036
char * typname ;
2037
2037
2038
2038
typname = findTypeByOid (tinfo , numTypes , finfo [i ].argtypes [j ]);
2039
- sprintf (q , "%s%s%s " ,
2039
+ sprintf (q , "%s%s\"%s\" " ,
2040
2040
q ,
2041
2041
(j > 0 ) ? "," : "" ,
2042
2042
fmtId (typname ));
@@ -2155,7 +2155,7 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
2155
2155
commutator ,
2156
2156
negator ,
2157
2157
restrictor ,
2158
- (strcmp (oprinfo [i ].oprcanhash , "t" )) ? ", HASHES" : "" ,
2158
+ (strcmp (oprinfo [i ].oprcanhash , "t" ) == 0 ) ? ", HASHES" : "" ,
2159
2159
join ,
2160
2160
sortop );
2161
2161
@@ -2390,21 +2390,21 @@ dumpACL(FILE *fout, TableInfo tbinfo)
2390
2390
return ;
2391
2391
else
2392
2392
{
2393
- fprintf (stderr , "Could not parse ACL list for %s ...Exiting!\n" ,
2393
+ fprintf (stderr , "Could not parse ACL list for '%s' ...Exiting!\n" ,
2394
2394
tbinfo .relname );
2395
2395
exit_nicely (g_conn );
2396
2396
}
2397
2397
2398
2398
/* Revoke Default permissions for PUBLIC */
2399
2399
fprintf (fout ,
2400
- "REVOKE ALL on %s from PUBLIC;\n" ,
2400
+ "REVOKE ALL on '%s' from PUBLIC;\n" ,
2401
2401
tbinfo .relname );
2402
2402
2403
2403
for (k = 0 ; k < l ; k ++ )
2404
2404
{
2405
2405
if (ACLlist [k ].privledges != (char * ) NULL )
2406
2406
fprintf (fout ,
2407
- "GRANT %s on %s to %s ;\n" ,
2407
+ "GRANT %s on \"%s\" to \"%s\" ;\n" ,
2408
2408
ACLlist [k ].privledges , tbinfo .relname ,
2409
2409
ACLlist [k ].user );
2410
2410
}
@@ -2461,7 +2461,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
2461
2461
2462
2462
fprintf (fout , "\\connect - %s\n" , tblinfo [i ].usename );
2463
2463
2464
- sprintf (q , "CREATE TABLE %s (" , fmtId (tblinfo [i ].relname ));
2464
+ sprintf (q , "CREATE TABLE \"%s\" (" , fmtId (tblinfo [i ].relname ));
2465
2465
actual_atts = 0 ;
2466
2466
for (j = 0 ; j < tblinfo [i ].numatts ; j ++ )
2467
2467
{
@@ -2471,7 +2471,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
2471
2471
/* Show lengths on bpchar and varchar */
2472
2472
if (!strcmp (tblinfo [i ].typnames [j ], "bpchar" ))
2473
2473
{
2474
- sprintf (q , "%s%s%s char" ,
2474
+ sprintf (q , "%s%s\"%s\" char" ,
2475
2475
q ,
2476
2476
(actual_atts > 0 ) ? ", " : "" ,
2477
2477
fmtId (tblinfo [i ].attnames [j ]));
@@ -2483,7 +2483,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
2483
2483
}
2484
2484
else if (!strcmp (tblinfo [i ].typnames [j ], "varchar" ))
2485
2485
{
2486
- sprintf (q , "%s%s%s %s" ,
2486
+ sprintf (q , "%s%s\"%s\" %s" ,
2487
2487
q ,
2488
2488
(actual_atts > 0 ) ? ", " : "" ,
2489
2489
fmtId (tblinfo [i ].attnames [j ]),
@@ -2496,7 +2496,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
2496
2496
}
2497
2497
else
2498
2498
{
2499
- sprintf (q , "%s%s%s %s" ,
2499
+ sprintf (q , "%s%s\"%s\" %s" ,
2500
2500
q ,
2501
2501
(actual_atts > 0 ) ? ", " : "" ,
2502
2502
fmtId (tblinfo [i ].attnames [j ]),
@@ -2638,18 +2638,18 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
2638
2638
else
2639
2639
attname = tblinfo [tableInd ].attnames [indkey ];
2640
2640
if (funcname )
2641
- sprintf (attlist + strlen (attlist ), "%s%s " ,
2641
+ sprintf (attlist + strlen (attlist ), "%s\"%s\" " ,
2642
2642
(k == 0 ) ? "" : ", " , fmtId (attname ));
2643
2643
else
2644
2644
{
2645
2645
if (k >= nclass )
2646
2646
{
2647
2647
fprintf (stderr , "dumpIndices(): OpClass not found for "
2648
- "attribute %s of index %s \n" ,
2648
+ "attribute '%s' of index '%s' \n" ,
2649
2649
attname , indinfo [i ].indexrelname );
2650
2650
exit_nicely (g_conn );
2651
2651
}
2652
- sprintf (attlist + strlen (attlist ), "%s%s %s " ,
2652
+ sprintf (attlist + strlen (attlist ), "%s\"%s\" \"%s\" " ,
2653
2653
(k == 0 ) ? "" : ", " , fmtId (attname ), fmtId (classname [k ]));
2654
2654
free (classname [k ]);
2655
2655
}
@@ -2658,14 +2658,14 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
2658
2658
if (!tablename || (!strcmp (indinfo [i ].indrelname , tablename )))
2659
2659
{
2660
2660
2661
- sprintf (q , "CREATE %s INDEX %s on %s using %s (" ,
2661
+ sprintf (q , "CREATE %s INDEX \"%s\" on \"%s\" using %s (" ,
2662
2662
(strcmp (indinfo [i ].indisunique , "t" ) == 0 ) ? "UNIQUE" : "" ,
2663
2663
fmtId (indinfo [i ].indexrelname ),
2664
2664
fmtId (indinfo [i ].indrelname ),
2665
2665
indinfo [i ].indamname );
2666
2666
if (funcname )
2667
2667
{
2668
- sprintf (q , "%s %s (%s) %s );\n" ,
2668
+ sprintf (q , "%s %s (%s) \"%s\" );\n" ,
2669
2669
q , funcname , attlist , fmtId (classname [0 ]));
2670
2670
free (funcname );
2671
2671
free (classname [0 ]);
@@ -2882,7 +2882,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
2882
2882
2883
2883
sprintf (query ,
2884
2884
"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\" " ,
2886
2886
fmtId (tbinfo .relname ));
2887
2887
2888
2888
res = PQexec (g_conn , query );
@@ -2921,7 +2921,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
2921
2921
PQclear (res );
2922
2922
2923
2923
sprintf (query ,
2924
- "CREATE SEQUENCE %s start %d increment %d maxvalue %d "
2924
+ "CREATE SEQUENCE \"%s\" start %d increment %d maxvalue %d "
2925
2925
"minvalue %d cache %d %s;\n" ,
2926
2926
fmtId (tbinfo .relname ), last , incby , maxv , minv , cache ,
2927
2927
(cycled == 't' ) ? "cycle" : "" );
0 commit comments