@@ -1550,72 +1550,76 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster)
1550
1550
}
1551
1551
1552
1552
/*
1553
- * Verify that no tables are declared WITH OIDS.
1553
+ * Callback function for processing results of query for
1554
+ * check_for_tables_with_oids()'s UpgradeTask. If the query returned any rows
1555
+ * (i.e., the check failed), write the details to the report file.
1554
1556
*/
1555
1557
static void
1556
- check_for_tables_with_oids ( ClusterInfo * cluster )
1558
+ process_with_oids_check ( DbInfo * dbinfo , PGresult * res , void * arg )
1557
1559
{
1558
- int dbnum ;
1559
- FILE * script = NULL ;
1560
- char output_path [MAXPGPATH ];
1560
+ UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
1561
+ bool db_used = false;
1562
+ int ntups = PQntuples (res );
1563
+ int i_nspname = PQfnumber (res , "nspname" );
1564
+ int i_relname = PQfnumber (res , "relname" );
1561
1565
1562
- prep_status ( "Checking for tables WITH OIDS" );
1566
+ AssertVariableIsOfType ( & process_with_oids_check , UpgradeTaskProcessCB );
1563
1567
1564
- snprintf (output_path , sizeof (output_path ), "%s/%s" ,
1565
- log_opts .basedir ,
1566
- "tables_with_oids.txt" );
1568
+ if (!ntups )
1569
+ return ;
1567
1570
1568
- /* Find any tables declared WITH OIDS */
1569
- for (dbnum = 0 ; dbnum < cluster -> dbarr .ndbs ; dbnum ++ )
1571
+ for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1570
1572
{
1571
- PGresult * res ;
1572
- bool db_used = false;
1573
- int ntups ;
1574
- int rowno ;
1575
- int i_nspname ,
1576
- i_relname ;
1577
- DbInfo * active_db = & cluster -> dbarr .dbs [dbnum ];
1578
- PGconn * conn = connectToServer (cluster , active_db -> db_name );
1579
-
1580
- res = executeQueryOrDie (conn ,
1581
- "SELECT n.nspname, c.relname "
1582
- "FROM pg_catalog.pg_class c, "
1583
- " pg_catalog.pg_namespace n "
1584
- "WHERE c.relnamespace = n.oid AND "
1585
- " c.relhasoids AND"
1586
- " n.nspname NOT IN ('pg_catalog')" );
1587
-
1588
- ntups = PQntuples (res );
1589
- i_nspname = PQfnumber (res , "nspname" );
1590
- i_relname = PQfnumber (res , "relname" );
1591
- for (rowno = 0 ; rowno < ntups ; rowno ++ )
1573
+ if (report -> file == NULL &&
1574
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1575
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1576
+ if (!db_used )
1592
1577
{
1593
- if (script == NULL && (script = fopen_priv (output_path , "w" )) == NULL )
1594
- pg_fatal ("could not open file \"%s\": %m" , output_path );
1595
- if (!db_used )
1596
- {
1597
- fprintf (script , "In database: %s\n" , active_db -> db_name );
1598
- db_used = true;
1599
- }
1600
- fprintf (script , " %s.%s\n" ,
1601
- PQgetvalue (res , rowno , i_nspname ),
1602
- PQgetvalue (res , rowno , i_relname ));
1578
+ fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1579
+ db_used = true;
1603
1580
}
1581
+ fprintf (report -> file , " %s.%s\n" ,
1582
+ PQgetvalue (res , rowno , i_nspname ),
1583
+ PQgetvalue (res , rowno , i_relname ));
1584
+ }
1585
+ }
1604
1586
1605
- PQclear (res );
1587
+ /*
1588
+ * Verify that no tables are declared WITH OIDS.
1589
+ */
1590
+ static void
1591
+ check_for_tables_with_oids (ClusterInfo * cluster )
1592
+ {
1593
+ UpgradeTaskReport report ;
1594
+ UpgradeTask * task = upgrade_task_create ();
1595
+ const char * query = "SELECT n.nspname, c.relname "
1596
+ "FROM pg_catalog.pg_class c, "
1597
+ " pg_catalog.pg_namespace n "
1598
+ "WHERE c.relnamespace = n.oid AND "
1599
+ " c.relhasoids AND"
1600
+ " n.nspname NOT IN ('pg_catalog')" ;
1606
1601
1607
- PQfinish (conn );
1608
- }
1602
+ prep_status ("Checking for tables WITH OIDS" );
1609
1603
1610
- if (script )
1604
+ report .file = NULL ;
1605
+ snprintf (report .path , sizeof (report .path ), "%s/%s" ,
1606
+ log_opts .basedir ,
1607
+ "tables_with_oids.txt" );
1608
+
1609
+ upgrade_task_add_step (task , query , process_with_oids_check ,
1610
+ true, & report );
1611
+ upgrade_task_run (task , cluster );
1612
+ upgrade_task_free (task );
1613
+
1614
+ if (report .file )
1611
1615
{
1612
- fclose (script );
1616
+ fclose (report . file );
1613
1617
pg_log (PG_REPORT , "fatal" );
1614
1618
pg_fatal ("Your installation contains tables declared WITH OIDS, which is not\n"
1615
1619
"supported anymore. Consider removing the oid column using\n"
1616
1620
" ALTER TABLE ... SET WITHOUT OIDS;\n"
1617
1621
"A list of tables with the problem is in the file:\n"
1618
- " %s" , output_path );
1622
+ " %s" , report . path );
1619
1623
}
1620
1624
else
1621
1625
check_ok ();
0 commit comments