2121 *
2222 *
2323 * 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 $
2525 *
2626 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727 *
@@ -643,7 +643,8 @@ main(int argc, char **argv)
643643force_quotes = true;
644644break ;
645645case '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 */
647648case 'O' :/* Dump oids */
648649oids = true;
649650break ;
@@ -1632,13 +1633,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16321633
16331634resetPQExpBuffer (query );
16341635if (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 ));
16381638}
1639- appendPQExpBuffer (query ,"CHECK (" );
1640- appendPQExpBuffer (query ,expr );
1641- appendPQExpBuffer (query ,")" );
1639+ appendPQExpBuffer (query ,"CHECK (%s)" ,expr );
16421640tblinfo [i ].check_expr [i2 ]= strdup (query -> data );
16431641}
16441642PQclear (res2 );
@@ -1647,11 +1645,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16471645tblinfo [i ].check_expr = NULL ;
16481646
16491647/* 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 ;
16551653
16561654resetPQExpBuffer (query );
16571655appendPQExpBuffer (query ,
@@ -1661,33 +1659,34 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16611659" AND i.indexrelid = c.oid AND a.attnum > 0 AND a.attrelid = c.oid "
16621660"ORDER BY a.attnum " ,
16631661tblinfo [i ].oid );
1664- res2 = PQexec (g_conn ,query -> data );
1662+ res2 = PQexec (g_conn ,query -> data );
16651663if (!res2 || PQresultStatus (res2 )!= PGRES_TUPLES_OK )
16661664{
16671665fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY) failed. Explanation from backend: %s" ,
16681666PQerrorMessage (g_conn ));
16691667exit_nicely (g_conn );
16701668}
16711669
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+ }
16781677
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 ;
16841687}
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 ;
16911690
16921691/* Get Triggers */
16931692if (tblinfo [i ].ntrig > 0 )
@@ -1740,7 +1739,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
17401739int tgnargs = atoi (PQgetvalue (res2 ,i2 ,i_tgnargs ));
17411740const char * tgargs = PQgetvalue (res2 ,i2 ,i_tgargs );
17421741const char * p ;
1743- PQExpBuffer farg = createPQExpBuffer ();
17441742int findx ;
17451743
17461744for (findx = 0 ;findx < numFuncs ;findx ++ )
@@ -1763,9 +1761,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
17631761if (dropSchema )
17641762{
17651763resetPQExpBuffer (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 ));
17691769fputs (query -> data ,fout );
17701770}
17711771#endif
@@ -1800,8 +1800,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
18001800else
18011801appendPQExpBuffer (query ," UPDATE" );
18021802}
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 ));
18051807for (findx = 0 ;findx < tgnargs ;findx ++ )
18061808{
18071809const char * s ;
@@ -1827,15 +1829,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
18271829break ;
18281830}
18291831p -- ;
1832+ appendPQExpBufferChar (query ,'\'' );
18301833for (s = tgargs ;s < p ;)
18311834{
18321835if (* s == '\'' )
1833- appendPQExpBufferChar (farg ,'\\' );
1834- appendPQExpBufferChar (farg ,* s ++ );
1836+ appendPQExpBufferChar (query ,'\\' );
1837+ appendPQExpBufferChar (query ,* s ++ );
18351838}
18361839appendPQExpBufferChar (query ,'\'' );
1837- appendPQExpBuffer (query ,farg -> data );
1838- appendPQExpBufferChar (query ,'\'' );
18391840appendPQExpBuffer (query , (findx < tgnargs - 1 ) ?", " :"" );
18401841tgargs = p + 4 ;
18411842}
@@ -2476,9 +2477,12 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
24762477if (dropSchema )
24772478{
24782479resetPQExpBuffer (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));
24822486fputs (q -> data ,fout );
24832487}
24842488