21
21
*
22
22
*
23
23
* IDENTIFICATION
24
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.72 1998/06/15 19:30:01 momjian Exp $
24
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.73 1998/06/16 06:52:15 momjian Exp $
25
25
*
26
26
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
27
27
*
@@ -110,6 +110,7 @@ int dumpData; /* dump data using proper insert strings */
110
110
int attrNames ; /* put attr names into insert strings */
111
111
int schemaOnly ;
112
112
int dataOnly ;
113
+ int compatConstraint ;
113
114
114
115
char g_opaque_type [10 ]; /* name for the opaque type */
115
116
@@ -125,6 +126,8 @@ usage(const char *progname)
125
126
"usage: %s [options] dbname\n" , progname );
126
127
fprintf (stderr ,
127
128
"\t -a \t\t dump out only the data, no schema\n" );
129
+ fprintf (stderr ,
130
+ "\t -c \t\t generate pgsql-compatible CONSTRAINT syntax\n" );
128
131
fprintf (stderr ,
129
132
"\t -d \t\t dump data as proper insert strings\n" );
130
133
fprintf (stderr ,
@@ -550,17 +553,21 @@ main(int argc, char **argv)
550
553
g_comment_end [0 ] = '\0' ;
551
554
strcpy (g_opaque_type , "opaque" );
552
555
553
- dataOnly = schemaOnly = dumpData = attrNames = 0 ;
556
+ compatConstraint = dataOnly = schemaOnly = dumpData = attrNames = 0 ;
554
557
555
558
progname = * argv ;
556
559
557
- while ((c = getopt (argc , argv , "adDf :h:op:st:vzu" )) != EOF )
560
+ while ((c = getopt (argc , argv , "acdDf :h:op:st:vzu" )) != EOF )
558
561
{
559
562
switch (c )
560
563
{
561
564
case 'a' : /* Dump data only */
562
565
dataOnly = 1 ;
563
566
break ;
567
+ case 'c' : /* generate constraint syntax that
568
+ can be read back into postgreSQL */
569
+ compatConstraint = 1 ;
570
+ break ;
564
571
case 'd' : /* dump data as proper insert strings */
565
572
dumpData = 1 ;
566
573
break ;
@@ -1491,7 +1498,12 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1491
1498
query [0 ] = 0 ;
1492
1499
if (name [0 ] != '$' )
1493
1500
sprintf (query , "CONSTRAINT %s " , name );
1494
- sprintf (query , "%sCHECK %s" , query , expr );
1501
+ if ( compatConstraint ) {
1502
+ sprintf (query , "%sCHECK (%s)" , query , expr );
1503
+ }
1504
+ else {
1505
+ sprintf (query , "%sCHECK %s" , query , expr );
1506
+ }
1495
1507
tblinfo [i ].check_expr [i2 ] = strdup (query );
1496
1508
}
1497
1509
PQclear (res2 );
@@ -2509,6 +2521,17 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
2509
2521
}
2510
2522
}
2511
2523
2524
+ if ( compatConstraint ) {
2525
+ /* put the CONSTRAINTS inside the table def */
2526
+ for (k = 0 ; k < tblinfo [i ].ncheck ; k ++ )
2527
+ {
2528
+ sprintf (q , "%s%s %s" ,
2529
+ q ,
2530
+ (actual_atts + k > 0 ) ? ", " : "" ,
2531
+ tblinfo [i ].check_expr [k ]);
2532
+ }
2533
+ }
2534
+
2512
2535
strcat (q , ")" );
2513
2536
2514
2537
if (numParents > 0 )
@@ -2524,8 +2547,9 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
2524
2547
strcat (q , ")" );
2525
2548
}
2526
2549
2527
- if ( tblinfo [ i ]. ncheck > 0 )
2550
+ if ( ! compatConstraint )
2528
2551
{
2552
+ /* put the CONSTRAINT defs outside the table def */
2529
2553
for (k = 0 ; k < tblinfo [i ].ncheck ; k ++ )
2530
2554
{
2531
2555
sprintf (q , "%s%s %s" ,
@@ -2534,6 +2558,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
2534
2558
tblinfo [i ].check_expr [k ]);
2535
2559
}
2536
2560
}
2561
+
2537
2562
strcat (q , ";\n" );
2538
2563
fputs (q , fout );
2539
2564
if (acls )
0 commit comments