Skip to content

Commit 85cf8c3

Browse files
committed
log more verbose error messages if the view primary key selection is wrong.
1 parent 4c673b1 commit 85cf8c3

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/providers/postgres/qgspostgresprovider.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -1423,20 +1423,39 @@ bool QgsPostgresProvider::determinePrimaryKey()
14231423
else if ( type == "v" ) // the relation is a view
14241424
{
14251425
QString primaryKey = mUri.keyColumn();
1426-
int idx = fieldNameIndex( mUri.keyColumn() );
1426+
mPrimaryKeyType = pktUnknown;
14271427

1428-
if ( idx >= 0 && ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong ) )
1428+
if ( !primaryKey.isEmpty() )
14291429
{
1430-
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
1430+
int idx = fieldNameIndex( primaryKey );
1431+
1432+
if ( idx >= 0 )
1433+
{
1434+
if ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong )
1435+
{
1436+
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
1437+
{
1438+
mPrimaryKeyType = pktInt;
1439+
mPrimaryKeyAttrs << idx;
1440+
}
1441+
else
1442+
{
1443+
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view not unique." ).arg( primaryKey ), tr( "PostGIS" ) );
1444+
}
1445+
}
1446+
else
1447+
{
1448+
QgsMessageLog::logMessage( tr( "Type '%1' of primary key field '%2' for view invalid." ).arg( mAttributeFields[idx].typeName() ).arg( primaryKey ), tr( "PostGIS" ) );
1449+
}
1450+
}
1451+
else
14311452
{
1432-
mPrimaryKeyType = pktInt;
1433-
mPrimaryKeyAttrs << idx;
1453+
QgsMessageLog::logMessage( tr( "Key field '%1' for view not found." ).arg( primaryKey ), tr( "PostGIS" ) );
14341454
}
14351455
}
14361456
else
14371457
{
14381458
QgsMessageLog::logMessage( tr( "No key field for view given." ), tr( "PostGIS" ) );
1439-
mPrimaryKeyType = pktUnknown;
14401459
}
14411460
}
14421461
else

0 commit comments

Comments
 (0)