Skip to content
Permalink
Browse files

log more verbose error messages if the view primary key selection is …

…wrong.
  • Loading branch information
jef-n committed May 21, 2012
1 parent 46dba8a commit d651892bedd8881e8d06ff2fd0328eae189c57aa
Showing with 25 additions and 6 deletions.
  1. +25 −6 src/providers/postgres/qgspostgresprovider.cpp
@@ -1423,20 +1423,39 @@ bool QgsPostgresProvider::determinePrimaryKey()
else if ( type == "v" ) // the relation is a view
{
QString primaryKey = mUri.keyColumn();
int idx = fieldNameIndex( mUri.keyColumn() );
mPrimaryKeyType = pktUnknown;

if ( idx >= 0 && ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong ) )
if ( !primaryKey.isEmpty() )
{
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
int idx = fieldNameIndex( primaryKey );

if ( idx >= 0 )
{
if ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong )
{
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
mPrimaryKeyType = pktInt;
mPrimaryKeyAttrs << idx;
}
else
{
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view not unique." ).arg( primaryKey ), tr( "PostGIS" ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "Type '%1' of primary key field '%2' for view invalid." ).arg( mAttributeFields[idx].typeName() ).arg( primaryKey ), tr( "PostGIS" ) );
}
}
else
{
mPrimaryKeyType = pktInt;
mPrimaryKeyAttrs << idx;
QgsMessageLog::logMessage( tr( "Key field '%1' for view not found." ).arg( primaryKey ), tr( "PostGIS" ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "No key field for view given." ), tr( "PostGIS" ) );
mPrimaryKeyType = pktUnknown;
}
}
else

0 comments on commit d651892

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