Skip to content
Permalink
Browse files

When loading a query as a postgis layer the primary key may now also …

…span multiple columns.
  • Loading branch information
SebDieBln authored and jef-n committed Oct 17, 2015
1 parent a721949 commit a4124da2a95c30f8d9facfa701a092d1d73368aa
Showing with 5 additions and 20 deletions.
  1. +5 −20 src/providers/postgres/qgspostgresprovider.cpp
@@ -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;
@@ -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;
}
@@ -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" ) );
}
}

0 comments on commit a4124da

Please sign in to comment.
You can’t perform that action at this time.