2222 *
2323 *
2424 * IDENTIFICATION
25- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.189 2001/01/2802:57:06 pjw Exp $
25+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.190 2001/01/2803:47:49 pjw Exp $
2626 *
2727 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828 *
@@ -2037,6 +2037,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
20372037tblinfo [i ].relname ,
20382038g_comment_end );
20392039
2040+ /* XXXX: Use LOJ maybe - need to compare with subsequent query for non-inherited */
20402041resetPQExpBuffer (query );
20412042appendPQExpBuffer (query ,"SELECT rcname from pg_relcheck, pg_inherits as i "
20422043"where rcrelid = '%s'::oid "
@@ -2141,13 +2142,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21412142res2 = PQexec (g_conn ,query -> data );
21422143if (!res2 || PQresultStatus (res2 )!= PGRES_TUPLES_OK )
21432144{
2144- fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY) failed. Explanation from backend: %s\n" ,
2145- PQerrorMessage (g_conn ));
2145+ fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY) failed on table %s . Explanation from backend: %s\n" ,
2146+ tblinfo [ i ]. relname , PQerrorMessage (g_conn ));
21462147exit_nicely (g_conn );
21472148}
21482149
21492150if (PQntuples (res2 )> 1 ) {
2150- fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY) produced more than one row.\n" );
2151+ fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY) produced more than one row on table %s.\n" ,
2152+ tblinfo [i ].relname );
21512153exit_nicely (g_conn );
21522154}
21532155
@@ -2170,29 +2172,38 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21702172resetPQExpBuffer (query );
21712173appendPQExpBuffer (query ,
21722174"SELECT c.relname "
2173- "FROM pg_index i, pg_class c "
2175+ "FROM pg_index i LEFT OUTER JOIN pg_class c ON c.oid = i.indexrelid "
21742176"WHERE i.indrelid = %s"
2175- "AND i.indisprimary "
2176- "AND c.oid = i.indexrelid " ,
2177+ "AND i.indisprimary " ,
21772178tblinfo [i ].oid );
21782179res2 = PQexec (g_conn ,query -> data );
21792180if (!res2 || PQresultStatus (res2 )!= PGRES_TUPLES_OK )
21802181{
2181- fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY NAME) failed. Explanation from backend: %s" ,
2182- PQerrorMessage (g_conn ));
2182+ fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY NAME) failed for table %s . Explanation from backend: %s" ,
2183+ tblinfo [ i ]. relname , PQerrorMessage (g_conn ));
21832184exit_nicely (g_conn );
21842185}
21852186
21862187n = PQntuples (res2 );
21872188if (n != 1 )
21882189{
21892190fprintf (stderr ,
2190- "getTables(): SELECT (for PRIMARY KEY NAME) failed. This is impossible but object with OID == %s have %d primary keys.\n" ,
2191+ "getTables(): SELECT (for PRIMARY KEY NAME) failed for table %s. "
2192+ "This is impossible but object with OID == %s have %d primary keys.\n" ,
2193+ tblinfo [i ].relname ,
21912194tblinfo [i ].oid ,
21922195n );
21932196exit_nicely (g_conn );
21942197}
21952198
2199+ /* Sanity check on LOJ */
2200+ if (PQgetisnull (res2 ,0 ,0 ))
2201+ {
2202+ fprintf (stderr ,"getTables(): SELECT (for PRIMARY KEY NAME) on table %s returned NULL value.\n" ,
2203+ tblinfo [i ].relname );
2204+ exit_nicely (g_conn );
2205+ }
2206+
21962207tblinfo [i ].primary_key_name =
21972208strdup (fmtId (PQgetvalue (res2 ,0 ,0 ),force_quotes ));
21982209if (tblinfo [i ].primary_key_name == NULL )
@@ -2569,8 +2580,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
25692580resetPQExpBuffer (q );
25702581appendPQExpBuffer (q ,"SELECT a.oid as attoid, a.attnum, a.attname, t.typname, a.atttypmod, "
25712582"a.attnotnull, a.atthasdef, format_type(a.atttypid, a.atttypmod) as atttypedefn "
2572- "from pg_attribute a, pg_type t "
2573- "where a.attrelid = '%s'::oidand a.atttypid = t.oid "
2583+ "from pg_attribute a LEFT OUTER JOIN pg_type t ON a.atttypid = t.oid "
2584+ "where a.attrelid = '%s'::oid "
25742585"and a.attnum > 0 order by attnum" ,
25752586tblinfo [i ].oid );
25762587res = PQexec (g_conn ,q -> data );
@@ -2605,6 +2616,15 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
26052616tblinfo [i ].numParents = 0 ;
26062617for (j = 0 ;j < ntups ;j ++ )
26072618{
2619+
2620+ /* Sanity check on LOJ */
2621+ if (PQgetisnull (res ,j ,i_typname ))
2622+ {
2623+ fprintf (stderr ,"getTableAttrs(): SELECT produced NULL attribute type name for attr %d on table %s.\n" ,
2624+ j ,tblinfo [i ].relname );
2625+ exit_nicely (g_conn );
2626+ }
2627+
26082628tblinfo [i ].attoids [j ]= strdup (PQgetvalue (res ,j ,i_attoid ));
26092629tblinfo [i ].attnames [j ]= strdup (PQgetvalue (res ,j ,i_attname ));
26102630tblinfo [i ].atttypedefns [j ]= strdup (PQgetvalue (res ,j ,i_atttypedefn ));
@@ -2692,6 +2712,8 @@ getIndices(int *numIndices)
26922712 * Notice we skip indices on system classes
26932713 *
26942714 * this is a 4-way join !!
2715+ *
2716+ * XXXX: Use LOJ
26952717 */
26962718
26972719appendPQExpBuffer (query ,
@@ -4423,6 +4445,8 @@ dumpRules(Archive *fout, const char *tablename,
44234445 * Get all rules defined for this table
44244446 * We include pg_rules in the cross since it filters out
44254447 * all view rules (pjw 15-Sep-2000).
4448+ *
4449+ * XXXX: Use LOJ here
44264450 */
44274451resetPQExpBuffer (query );
44284452appendPQExpBuffer (query ,"SELECT definition,"