Skip to content

Commit

Permalink
When loading a query as a postgis layer the primary key may now also …
Browse files Browse the repository at this point in the history
…span multiple columns.
  • Loading branch information
SebDieBln authored and jef-n committed Oct 17, 2015
1 parent a721949 commit a4124da
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,22 +1219,7 @@ bool QgsPostgresProvider::determinePrimaryKey()
}
else
{
QString primaryKey = mUri.keyColumn();
int idx = fieldNameIndex( mUri.keyColumn() );

if ( idx >= 0 && ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong ) )
{
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
mPrimaryKeyType = pktInt;
mPrimaryKeyAttrs << idx;
}
}
else
{
QgsMessageLog::logMessage( tr( "No key field for query given." ), tr( "PostGIS" ) );
mPrimaryKeyType = pktUnknown;
}
determinePrimaryKeyFromUriKeyColumn();
}

mValid = mPrimaryKeyType != pktUnknown;
Expand Down Expand Up @@ -1299,7 +1284,7 @@ void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn()
int idx = fieldNameIndex( col );
if ( idx < 0 )
{
QgsMessageLog::logMessage( tr( "Key field '%1' for view not found." ).arg( col ), tr( "PostGIS" ) );
QgsMessageLog::logMessage( tr( "Key field '%1' for view/query not found." ).arg( col ), tr( "PostGIS" ) );
mPrimaryKeyAttrs.clear();
break;
}
Expand All @@ -1315,17 +1300,17 @@ void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn()
}
else
{
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view not unique." ).arg( primaryKey ), tr( "PostGIS" ) );
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view/query not unique." ).arg( primaryKey ), tr( "PostGIS" ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "Keys for view undefined." ).arg( primaryKey ), tr( "PostGIS" ) );
QgsMessageLog::logMessage( tr( "Keys for view/query undefined." ).arg( primaryKey ), tr( "PostGIS" ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "No key field for view given." ), tr( "PostGIS" ) );
QgsMessageLog::logMessage( tr( "No key field for view/query given." ), tr( "PostGIS" ) );
}
}

Expand Down

0 comments on commit a4124da

Please sign in to comment.