File tree 1 file changed +25
-6
lines changed
1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -1423,20 +1423,39 @@ bool QgsPostgresProvider::determinePrimaryKey()
1423
1423
else if ( type == " v" ) // the relation is a view
1424
1424
{
1425
1425
QString primaryKey = mUri .keyColumn ();
1426
- int idx = fieldNameIndex ( mUri . keyColumn () ) ;
1426
+ mPrimaryKeyType = pktUnknown ;
1427
1427
1428
- if ( idx >= 0 && ( mAttributeFields [idx]. type () == QVariant::Int || mAttributeFields [idx]. type () == QVariant::LongLong ) )
1428
+ if ( !primaryKey. isEmpty ( ) )
1429
1429
{
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
1431
1452
{
1432
- mPrimaryKeyType = pktInt;
1433
- mPrimaryKeyAttrs << idx;
1453
+ QgsMessageLog::logMessage ( tr ( " Key field '%1' for view not found." ).arg ( primaryKey ), tr ( " PostGIS" ) );
1434
1454
}
1435
1455
}
1436
1456
else
1437
1457
{
1438
1458
QgsMessageLog::logMessage ( tr ( " No key field for view given." ), tr ( " PostGIS" ) );
1439
- mPrimaryKeyType = pktUnknown;
1440
1459
}
1441
1460
}
1442
1461
else
You can’t perform that action at this time.
0 commit comments