22
22
*
23
23
*
24
24
* IDENTIFICATION
25
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.205.2.3 2001/07/29 22:12:49 tgl Exp $
25
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.205.2.4 2001/08/03 20:14:06 tgl Exp $
26
26
*
27
27
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
28
28
*
@@ -180,7 +180,8 @@ typedef enum _formatLiteralOptions
180
180
/* only checks for 'opts == CONV_ALL' anyway. */
181
181
} formatLiteralOptions ;
182
182
183
- static void dumpComment (Archive * outfile , const char * target , const char * oid );
183
+ static void dumpComment (Archive * outfile , const char * target , const char * oid ,
184
+ const char * ((* deps )[]));
184
185
static void dumpSequence (Archive * fout , TableInfo tbinfo , const bool schemaOnly , const bool dataOnly );
185
186
static void dumpACL (Archive * fout , TableInfo tbinfo );
186
187
static void dumpTriggers (Archive * fout , const char * tablename ,
@@ -1329,7 +1330,10 @@ getTypes(int *numTypes)
1329
1330
int i_typdelim ;
1330
1331
int i_typdefault ;
1331
1332
int i_typrelid ;
1333
+ int i_typalign ;
1334
+ int i_typstorage ;
1332
1335
int i_typbyval ;
1336
+ int i_typisdefined ;
1333
1337
int i_usename ;
1334
1338
int i_typedefn ;
1335
1339
@@ -1348,14 +1352,14 @@ getTypes(int *numTypes)
1348
1352
{
1349
1353
appendPQExpBuffer (query , "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, "
1350
1354
"typinput, typoutput, typreceive, typsend, typelem, typdelim, "
1351
- "typdefault, typrelid, typbyval, "
1355
+ "typdefault, typrelid, typalign, 'p'::char as typstorage, typbyval, typisdefined , "
1352
1356
"(select usename from pg_user where typowner = usesysid) as usename, "
1353
1357
"typname as typedefn "
1354
1358
"from pg_type" );
1355
1359
} else {
1356
1360
appendPQExpBuffer (query , "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, "
1357
1361
"typinput, typoutput, typreceive, typsend, typelem, typdelim, "
1358
- "typdefault, typrelid, typbyval, "
1362
+ "typdefault, typrelid, typalign, typstorage, typbyval, typisdefined , "
1359
1363
"(select usename from pg_user where typowner = usesysid) as usename, "
1360
1364
"format_type(pg_type.oid, NULL) as typedefn "
1361
1365
"from pg_type" );
@@ -1386,7 +1390,10 @@ getTypes(int *numTypes)
1386
1390
i_typdelim = PQfnumber (res , "typdelim" );
1387
1391
i_typdefault = PQfnumber (res , "typdefault" );
1388
1392
i_typrelid = PQfnumber (res , "typrelid" );
1393
+ i_typalign = PQfnumber (res , "typalign" );
1394
+ i_typstorage = PQfnumber (res , "typstorage" );
1389
1395
i_typbyval = PQfnumber (res , "typbyval" );
1396
+ i_typisdefined = PQfnumber (res , "typisdefined" );
1390
1397
i_usename = PQfnumber (res , "usename" );
1391
1398
i_typedefn = PQfnumber (res , "typedefn" );
1392
1399
@@ -1405,6 +1412,8 @@ getTypes(int *numTypes)
1405
1412
tinfo [i ].typdelim = strdup (PQgetvalue (res , i , i_typdelim ));
1406
1413
tinfo [i ].typdefault = strdup (PQgetvalue (res , i , i_typdefault ));
1407
1414
tinfo [i ].typrelid = strdup (PQgetvalue (res , i , i_typrelid ));
1415
+ tinfo [i ].typalign = strdup (PQgetvalue (res , i , i_typalign ));
1416
+ tinfo [i ].typstorage = strdup (PQgetvalue (res , i , i_typstorage ));
1408
1417
tinfo [i ].usename = strdup (PQgetvalue (res , i , i_usename ));
1409
1418
tinfo [i ].typedefn = strdup (PQgetvalue (res , i , i_typedefn ));
1410
1419
@@ -1424,12 +1433,19 @@ getTypes(int *numTypes)
1424
1433
tinfo [i ].isArray = 1 ;
1425
1434
else
1426
1435
tinfo [i ].isArray = 0 ;
1436
+
1437
+ if (strcmp (PQgetvalue (res , i , i_typisdefined ), "f" ) == 0 )
1438
+ tinfo [i ].isDefined = 0 ;
1439
+ else
1440
+ tinfo [i ].isDefined = 1 ;
1427
1441
}
1428
1442
1429
1443
* numTypes = ntups ;
1430
1444
1431
1445
PQclear (res );
1432
1446
1447
+ destroyPQExpBuffer (query );
1448
+
1433
1449
return tinfo ;
1434
1450
}
1435
1451
@@ -1567,8 +1583,14 @@ clearTypeInfo(TypeInfo *tp, int numTypes)
1567
1583
free (tp [i ].typdefault );
1568
1584
if (tp [i ].typrelid )
1569
1585
free (tp [i ].typrelid );
1586
+ if (tp [i ].typalign )
1587
+ free (tp [i ].typalign );
1588
+ if (tp [i ].typstorage )
1589
+ free (tp [i ].typstorage );
1570
1590
if (tp [i ].usename )
1571
1591
free (tp [i ].usename );
1592
+ if (tp [i ].typedefn )
1593
+ free (tp [i ].typedefn );
1572
1594
}
1573
1595
free (tp );
1574
1596
}
@@ -2989,16 +3011,17 @@ getIndices(int *numIndices)
2989
3011
* oid handed to this routine. The routine takes a constant character
2990
3012
* string for the target part of the object and the oid of the object
2991
3013
* whose comments are to be dumped. It is perfectly acceptable
2992
- * to hand an oid to this routine which has not been commented. In
2993
- * addition, the routine takes the stdio FILE handle to which the
2994
- * output should be written.
3014
+ * to hand an oid to this routine which has not been commented. Additional
3015
+ * dependencies can be passed for the comment, too --- this is needed for
3016
+ * VIEWs, whose comments are filed under the table OID but which are dumped
3017
+ * in order by their rule OID.
2995
3018
*------------------------------------------------------------------
2996
3019
*/
2997
3020
2998
3021
static void
2999
- dumpComment (Archive * fout , const char * target , const char * oid )
3022
+ dumpComment (Archive * fout , const char * target , const char * oid ,
3023
+ const char * ((* deps )[]))
3000
3024
{
3001
-
3002
3025
PGresult * res ;
3003
3026
PQExpBuffer query ;
3004
3027
int i_description ;
@@ -3033,7 +3056,8 @@ dumpComment(Archive *fout, const char *target, const char *oid)
3033
3056
formatStringLiteral (query , PQgetvalue (res , 0 , i_description ), PASS_LFTAB );
3034
3057
appendPQExpBuffer (query , ";\n" );
3035
3058
3036
- ArchiveEntry (fout , oid , target , "COMMENT" , NULL , query -> data , "" /* Del */ ,
3059
+ ArchiveEntry (fout , oid , target , "COMMENT" , deps ,
3060
+ query -> data , "" /* Del */ ,
3037
3061
"" /* Copy */ , "" /* Owner */ , NULL , NULL );
3038
3062
3039
3063
}
@@ -3085,13 +3109,13 @@ dumpDBComment(Archive *fout)
3085
3109
i_oid = PQfnumber (res , "oid" );
3086
3110
resetPQExpBuffer (query );
3087
3111
appendPQExpBuffer (query , "DATABASE %s" , fmtId (PQdb (g_conn ), force_quotes ));
3088
- dumpComment (fout , query -> data , PQgetvalue (res , 0 , i_oid ));
3112
+ dumpComment (fout , query -> data , PQgetvalue (res , 0 , i_oid ), NULL );
3089
3113
}
3090
3114
3091
3115
/*** Clear the statement buffer and return ***/
3092
3116
3093
3117
PQclear (res );
3094
-
3118
+ destroyPQExpBuffer ( query );
3095
3119
}
3096
3120
3097
3121
/*
@@ -3108,13 +3132,10 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
3108
3132
PQExpBuffer delq = createPQExpBuffer ();
3109
3133
int funcInd ;
3110
3134
const char * ((* deps )[]);
3111
- int depIdx = 0 ;
3112
-
3113
- deps = malloc (sizeof (char * ) * 10 );
3135
+ int depIdx ;
3114
3136
3115
3137
for (i = 0 ; i < numTypes ; i ++ )
3116
3138
{
3117
-
3118
3139
/* skip all the builtin types */
3119
3140
if (atooid (tinfo [i ].oid ) <= g_last_builtin_oid )
3120
3141
continue ;
@@ -3123,11 +3144,18 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
3123
3144
if (atoi (tinfo [i ].typrelid ) != 0 )
3124
3145
continue ;
3125
3146
3147
+ /* skip undefined placeholder types */
3148
+ if (!tinfo [i ].isDefined )
3149
+ continue ;
3150
+
3126
3151
/* skip all array types that start w/ underscore */
3127
3152
if ((tinfo [i ].typname [0 ] == '_' ) &&
3128
3153
(strcmp (tinfo [i ].typinput , "array_in" ) == 0 ))
3129
3154
continue ;
3130
3155
3156
+ deps = malloc (sizeof (char * ) * 10 );
3157
+ depIdx = 0 ;
3158
+
3131
3159
/*
3132
3160
* before we create a type, we need to create the input and output
3133
3161
* functions for it, if they haven't been created already
@@ -3146,6 +3174,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
3146
3174
dumpOneFunc (fout , finfo , funcInd , tinfo , numTypes );
3147
3175
}
3148
3176
3177
+ resetPQExpBuffer (delq );
3149
3178
appendPQExpBuffer (delq , "DROP TYPE %s;\n" , fmtId (tinfo [i ].typname , force_quotes ));
3150
3179
3151
3180
resetPQExpBuffer (q );
@@ -3175,8 +3204,6 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
3175
3204
{
3176
3205
fprintf (stderr , "Notice: array type %s - type for elements (oid %s) is not dumped.\n" ,
3177
3206
tinfo [i ].typname , tinfo [i ].typelem );
3178
- resetPQExpBuffer (q );
3179
- resetPQExpBuffer (delq );
3180
3207
continue ;
3181
3208
}
3182
3209
@@ -3185,8 +3212,24 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
3185
3212
3186
3213
(* deps )[depIdx ++ ] = strdup (tinfo [i ].typelem );
3187
3214
}
3215
+
3216
+ /* XXX these are all the aligns currently handled by DefineType */
3217
+ if (strcmp (tinfo [i ].typalign , "i" ) == 0 )
3218
+ appendPQExpBuffer (q , ", alignment = int4" );
3219
+ else if (strcmp (tinfo [i ].typalign , "d" ) == 0 )
3220
+ appendPQExpBuffer (q , ", alignment = double" );
3221
+
3222
+ if (strcmp (tinfo [i ].typstorage , "p" ) == 0 )
3223
+ appendPQExpBuffer (q , ", storage = plain" );
3224
+ if (strcmp (tinfo [i ].typstorage , "e" ) == 0 )
3225
+ appendPQExpBuffer (q , ", storage = external" );
3226
+ if (strcmp (tinfo [i ].typstorage , "x" ) == 0 )
3227
+ appendPQExpBuffer (q , ", storage = extended" );
3228
+ if (strcmp (tinfo [i ].typstorage , "m" ) == 0 )
3229
+ appendPQExpBuffer (q , ", storage = main" );
3230
+
3188
3231
if (tinfo [i ].passedbyvalue )
3189
- appendPQExpBuffer (q , ",passedbyvalue);\n" );
3232
+ appendPQExpBuffer (q , ", passedbyvalue);\n" );
3190
3233
else
3191
3234
appendPQExpBuffer (q , ");\n" );
3192
3235
@@ -3201,7 +3244,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
3201
3244
resetPQExpBuffer (delq );
3202
3245
3203
3246
appendPQExpBuffer (q , "TYPE %s" , fmtId (tinfo [i ].typname , force_quotes ));
3204
- dumpComment (fout , q -> data , tinfo [i ].oid );
3247
+ dumpComment (fout , q -> data , tinfo [i ].oid , NULL );
3205
3248
3206
3249
resetPQExpBuffer (q );
3207
3250
}
@@ -3486,7 +3529,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
3486
3529
appendPQExpBuffer (q , "FUNCTION %s " ,
3487
3530
fmtId (finfo [i ].proname , force_quotes ));
3488
3531
appendPQExpBuffer (q , "( %s )" , fnlist -> data );
3489
- dumpComment (fout , q -> data , finfo [i ].oid );
3532
+ dumpComment (fout , q -> data , finfo [i ].oid , NULL );
3490
3533
3491
3534
}
3492
3535
@@ -3743,7 +3786,7 @@ dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs,
3743
3786
resetPQExpBuffer (q );
3744
3787
appendPQExpBuffer (q , "AGGREGATE %s %s" , agginfo [i ].aggname ,
3745
3788
findTypeByOid (tinfo , numTypes , agginfo [i ].aggbasetype , zeroAsOpaque + useBaseTypeName ));
3746
- dumpComment (fout , q -> data , agginfo [i ].oid );
3789
+ dumpComment (fout , q -> data , agginfo [i ].oid , NULL );
3747
3790
3748
3791
}
3749
3792
}
@@ -4001,6 +4044,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
4001
4044
int actual_atts ; /* number of attrs in this CREATE statment */
4002
4045
char * reltypename ;
4003
4046
char * objoid ;
4047
+ const char * ((* commentDeps )[]);
4004
4048
4005
4049
/* First - dump SEQUENCEs */
4006
4050
if (tablename && strlen (tablename ) > 0 )
@@ -4043,12 +4087,15 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
4043
4087
objoid = tblinfo [i ].viewoid ;
4044
4088
appendPQExpBuffer (delq , "DROP VIEW %s;\n" , fmtId (tblinfo [i ].relname , force_quotes ));
4045
4089
appendPQExpBuffer (q , "CREATE VIEW %s as %s\n" , fmtId (tblinfo [i ].relname , force_quotes ), tblinfo [i ].viewdef );
4046
-
4090
+ commentDeps = malloc (sizeof (char * ) * 2 );
4091
+ (* commentDeps )[0 ] = strdup (objoid );
4092
+ (* commentDeps )[1 ] = NULL ; /* end of list */
4047
4093
}
4048
4094
else
4049
4095
{
4050
4096
reltypename = "TABLE" ;
4051
4097
objoid = tblinfo [i ].oid ;
4098
+ commentDeps = NULL ;
4052
4099
parentRels = tblinfo [i ].parentRels ;
4053
4100
numParents = tblinfo [i ].numParents ;
4054
4101
@@ -4167,17 +4214,20 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
4167
4214
appendPQExpBuffer (q , "COLUMN %s" , fmtId (tblinfo [i ].relname , force_quotes ));
4168
4215
appendPQExpBuffer (q , "." );
4169
4216
appendPQExpBuffer (q , "%s" , fmtId (tblinfo [i ].attnames [j ], force_quotes ));
4170
- dumpComment (fout , q -> data , tblinfo [i ].attoids [j ]);
4217
+ dumpComment (fout , q -> data , tblinfo [i ].attoids [j ], NULL );
4171
4218
}
4172
4219
4173
4220
/* Dump Table Comments */
4174
4221
4175
4222
resetPQExpBuffer (q );
4176
4223
appendPQExpBuffer (q , "%s %s" , reltypename , fmtId (tblinfo [i ].relname , force_quotes ));
4177
- dumpComment (fout , q -> data , tblinfo [i ].oid );
4224
+ dumpComment (fout , q -> data , tblinfo [i ].oid , commentDeps );
4178
4225
4179
4226
}
4180
4227
}
4228
+
4229
+ destroyPQExpBuffer (q );
4230
+ destroyPQExpBuffer (delq );
4181
4231
}
4182
4232
4183
4233
static PQExpBuffer
@@ -4461,7 +4511,7 @@ dumpIndices(Archive *fout, IndInfo *indinfo, int numIndices,
4461
4511
/* Dump Index Comments */
4462
4512
resetPQExpBuffer (q );
4463
4513
appendPQExpBuffer (q , "INDEX %s" , id1 -> data );
4464
- dumpComment (fout , q -> data , indinfo [i ].indoid );
4514
+ dumpComment (fout , q -> data , indinfo [i ].indoid , NULL );
4465
4515
4466
4516
}
4467
4517
}
@@ -4776,7 +4826,7 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
4776
4826
4777
4827
resetPQExpBuffer (query );
4778
4828
appendPQExpBuffer (query , "SEQUENCE %s" , fmtId (tbinfo .relname , force_quotes ));
4779
- dumpComment (fout , query -> data , tbinfo .oid );
4829
+ dumpComment (fout , query -> data , tbinfo .oid , NULL );
4780
4830
}
4781
4831
}
4782
4832
@@ -4802,7 +4852,7 @@ dumpTriggers(Archive *fout, const char *tablename,
4802
4852
ArchiveEntry (fout , tblinfo [i ].triggers [j ].oid , tblinfo [i ].triggers [j ].tgname ,
4803
4853
"TRIGGER" , NULL , tblinfo [i ].triggers [j ].tgsrc , "" , "" ,
4804
4854
tblinfo [i ].usename , NULL , NULL );
4805
- dumpComment (fout , tblinfo [i ].triggers [j ].tgcomment , tblinfo [i ].triggers [j ].oid );
4855
+ dumpComment (fout , tblinfo [i ].triggers [j ].tgcomment , tblinfo [i ].triggers [j ].oid , NULL );
4806
4856
}
4807
4857
}
4808
4858
}
@@ -4882,7 +4932,7 @@ dumpRules(Archive *fout, const char *tablename,
4882
4932
4883
4933
resetPQExpBuffer (query );
4884
4934
appendPQExpBuffer (query , "RULE %s" , fmtId (PQgetvalue (res , i , i_rulename ), force_quotes ));
4885
- dumpComment (fout , query -> data , PQgetvalue (res , i , i_oid ));
4935
+ dumpComment (fout , query -> data , PQgetvalue (res , i , i_oid ), NULL );
4886
4936
4887
4937
}
4888
4938
0 commit comments