2121 *
2222 *
2323 * IDENTIFICATION
24- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.106 1999/05/13 02:35:44 momjian Exp $
24+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.107 1999/05/15 22:18:50 momjian Exp $
2525 *
2626 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727 *
@@ -194,7 +194,7 @@ isViewRule(char *relname)
194194if (!res ||
195195PQresultStatus (res )!= PGRES_COMMAND_OK )
196196{
197- fprintf (stderr ,"BEGIN command failed\n" );
197+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
198198exit_nicely (g_conn );
199199}
200200PQclear (res );
@@ -208,7 +208,7 @@ isViewRule(char *relname)
208208if (!res ||
209209PQresultStatus (res )!= PGRES_TUPLES_OK )
210210{
211- fprintf (stderr ,"isViewRule(): SELECT failed\n" );
211+ fprintf (stderr ,"isViewRule(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
212212exit_nicely (g_conn );
213213}
214214
@@ -306,12 +306,9 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
306306"Explanation from backend: '%s'.\n"
307307"The query was: '%s'.\n" ,
308308classname ,PQerrorMessage (g_conn ),query );
309- if (res )
310- PQclear (res );
309+ PQclear (res );
311310exit_nicely (g_conn );
312311}
313- if (res )
314- PQclear (res );
315312}
316313}
317314
@@ -333,7 +330,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
333330if (!res ||
334331PQresultStatus (res )!= PGRES_TUPLES_OK )
335332{
336- fprintf (stderr ,"dumpClasses(): command failed\n" );
333+ fprintf (stderr ,"dumpClasses(): command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
337334exit_nicely (g_conn );
338335}
339336for (tuple = 0 ;tuple < PQntuples (res );tuple ++ )
@@ -771,7 +768,7 @@ getTypes(int *numTypes)
771768if (!res ||
772769PQresultStatus (res )!= PGRES_COMMAND_OK )
773770{
774- fprintf (stderr ,"BEGIN command failed\n" );
771+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
775772exit_nicely (g_conn );
776773}
777774PQclear (res );
@@ -796,7 +793,7 @@ getTypes(int *numTypes)
796793if (!res ||
797794PQresultStatus (res )!= PGRES_TUPLES_OK )
798795{
799- fprintf (stderr ,"getTypes(): SELECT failed\n" );
796+ fprintf (stderr ,"getTypes(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
800797exit_nicely (g_conn );
801798}
802799
@@ -904,7 +901,7 @@ getOperators(int *numOprs)
904901if (!res ||
905902PQresultStatus (res )!= PGRES_COMMAND_OK )
906903{
907- fprintf (stderr ,"BEGIN command failed\n" );
904+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
908905exit_nicely (g_conn );
909906}
910907PQclear (res );
@@ -919,7 +916,7 @@ getOperators(int *numOprs)
919916if (!res ||
920917PQresultStatus (res )!= PGRES_TUPLES_OK )
921918{
922- fprintf (stderr ,"getOperators(): SELECT failed\n" );
919+ fprintf (stderr ,"getOperators(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
923920exit_nicely (g_conn );
924921}
925922
@@ -1241,7 +1238,7 @@ getAggregates(int *numAggs)
12411238if (!res ||
12421239PQresultStatus (res )!= PGRES_COMMAND_OK )
12431240{
1244- fprintf (stderr ,"BEGIN command failed\n" );
1241+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
12451242exit_nicely (g_conn );
12461243}
12471244PQclear (res );
@@ -1256,7 +1253,7 @@ getAggregates(int *numAggs)
12561253if (!res ||
12571254PQresultStatus (res )!= PGRES_TUPLES_OK )
12581255{
1259- fprintf (stderr ,"getAggregates(): SELECT failed\n" );
1256+ fprintf (stderr ,"getAggregates(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
12601257exit_nicely (g_conn );
12611258}
12621259
@@ -1334,7 +1331,7 @@ getFuncs(int *numFuncs)
13341331if (!res ||
13351332PQresultStatus (res )!= PGRES_COMMAND_OK )
13361333{
1337- fprintf (stderr ,"BEGIN command failed\n" );
1334+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
13381335exit_nicely (g_conn );
13391336}
13401337PQclear (res );
@@ -1350,7 +1347,7 @@ getFuncs(int *numFuncs)
13501347if (!res ||
13511348PQresultStatus (res )!= PGRES_TUPLES_OK )
13521349{
1353- fprintf (stderr ,"getFuncs(): SELECT failed\n" );
1350+ fprintf (stderr ,"getFuncs(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
13541351exit_nicely (g_conn );
13551352}
13561353
@@ -1437,7 +1434,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14371434if (!res ||
14381435PQresultStatus (res )!= PGRES_COMMAND_OK )
14391436{
1440- fprintf (stderr ,"BEGIN command failed\n" );
1437+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
14411438exit_nicely (g_conn );
14421439}
14431440PQclear (res );
@@ -1454,7 +1451,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14541451if (!res ||
14551452PQresultStatus (res )!= PGRES_TUPLES_OK )
14561453{
1457- fprintf (stderr ,"getTables(): SELECT failed\n" );
1454+ fprintf (stderr ,"getTables(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
14581455exit_nicely (g_conn );
14591456}
14601457
@@ -1511,7 +1508,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
15111508if (!res2 ||
15121509PQresultStatus (res2 )!= PGRES_TUPLES_OK )
15131510{
1514- fprintf (stderr ,"getTables(): SELECT (for inherited CHECK) failed\n" );
1511+ fprintf (stderr ,"getTables(): SELECT (for inherited CHECK) failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
15151512exit_nicely (g_conn );
15161513}
15171514ntups2 = PQntuples (res2 );
@@ -1554,7 +1551,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
15541551if (!res2 ||
15551552PQresultStatus (res2 )!= PGRES_TUPLES_OK )
15561553{
1557- fprintf (stderr ,"getTables(): SELECT (for CHECK) failed\n" );
1554+ fprintf (stderr ,"getTables(): SELECT (for CHECK) failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
15581555exit_nicely (g_conn );
15591556}
15601557ntups2 = PQntuples (res2 );
@@ -1609,7 +1606,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16091606if (!res2 ||
16101607PQresultStatus (res2 )!= PGRES_TUPLES_OK )
16111608{
1612- fprintf (stderr ,"getTables(): SELECT (for TRIGGER) failed\n" );
1609+ fprintf (stderr ,"getTables(): SELECT (for TRIGGER) failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
16131610exit_nicely (g_conn );
16141611}
16151612ntups2 = PQntuples (res2 );
@@ -1770,7 +1767,7 @@ getInherits(int *numInherits)
17701767if (!res ||
17711768PQresultStatus (res )!= PGRES_COMMAND_OK )
17721769{
1773- fprintf (stderr ,"BEGIN command failed\n" );
1770+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
17741771exit_nicely (g_conn );
17751772}
17761773PQclear (res );
@@ -1781,7 +1778,7 @@ getInherits(int *numInherits)
17811778if (!res ||
17821779PQresultStatus (res )!= PGRES_TUPLES_OK )
17831780{
1784- fprintf (stderr ,"getInherits(): SELECT failed\n" );
1781+ fprintf (stderr ,"getInherits(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
17851782exit_nicely (g_conn );
17861783}
17871784
@@ -1859,7 +1856,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
18591856if (!res ||
18601857PQresultStatus (res )!= PGRES_TUPLES_OK )
18611858{
1862- fprintf (stderr ,"getTableAttrs(): SELECT failed\n" );
1859+ fprintf (stderr ,"getTableAttrs(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
18631860exit_nicely (g_conn );
18641861}
18651862
@@ -1905,7 +1902,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
19051902if (!res2 ||
19061903PQresultStatus (res2 )!= PGRES_TUPLES_OK )
19071904{
1908- fprintf (stderr ,"getTableAttrs(): SELECT (for DEFAULT) failed\n" );
1905+ fprintf (stderr ,"getTableAttrs(): SELECT (for DEFAULT) failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
19091906exit_nicely (g_conn );
19101907}
19111908tblinfo [i ].adef_expr [j ]= strdup (PQgetvalue (res2 ,0 ,PQfnumber (res2 ,"adsrc" )));
@@ -1958,7 +1955,7 @@ getIndices(int *numIndices)
19581955if (!res ||
19591956PQresultStatus (res )!= PGRES_COMMAND_OK )
19601957{
1961- fprintf (stderr ,"BEGIN command failed\n" );
1958+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
19621959exit_nicely (g_conn );
19631960}
19641961PQclear (res );
@@ -1977,7 +1974,7 @@ getIndices(int *numIndices)
19771974if (!res ||
19781975PQresultStatus (res )!= PGRES_TUPLES_OK )
19791976{
1980- fprintf (stderr ,"getIndices(): SELECT failed\n" );
1977+ fprintf (stderr ,"getIndices(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
19811978exit_nicely (g_conn );
19821979}
19831980
@@ -2009,8 +2006,7 @@ getIndices(int *numIndices)
20092006}
20102007PQclear (res );
20112008res = PQexec (g_conn ,"end" );
2012- if (res )
2013- PQclear (res );
2009+ PQclear (res );
20142010return indinfo ;
20152011}
20162012
@@ -2120,7 +2116,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
21202116if (!res ||
21212117PQresultStatus (res )!= PGRES_COMMAND_OK )
21222118{
2123- fprintf (stderr ,"BEGIN command failed\n" );
2119+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
21242120exit_nicely (g_conn );
21252121}
21262122
@@ -2131,7 +2127,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
21312127if (!res ||
21322128PQresultStatus (res )!= PGRES_TUPLES_OK )
21332129{
2134- fprintf (stderr ,"dumpProcLangs(): SELECT failed\n" );
2130+ fprintf (stderr ,"dumpProcLangs(): SELECT failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
21352131exit_nicely (g_conn );
21362132}
21372133ntups = PQntuples (res );
@@ -2243,7 +2239,7 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
22432239if (!res ||
22442240PQresultStatus (res )!= PGRES_COMMAND_OK )
22452241{
2246- fprintf (stderr ,"dumpOneFunc(): BEGIN command failed\n" );
2242+ fprintf (stderr ,"dumpOneFunc(): BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
22472243exit_nicely (g_conn );
22482244}
22492245PQclear (res );
@@ -2255,7 +2251,7 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
22552251if (!res ||
22562252PQresultStatus (res )!= PGRES_TUPLES_OK )
22572253{
2258- fprintf (stderr ,"dumpOneFunc(): SELECT for procedural language failed\n" );
2254+ fprintf (stderr ,"dumpOneFunc(): SELECT for procedural language failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
22592255exit_nicely (g_conn );
22602256}
22612257nlangs = PQntuples (res );
@@ -2873,7 +2869,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
28732869res = PQexec (g_conn ,q );
28742870if (!res || PQresultStatus (res )!= PGRES_TUPLES_OK )
28752871{
2876- fprintf (stderr ,"dumpIndices(): SELECT (funcname) failed\n" );
2872+ fprintf (stderr ,"dumpIndices(): SELECT (funcname) failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
28772873exit_nicely (g_conn );
28782874}
28792875funcname = strdup (PQgetvalue (res ,0 ,
@@ -2894,7 +2890,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
28942890res = PQexec (g_conn ,q );
28952891if (!res || PQresultStatus (res )!= PGRES_TUPLES_OK )
28962892{
2897- fprintf (stderr ,"dumpIndices(): SELECT (classname) failed\n" );
2893+ fprintf (stderr ,"dumpIndices(): SELECT (classname) failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
28982894exit_nicely (g_conn );
28992895}
29002896classname [nclass ]= strdup (PQgetvalue (res ,0 ,
@@ -3059,15 +3055,15 @@ setMaxOid(FILE *fout)
30593055if (!res ||
30603056PQresultStatus (res )!= PGRES_COMMAND_OK )
30613057{
3062- fprintf (stderr ,"Can not create pgdump_oid table\n" );
3058+ fprintf (stderr ,"Can not create pgdump_oid table. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
30633059exit_nicely (g_conn );
30643060}
30653061PQclear (res );
30663062res = PQexec (g_conn ,"INSERT INTO pgdump_oid VALUES (0)" );
30673063if (!res ||
30683064PQresultStatus (res )!= PGRES_COMMAND_OK )
30693065{
3070- fprintf (stderr ,"Can not insert into pgdump_oid table\n" );
3066+ fprintf (stderr ,"Can not insert into pgdump_oid table. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
30713067exit_nicely (g_conn );
30723068}
30733069max_oid = atol (PQoidStatus (res ));
@@ -3081,7 +3077,7 @@ setMaxOid(FILE *fout)
30813077if (!res ||
30823078PQresultStatus (res )!= PGRES_COMMAND_OK )
30833079{
3084- fprintf (stderr ,"Can not drop pgdump_oid table\n" );
3080+ fprintf (stderr ,"Can not drop pgdump_oid table. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
30853081exit_nicely (g_conn );
30863082}
30873083PQclear (res );
@@ -3114,7 +3110,7 @@ findLastBuiltinOid(void)
31143110if (res == NULL ||
31153111PQresultStatus (res )!= PGRES_TUPLES_OK )
31163112{
3117- fprintf (stderr ,"pg_dump error in finding the template1 database\n" );
3113+ fprintf (stderr ,"pg_dump error in finding the template1 database. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
31183114exit_nicely (g_conn );
31193115}
31203116ntups = PQntuples (res );
@@ -3187,7 +3183,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
31873183res = PQexec (g_conn ,query );
31883184if (!res || PQresultStatus (res )!= PGRES_TUPLES_OK )
31893185{
3190- fprintf (stderr ,"dumpSequence(%s): SELECT failed\n" ,tbinfo .relname );
3186+ fprintf (stderr ,"dumpSequence(%s): SELECT failed. Explanation from backend: '%s'. \n" ,tbinfo .relname , PQerrorMessage ( g_conn ) );
31913187exit_nicely (g_conn );
31923188}
31933189
@@ -3293,7 +3289,7 @@ dumpRules(FILE *fout, const char *tablename,
32933289if (!res ||
32943290PQresultStatus (res )!= PGRES_COMMAND_OK )
32953291{
3296- fprintf (stderr ,"BEGIN command failed\n" );
3292+ fprintf (stderr ,"BEGIN command failed. Explanation from backend: '%s'. \n" , PQerrorMessage ( g_conn ) );
32973293exit_nicely (g_conn );
32983294}
32993295PQclear (res );
@@ -3311,8 +3307,8 @@ dumpRules(FILE *fout, const char *tablename,
33113307if (!res ||
33123308PQresultStatus (res )!= PGRES_TUPLES_OK )
33133309{
3314- fprintf (stderr ,"dumpRules(): SELECT failed for table %s\n" ,
3315- tblinfo [t ].relname );
3310+ fprintf (stderr ,"dumpRules(): SELECT failed for table %s. Explanation from backend: '%s'. \n" ,
3311+ tblinfo [t ].relname , PQerrorMessage ( g_conn ) );
33163312exit_nicely (g_conn );
33173313}
33183314