Navigation Menu

Skip to content

Commit

Permalink
Use relkind everywhere to determine if table is a foreign table
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 6, 2023
1 parent 1b1747d commit 8d71d28
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -713,7 +713,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
int dim = result.PQgetvalue( idx, 5 ).toInt();
QString relkind = result.PQgetvalue( idx, 6 );
bool isView = relkind == QLatin1String( "v" ) || relkind == QLatin1String( "m" );
bool isForeignTable = relkind == QLatin1String( "f" );
bool isRaster = type == QLatin1String( "RASTER" );
QString comment = result.PQgetvalue( idx, 7 );
QString attributes = result.PQgetvalue( idx, 8 );
Expand Down Expand Up @@ -769,11 +768,10 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
layerProperty.sql.clear();
layerProperty.relKind = relKindFromValue( relkind );
layerProperty.isView = isView;
layerProperty.isForeignTable = isForeignTable;
layerProperty.isRaster = isRaster;
layerProperty.tableComment = comment;
layerProperty.nSpCols = nSpCols;
if ( isView || isForeignTable )
if ( isView || ( layerProperty.relKind == Qgis::PostgresRelKind::ForeignTable ) )
{
// TODO: use std::transform
for ( const auto &a : QgsPostgresStringUtils::parseArray( attributes ) )
Expand Down Expand Up @@ -877,7 +875,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
QString relkind = result.PQgetvalue( i, 3 ); // relation kind
QString coltype = result.PQgetvalue( i, 4 ); // column type
bool isView = relkind == QLatin1String( "v" ) || relkind == QLatin1String( "m" );
bool isForeignTable = relkind == QLatin1String( "f" );
QString comment = result.PQgetvalue( i, 5 ); // table comment

QgsPostgresLayerProperty layerProperty;
Expand All @@ -888,7 +885,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
layerProperty.geometryColName = column;
layerProperty.relKind = relKindFromValue( relkind );
layerProperty.isView = isView;
layerProperty.isForeignTable = isForeignTable;
layerProperty.isRaster = coltype == QLatin1String( "raster" );
layerProperty.tableComment = comment;
if ( coltype == QLatin1String( "geometry" ) )
Expand Down Expand Up @@ -919,7 +915,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP

// TODO: use knowledge from already executed query to count
// spatial fields and list attribute names...
addColumnInfo( layerProperty, schemaName, tableName, isView || isForeignTable );
addColumnInfo( layerProperty, schemaName, tableName, isView || ( layerProperty.relKind == Qgis::PostgresRelKind::ForeignTable ) );

if ( isView && layerProperty.pkCols.empty() )
{
Expand Down Expand Up @@ -982,7 +978,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
QString comment = result.PQgetvalue( i, 3 ); // table comment
QString attributes = result.PQgetvalue( i, 4 ); // attributes array
bool isView = relkind == QLatin1String( "v" ) || relkind == QLatin1String( "m" );
bool isForeignTable = relkind == QLatin1String( "f" );

QgsPostgresLayerProperty layerProperty;
layerProperty.types = QList<Qgis::WkbType>() << Qgis::WkbType::NoGeometry;
Expand All @@ -994,7 +989,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
layerProperty.nSpCols = 0;
layerProperty.relKind = relKindFromValue( relkind );
layerProperty.isView = isView;
layerProperty.isForeignTable = isForeignTable;
layerProperty.isRaster = false;
layerProperty.tableComment = comment;

Expand All @@ -1013,7 +1007,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
if ( alreadyFound )
continue;

if ( isView || isForeignTable )
if ( isView || ( layerProperty.relKind == Qgis::PostgresRelKind::ForeignTable ) )
{
// TODO: use std::transform
for ( const auto &a : QgsPostgresStringUtils::parseArray( attributes ) )
Expand Down
1 change: 0 additions & 1 deletion src/providers/postgres/qgspostgresconn.h
Expand Up @@ -84,7 +84,6 @@ struct QgsPostgresLayerProperty
QString sql;
Qgis::PostgresRelKind relKind = Qgis::PostgresRelKind::Unknown;
bool isView = false;
bool isForeignTable = false;
bool isRaster = false;
QString tableComment;

Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -550,7 +550,7 @@ QgsPGLayerItem *QgsPGSchemaItem::createLayer( QgsPostgresLayerProperty layerProp
{
tip = tr( "Raster" );
}
else if ( layerProperty.isForeignTable )
else if ( layerProperty.relKind == Qgis::PostgresRelKind::ForeignTable )
{
tip = tr( "Foreign table" );
}
Expand Down
6 changes: 4 additions & 2 deletions src/providers/postgres/qgspostgresproviderconnection.cpp
Expand Up @@ -626,7 +626,7 @@ QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnectio
{
prFlags.setFlag( QgsPostgresProviderConnection::TableFlag::MaterializedView );
}
if ( pr.isForeignTable )
if ( pr.relKind == Qgis::PostgresRelKind::ForeignTable )
{
prFlags.setFlag( QgsPostgresProviderConnection::TableFlag::Foreign );
}
Expand Down Expand Up @@ -667,7 +667,9 @@ QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnectio
property.setComment( pr.tableComment );

// Get PKs
if ( pr.isView || ( pr.relKind == Qgis::PostgresRelKind::MaterializedView ) || pr.isForeignTable )
if ( pr.isView
|| ( pr.relKind == Qgis::PostgresRelKind::MaterializedView )
|| ( pr.relKind == Qgis::PostgresRelKind::ForeignTable ) )
{
// Set the candidates
property.setPrimaryKeyColumns( pr.pkCols );
Expand Down

0 comments on commit 8d71d28

Please sign in to comment.