22
22
*
23
23
*
24
24
* IDENTIFICATION
25
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.189 2001/01/28 02:57:06 pjw Exp $
25
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.190 2001/01/28 03:47:49 pjw Exp $
26
26
*
27
27
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
28
28
*
@@ -2037,6 +2037,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2037
2037
tblinfo [i ].relname ,
2038
2038
g_comment_end );
2039
2039
2040
+ /* XXXX: Use LOJ maybe - need to compare with subsequent query for non-inherited */
2040
2041
resetPQExpBuffer (query );
2041
2042
appendPQExpBuffer (query , "SELECT rcname from pg_relcheck, pg_inherits as i "
2042
2043
"where rcrelid = '%s'::oid "
@@ -2141,13 +2142,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2141
2142
res2 = PQexec (g_conn , query -> data );
2142
2143
if (!res2 || PQresultStatus (res2 ) != PGRES_TUPLES_OK )
2143
2144
{
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 ));
2146
2147
exit_nicely (g_conn );
2147
2148
}
2148
2149
2149
2150
if (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 );
2151
2153
exit_nicely (g_conn );
2152
2154
}
2153
2155
@@ -2170,29 +2172,38 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2170
2172
resetPQExpBuffer (query );
2171
2173
appendPQExpBuffer (query ,
2172
2174
"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 "
2174
2176
"WHERE i.indrelid = %s"
2175
- "AND i.indisprimary "
2176
- "AND c.oid = i.indexrelid " ,
2177
+ "AND i.indisprimary " ,
2177
2178
tblinfo [i ].oid );
2178
2179
res2 = PQexec (g_conn , query -> data );
2179
2180
if (!res2 || PQresultStatus (res2 ) != PGRES_TUPLES_OK )
2180
2181
{
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 ));
2183
2184
exit_nicely (g_conn );
2184
2185
}
2185
2186
2186
2187
n = PQntuples (res2 );
2187
2188
if (n != 1 )
2188
2189
{
2189
2190
fprintf (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 ,
2191
2194
tblinfo [i ].oid ,
2192
2195
n );
2193
2196
exit_nicely (g_conn );
2194
2197
}
2195
2198
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
+
2196
2207
tblinfo [i ].primary_key_name =
2197
2208
strdup (fmtId (PQgetvalue (res2 , 0 , 0 ), force_quotes ));
2198
2209
if (tblinfo [i ].primary_key_name == NULL )
@@ -2569,8 +2580,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
2569
2580
resetPQExpBuffer (q );
2570
2581
appendPQExpBuffer (q , "SELECT a.oid as attoid, a.attnum, a.attname, t.typname, a.atttypmod, "
2571
2582
"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'::oid and 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 "
2574
2585
"and a.attnum > 0 order by attnum" ,
2575
2586
tblinfo [i ].oid );
2576
2587
res = PQexec (g_conn , q -> data );
@@ -2605,6 +2616,15 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
2605
2616
tblinfo [i ].numParents = 0 ;
2606
2617
for (j = 0 ; j < ntups ; j ++ )
2607
2618
{
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
+
2608
2628
tblinfo [i ].attoids [j ] = strdup (PQgetvalue (res , j , i_attoid ));
2609
2629
tblinfo [i ].attnames [j ] = strdup (PQgetvalue (res , j , i_attname ));
2610
2630
tblinfo [i ].atttypedefns [j ] = strdup (PQgetvalue (res , j , i_atttypedefn ));
@@ -2692,6 +2712,8 @@ getIndices(int *numIndices)
2692
2712
* Notice we skip indices on system classes
2693
2713
*
2694
2714
* this is a 4-way join !!
2715
+ *
2716
+ * XXXX: Use LOJ
2695
2717
*/
2696
2718
2697
2719
appendPQExpBuffer (query ,
@@ -4423,6 +4445,8 @@ dumpRules(Archive *fout, const char *tablename,
4423
4445
* Get all rules defined for this table
4424
4446
* We include pg_rules in the cross since it filters out
4425
4447
* all view rules (pjw 15-Sep-2000).
4448
+ *
4449
+ * XXXX: Use LOJ here
4426
4450
*/
4427
4451
resetPQExpBuffer (query );
4428
4452
appendPQExpBuffer (query , "SELECT definition,"
0 commit comments