22
22
*
23
23
*
24
24
* IDENTIFICATION
25
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.268 2002/07/02 05:49:51 momjian Exp $
25
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.269 2002/07/04 03:04:54 momjian Exp $
26
26
*
27
27
*-------------------------------------------------------------------------
28
28
*/
@@ -104,14 +104,14 @@ static void dumpTableACL(Archive *fout, TableInfo *tbinfo);
104
104
static void dumpFuncACL (Archive * fout ,FuncInfo * finfo );
105
105
static void dumpAggACL (Archive * fout ,AggInfo * finfo );
106
106
static void dumpACL (Archive * fout ,const char * type ,const char * name ,
107
- const char * nspname ,const char * usename ,
108
- const char * acl ,const char * objoid );
107
+ const char * name_noquotes ,const char * nspname ,
108
+ const char * usename , const char * acl ,const char * objoid );
109
109
110
110
static void dumpTriggers (Archive * fout ,TableInfo * tblinfo ,int numTables );
111
111
static void dumpRules (Archive * fout ,TableInfo * tblinfo ,int numTables );
112
112
static void formatStringLiteral (PQExpBuffer buf ,const char * str ,
113
113
const formatLiteralOptions opts );
114
- static char * format_function_signature (FuncInfo * finfo );
114
+ static char * format_function_signature (FuncInfo * finfo , bool honor_quotes );
115
115
static void dumpOneFunc (Archive * fout ,FuncInfo * finfo );
116
116
static void dumpOneOpr (Archive * fout ,OprInfo * oprinfo ,
117
117
OprInfo * g_oprinfo ,int numOperators );
@@ -2721,7 +2721,7 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
2721
2721
if (strcmp (nspinfo -> nspname ,"public" )== 0 )
2722
2722
{
2723
2723
if (!aclsSkip && strcmp (nspinfo -> nspacl ,"{=UC}" )!= 0 )
2724
- dumpACL (fout ,"SCHEMA" ,qnspname ,NULL ,
2724
+ dumpACL (fout ,"SCHEMA" ,qnspname ,nspinfo -> nspname , NULL ,
2725
2725
nspinfo -> usename ,nspinfo -> nspacl ,
2726
2726
nspinfo -> oid );
2727
2727
}
@@ -2747,7 +2747,7 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
2747
2747
nspinfo -> oid ,"pg_namespace" ,0 ,NULL );
2748
2748
2749
2749
if (!aclsSkip )
2750
- dumpACL (fout ,"SCHEMA" ,qnspname ,NULL ,
2750
+ dumpACL (fout ,"SCHEMA" ,qnspname ,nspinfo -> nspname , NULL ,
2751
2751
nspinfo -> usename ,nspinfo -> nspacl ,
2752
2752
nspinfo -> oid );
2753
2753
}
@@ -3291,8 +3291,9 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs)
3291
3291
3292
3292
if (!aclsSkip )
3293
3293
{
3294
- char * tmp = strdup (fmtId (lanname ,force_quotes ));
3295
- dumpACL (fout ,"LANGUAGE" ,tmp ,finfo [fidx ].pronamespace -> nspname ,
3294
+ char * tmp = strdup (fmtId (lanname ,force_quotes ));
3295
+ dumpACL (fout ,"LANGUAGE" ,tmp ,lanname ,
3296
+ finfo [fidx ].pronamespace -> nspname ,
3296
3297
NULL ,lanacl ,lanoid );
3297
3298
free (tmp );
3298
3299
}
@@ -3333,13 +3334,16 @@ dumpFuncs(Archive *fout, FuncInfo finfo[], int numFuncs)
3333
3334
* is never qualified.
3334
3335
*/
3335
3336
static char *
3336
- format_function_signature (FuncInfo * finfo )
3337
+ format_function_signature (FuncInfo * finfo , bool honor_quotes )
3337
3338
{
3338
3339
PQExpBufferData fn ;
3339
3340
int j ;
3340
3341
3341
3342
initPQExpBuffer (& fn );
3342
- appendPQExpBuffer (& fn ,"%s (" ,fmtId (finfo -> proname ,force_quotes ));
3343
+ if (honor_quotes )
3344
+ appendPQExpBuffer (& fn ,"%s(" ,fmtId (finfo -> proname ,force_quotes ));
3345
+ else
3346
+ appendPQExpBuffer (& fn ,"%s(" ,finfo -> proname );
3343
3347
for (j = 0 ;j < finfo -> nargs ;j ++ )
3344
3348
{
3345
3349
char * typname ;
@@ -3358,12 +3362,15 @@ format_function_signature(FuncInfo *finfo)
3358
3362
static void
3359
3363
dumpFuncACL (Archive * fout ,FuncInfo * finfo )
3360
3364
{
3361
- char * funcsig ;
3365
+ char * funcsig , * funcsig_noquotes ;
3362
3366
3363
- funcsig = format_function_signature (finfo );
3364
- dumpACL (fout ,"FUNCTION" ,funcsig ,finfo -> pronamespace -> nspname ,
3367
+ funcsig = format_function_signature (finfo , true);
3368
+ funcsig_noquotes = format_function_signature (finfo , false);
3369
+ dumpACL (fout ,"FUNCTION" ,funcsig ,funcsig_noquotes ,
3370
+ finfo -> pronamespace -> nspname ,
3365
3371
finfo -> usename ,finfo -> proacl ,finfo -> oid );
3366
3372
free (funcsig );
3373
+ free (funcsig_noquotes );
3367
3374
}
3368
3375
3369
3376
@@ -3380,6 +3387,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
3380
3387
PQExpBuffer asPart = createPQExpBuffer ();
3381
3388
PGresult * res = NULL ;
3382
3389
char * funcsig = NULL ;
3390
+ char * funcsig_noquotes = NULL ;
3383
3391
int ntups ;
3384
3392
char * proretset ;
3385
3393
char * prosrc ;
@@ -3487,7 +3495,8 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
3487
3495
}
3488
3496
}
3489
3497
3490
- funcsig = format_function_signature (finfo );
3498
+ funcsig = format_function_signature (finfo , true);
3499
+ funcsig_noquotes = format_function_signature (finfo , false);
3491
3500
3492
3501
/* DROP must be fully qualified in case same name appears in pg_catalog */
3493
3502
appendPQExpBuffer (delqry ,"DROP FUNCTION %s.%s;\n" ,
@@ -3517,7 +3526,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
3517
3526
finfo -> proname );
3518
3527
exit_nicely ();
3519
3528
}
3520
- }
3529
+ }
3521
3530
3522
3531
if (proimplicit [0 ]== 't' )
3523
3532
appendPQExpBuffer (q ," IMPLICIT CAST" );
@@ -3530,7 +3539,8 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
3530
3539
3531
3540
appendPQExpBuffer (q ,";\n" );
3532
3541
3533
- ArchiveEntry (fout ,finfo -> oid ,funcsig ,finfo -> pronamespace -> nspname ,
3542
+ ArchiveEntry (fout ,finfo -> oid ,funcsig_noquotes ,
3543
+ finfo -> pronamespace -> nspname ,
3534
3544
finfo -> usename ,"FUNCTION" ,NULL ,
3535
3545
q -> data ,delqry -> data ,
3536
3546
NULL ,NULL ,NULL );
@@ -3551,6 +3561,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
3551
3561
destroyPQExpBuffer (delqry );
3552
3562
destroyPQExpBuffer (asPart );
3553
3563
free (funcsig );
3564
+ free (funcsig_noquotes );
3554
3565
}
3555
3566
3556
3567
/*
@@ -3939,14 +3950,17 @@ dumpAggs(Archive *fout, AggInfo agginfo[], int numAggs)
3939
3950
* is never qualified.
3940
3951
*/
3941
3952
static char *
3942
- format_aggregate_signature (AggInfo * agginfo ,Archive * fout )
3953
+ format_aggregate_signature (AggInfo * agginfo ,Archive * fout , bool honor_quotes )
3943
3954
{
3944
3955
PQExpBufferData buf ;
3945
3956
bool anybasetype ;
3946
3957
3947
3958
initPQExpBuffer (& buf );
3948
- appendPQExpBuffer (& buf ,"%s" ,
3959
+ if (honor_quotes )
3960
+ appendPQExpBuffer (& buf ,"%s" ,
3949
3961
fmtId (agginfo -> aggname ,force_quotes ));
3962
+ else
3963
+ appendPQExpBuffer (& buf ,"%s" ,agginfo -> aggname );
3950
3964
3951
3965
anybasetype = (strcmp (agginfo -> aggbasetype ,"0" )== 0 );
3952
3966
@@ -3974,12 +3988,15 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout)
3974
3988
static void
3975
3989
dumpAggACL (Archive * fout ,AggInfo * finfo )
3976
3990
{
3977
- char * aggsig ;
3991
+ char * aggsig , * aggsig_noquotes ;
3978
3992
3979
- aggsig = format_aggregate_signature (finfo ,fout );
3980
- dumpACL (fout ,"FUNCTION" ,aggsig ,finfo -> aggnamespace -> nspname ,
3993
+ aggsig = format_aggregate_signature (finfo ,fout , true);
3994
+ aggsig_noquotes = format_aggregate_signature (finfo ,fout , false);
3995
+ dumpACL (fout ,"FUNCTION" ,aggsig ,aggsig_noquotes ,
3996
+ finfo -> aggnamespace -> nspname ,
3981
3997
finfo -> usename ,finfo -> aggacl ,finfo -> oid );
3982
3998
free (aggsig );
3999
+ free (aggsig_noquotes );
3983
4000
}
3984
4001
3985
4002
@@ -3994,7 +4011,8 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
3994
4011
PQExpBuffer q = createPQExpBuffer ();
3995
4012
PQExpBuffer delq = createPQExpBuffer ();
3996
4013
PQExpBuffer details = createPQExpBuffer ();
3997
- char * aggSig ;
4014
+ char * aggsig ;
4015
+ char * aggsig_noquotes ;
3998
4016
PGresult * res ;
3999
4017
int ntups ;
4000
4018
int i_aggtransfn ;
@@ -4084,16 +4102,17 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
4084
4102
agginfo -> fmtbasetype = strdup (PQgetvalue (res ,0 ,i_fmtbasetype ));
4085
4103
convertok = (PQgetvalue (res ,0 ,i_convertok )[0 ]== 't' );
4086
4104
4087
- aggSig = format_aggregate_signature (agginfo ,g_fout );
4105
+ aggsig = format_aggregate_signature (agginfo ,g_fout , true);
4106
+ aggsig_noquotes = format_aggregate_signature (agginfo ,g_fout , false);
4088
4107
4089
4108
if (!convertok )
4090
4109
{
4091
4110
write_msg (NULL ,"WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n" ,
4092
- aggSig );
4111
+ aggsig );
4093
4112
4094
4113
appendPQExpBuffer (q ,"-- WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n" ,
4095
- aggSig );
4096
- ArchiveEntry (fout ,agginfo -> oid ,aggSig ,
4114
+ aggsig );
4115
+ ArchiveEntry (fout ,agginfo -> oid ,aggsig_noquotes ,
4097
4116
agginfo -> aggnamespace -> nspname ,agginfo -> usename ,
4098
4117
"WARNING" ,NULL ,
4099
4118
q -> data ,"" /* Del */ ,
@@ -4146,13 +4165,13 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
4146
4165
/* DROP must be fully qualified in case same name appears in pg_catalog */
4147
4166
appendPQExpBuffer (delq ,"DROP AGGREGATE %s.%s;\n" ,
4148
4167
fmtId (agginfo -> aggnamespace -> nspname ,force_quotes ),
4149
- aggSig );
4168
+ aggsig );
4150
4169
4151
4170
appendPQExpBuffer (q ,"CREATE AGGREGATE %s ( %s );\n" ,
4152
4171
fmtId (agginfo -> aggname ,force_quotes ),
4153
4172
details -> data );
4154
4173
4155
- ArchiveEntry (fout ,agginfo -> oid ,aggSig ,
4174
+ ArchiveEntry (fout ,agginfo -> oid ,aggsig_noquotes ,
4156
4175
agginfo -> aggnamespace -> nspname ,agginfo -> usename ,
4157
4176
"AGGREGATE" ,NULL ,
4158
4177
q -> data ,delq -> data ,
@@ -4161,7 +4180,7 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
4161
4180
/*** Dump Aggregate Comments ***/
4162
4181
4163
4182
resetPQExpBuffer (q );
4164
- appendPQExpBuffer (q ,"AGGREGATE %s" ,aggSig );
4183
+ appendPQExpBuffer (q ,"AGGREGATE %s" ,aggsig );
4165
4184
if (g_fout -> remoteVersion >=70300 )
4166
4185
dumpComment (fout ,q -> data ,
4167
4186
agginfo -> aggnamespace -> nspname ,agginfo -> usename ,
@@ -4177,7 +4196,8 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
4177
4196
destroyPQExpBuffer (q );
4178
4197
destroyPQExpBuffer (delq );
4179
4198
destroyPQExpBuffer (details );
4180
- free (aggSig );
4199
+ free (aggsig );
4200
+ free (aggsig_noquotes );
4181
4201
}
4182
4202
4183
4203
@@ -4276,7 +4296,7 @@ GetPrivileges(Archive *AH, const char *s, const char *type)
4276
4296
*/
4277
4297
static void
4278
4298
dumpACL (Archive * fout ,const char * type ,const char * name ,
4279
- const char * nspname ,const char * usename ,
4299
+ const char * name_noquotes , const char * nspname ,const char * usename ,
4280
4300
const char * acls ,const char * objoid )
4281
4301
{
4282
4302
char * aclbuf ,
@@ -4390,7 +4410,7 @@ dumpACL(Archive *fout, const char *type, const char *name,
4390
4410
appendPQExpBuffer (sql ,"%s;\n" ,fmtId (usename ,force_quotes ));
4391
4411
}
4392
4412
4393
- ArchiveEntry (fout ,objoid ,name ,nspname ,usename ?usename :"" ,
4413
+ ArchiveEntry (fout ,objoid ,name_noquotes ,nspname ,usename ?usename :"" ,
4394
4414
"ACL" ,NULL ,sql -> data ,"" ,NULL ,NULL ,NULL );
4395
4415
4396
4416
free (aclbuf );
@@ -4401,9 +4421,9 @@ dumpACL(Archive *fout, const char *type, const char *name,
4401
4421
static void
4402
4422
dumpTableACL (Archive * fout ,TableInfo * tbinfo )
4403
4423
{
4404
- char * tmp = strdup (fmtId (tbinfo -> relname ,force_quotes ) );
4405
- dumpACL (fout ,"TABLE" ,tmp ,tbinfo -> relnamespace -> nspname ,
4406
- tbinfo -> usename ,tbinfo -> relacl ,
4424
+ char * tmp = strdup (fmtId (tbinfo -> relname ,force_quotes ));
4425
+ dumpACL (fout ,"TABLE" ,tmp ,tbinfo -> relname ,
4426
+ tbinfo -> relnamespace -> nspname , tbinfo -> usename ,tbinfo -> relacl ,
4407
4427
tbinfo -> viewoid != NULL ?tbinfo -> viewoid :tbinfo -> oid );
4408
4428
free (tmp );
4409
4429
}
@@ -5793,20 +5813,17 @@ myFormatType(const char *typname, int32 typmod)
5793
5813
precision ,scale );
5794
5814
}
5795
5815
}
5796
-
5797
5816
/*
5798
5817
* char is an internal single-byte data type; Let's make sure we force
5799
5818
* it through with quotes. - thomas 1998-12-13
5800
5819
*/
5801
5820
else if (!strcmp (typname ,"char" ))
5802
5821
{
5803
- appendPQExpBuffer (buf ,"%s" ,
5804
- fmtId (typname , true));
5822
+ appendPQExpBuffer (buf ,"%s" ,fmtId (typname , true));
5805
5823
}
5806
5824
else
5807
5825
{
5808
- appendPQExpBuffer (buf ,"%s" ,
5809
- fmtId (typname , false));
5826
+ appendPQExpBuffer (buf ,"%s" ,fmtId (typname , false));
5810
5827
}
5811
5828
5812
5829
result = strdup (buf -> data );