21
21
*
22
22
*
23
23
* IDENTIFICATION
24
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.133 2000/01/1800:03:37 petere Exp $
24
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.134 2000/01/1807:29:58 tgl Exp $
25
25
*
26
26
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
27
27
*
@@ -643,7 +643,8 @@ main(int argc, char **argv)
643
643
force_quotes = true;
644
644
break ;
645
645
case 'o' :
646
- fprintf (stderr ,"%s: The -o option for dumping oids is deprecated. Please use -O." );
646
+ fprintf (stderr ,"%s: The -o option for dumping oids is deprecated. Please use -O.\n" ,progname );
647
+ /* FALLTHRU */
647
648
case 'O' :/* Dump oids */
648
649
oids = true;
649
650
break ;
@@ -1632,13 +1633,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1632
1633
1633
1634
resetPQExpBuffer (query );
1634
1635
if (name [0 ]!= '$' ) {
1635
- appendPQExpBuffer (query ,"CONSTRAINT " );
1636
- appendPQExpBuffer (query ,fmtId (name ,force_quotes ));
1637
- appendPQExpBufferChar (query ,' ' );
1636
+ appendPQExpBuffer (query ,"CONSTRAINT %s " ,
1637
+ fmtId (name ,force_quotes ));
1638
1638
}
1639
- appendPQExpBuffer (query ,"CHECK (" );
1640
- appendPQExpBuffer (query ,expr );
1641
- appendPQExpBuffer (query ,")" );
1639
+ appendPQExpBuffer (query ,"CHECK (%s)" ,expr );
1642
1640
tblinfo [i ].check_expr [i2 ]= strdup (query -> data );
1643
1641
}
1644
1642
PQclear (res2 );
@@ -1647,11 +1645,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1647
1645
tblinfo [i ].check_expr = NULL ;
1648
1646
1649
1647
/* Get primary key */
1650
- if (strcmp (PQgetvalue (res ,i ,i_relhasindex ),"t" )== 0 )
1651
- {
1652
- PGresult * res2 ;
1653
- char str [INDEX_MAX_KEYS * NAMEDATALEN + 3 ] = "" ;
1654
- int j ;
1648
+ if (strcmp (PQgetvalue (res ,i ,i_relhasindex ),"t" )== 0 )
1649
+ {
1650
+ PGresult * res2 ;
1651
+ char str [INDEX_MAX_KEYS * ( NAMEDATALEN * 2 + 4 ) + 1 ] ;
1652
+ int j ;
1655
1653
1656
1654
resetPQExpBuffer (query );
1657
1655
appendPQExpBuffer (query ,
@@ -1661,33 +1659,34 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1661
1659
" AND i.indexrelid = c.oid AND a.attnum > 0 AND a.attrelid = c.oid "
1662
1660
"ORDER BY a.attnum " ,
1663
1661
tblinfo [i ].oid );
1664
- res2 = PQexec (g_conn ,query -> data );
1662
+ res2 = PQexec (g_conn ,query -> data );
1665
1663
if (!res2 || PQresultStatus (res2 )!= PGRES_TUPLES_OK )
1666
1664
{
1667
1665
fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY) failed. Explanation from backend: %s" ,
1668
1666
PQerrorMessage (g_conn ));
1669
1667
exit_nicely (g_conn );
1670
1668
}
1671
1669
1672
- for (j = 0 ;j < PQntuples (res2 );j ++ )
1673
- {
1674
- if (strlen (str )> 0 )
1675
- strcat (str ,", " );
1676
- strcat (str ,fmtId (PQgetvalue (res2 ,j ,0 ),force_quotes ));
1677
- }
1670
+ str [0 ]= '\0' ;
1671
+ for (j = 0 ;j < PQntuples (res2 );j ++ )
1672
+ {
1673
+ if (strlen (str )> 0 )
1674
+ strcat (str ,", " );
1675
+ strcat (str ,fmtId (PQgetvalue (res2 ,j ,0 ),force_quotes ));
1676
+ }
1678
1677
1679
- if (strlen (str )> 0 ) {
1680
- tblinfo [i ].primary_key = strdup (str );
1681
- if (tblinfo [i ].primary_key == NULL ) {
1682
- perror ("strdup" );
1683
- exit (1 );
1678
+ if (strlen (str )> 0 ) {
1679
+ tblinfo [i ].primary_key = strdup (str );
1680
+ if (tblinfo [i ].primary_key == NULL ) {
1681
+ perror ("strdup" );
1682
+ exit (1 );
1683
+ }
1684
+ }
1685
+ else
1686
+ tblinfo [i ].primary_key = NULL ;
1684
1687
}
1685
- }
1686
- else
1687
- tblinfo [i ].primary_key = NULL ;
1688
- }
1689
- else
1690
- tblinfo [i ].primary_key = NULL ;
1688
+ else
1689
+ tblinfo [i ].primary_key = NULL ;
1691
1690
1692
1691
/* Get Triggers */
1693
1692
if (tblinfo [i ].ntrig > 0 )
@@ -1740,7 +1739,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1740
1739
int tgnargs = atoi (PQgetvalue (res2 ,i2 ,i_tgnargs ));
1741
1740
const char * tgargs = PQgetvalue (res2 ,i2 ,i_tgargs );
1742
1741
const char * p ;
1743
- PQExpBuffer farg = createPQExpBuffer ();
1744
1742
int findx ;
1745
1743
1746
1744
for (findx = 0 ;findx < numFuncs ;findx ++ )
@@ -1763,9 +1761,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1763
1761
if (dropSchema )
1764
1762
{
1765
1763
resetPQExpBuffer (query );
1766
- appendPQExpBuffer (query ,"DROP TRIGGER %s ON %s;\n" ,
1767
- fmtId (PQgetvalue (res2 ,i2 ,i_tgname ),force_quotes ),
1768
- fmtId (tblinfo [i ].relname ,force_quotes ));
1764
+ appendPQExpBuffer (query ,"DROP TRIGGER %s " ,
1765
+ fmtId (PQgetvalue (res2 ,i2 ,i_tgname ),
1766
+ force_quotes ));
1767
+ appendPQExpBuffer (query ,"ON %s;\n" ,
1768
+ fmtId (tblinfo [i ].relname ,force_quotes ));
1769
1769
fputs (query -> data ,fout );
1770
1770
}
1771
1771
#endif
@@ -1800,8 +1800,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1800
1800
else
1801
1801
appendPQExpBuffer (query ," UPDATE" );
1802
1802
}
1803
- appendPQExpBuffer (query ," ON %s FOR EACH ROW EXECUTE PROCEDURE %s (" ,
1804
- fmtId (tblinfo [i ].relname ,force_quotes ),tgfunc );
1803
+ appendPQExpBuffer (query ," ON %s FOR EACH ROW" ,
1804
+ fmtId (tblinfo [i ].relname ,force_quotes ));
1805
+ appendPQExpBuffer (query ," EXECUTE PROCEDURE %s (" ,
1806
+ fmtId (tgfunc ,force_quotes ));
1805
1807
for (findx = 0 ;findx < tgnargs ;findx ++ )
1806
1808
{
1807
1809
const char * s ;
@@ -1827,15 +1829,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
1827
1829
break ;
1828
1830
}
1829
1831
p -- ;
1832
+ appendPQExpBufferChar (query ,'\'' );
1830
1833
for (s = tgargs ;s < p ;)
1831
1834
{
1832
1835
if (* s == '\'' )
1833
- appendPQExpBufferChar (farg ,'\\' );
1834
- appendPQExpBufferChar (farg ,* s ++ );
1836
+ appendPQExpBufferChar (query ,'\\' );
1837
+ appendPQExpBufferChar (query ,* s ++ );
1835
1838
}
1836
1839
appendPQExpBufferChar (query ,'\'' );
1837
- appendPQExpBuffer (query ,farg -> data );
1838
- appendPQExpBufferChar (query ,'\'' );
1839
1840
appendPQExpBuffer (query , (findx < tgnargs - 1 ) ?", " :"" );
1840
1841
tgargs = p + 4 ;
1841
1842
}
@@ -2476,9 +2477,12 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
2476
2477
if (dropSchema )
2477
2478
{
2478
2479
resetPQExpBuffer (q );
2479
- appendPQExpBuffer (q ,"DROP OPERATOR %s (%s, %s);\n" ,oprinfo [i ].oprname ,
2480
- fmtId (findTypeByOid (tinfo ,numTypes ,oprinfo [i ].oprleft ), false),
2481
- fmtId (findTypeByOid (tinfo ,numTypes ,oprinfo [i ].oprright ), false));
2480
+ appendPQExpBuffer (q ,"DROP OPERATOR %s (%s" ,oprinfo [i ].oprname ,
2481
+ fmtId (findTypeByOid (tinfo ,numTypes ,oprinfo [i ].oprleft ),
2482
+ false));
2483
+ appendPQExpBuffer (q ,", %s);\n" ,
2484
+ fmtId (findTypeByOid (tinfo ,numTypes ,oprinfo [i ].oprright ),
2485
+ false));
2482
2486
fputs (q -> data ,fout );
2483
2487
}
2484
2488