2 changes: 2 additions & 0 deletions src/providers/postgres/qgspgsourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
QString tableName = mTableModel.itemFromIndex( index.sibling( index.row(), QgsDbTableModel::dbtmTable ) )->text();
QString geomColumnName = mTableModel.itemFromIndex( index.sibling( index.row(), QgsDbTableModel::dbtmGeomCol ) )->text();
QString pkColumnName = mTableModel.itemFromIndex( index.sibling( index.row(), QgsDbTableModel::dbtmPkCol ) )->text();
bool selectAtId = mTableModel.itemFromIndex( index.sibling( index.row(), QgsDbTableModel::dbtmSelectAtId ) )->checkState() == Qt::Checked;
QString sql = mTableModel.itemFromIndex( index.sibling( index.row(), QgsDbTableModel::dbtmSql ) )->text();

if ( geomColumnName.contains( " AS " ) )
Expand Down Expand Up @@ -389,6 +390,7 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
QgsDataSourceURI uri( m_connInfo );
uri.setDataSource( schemaName, tableName, geomColumnName, sql, pkColumnName );
uri.setUseEstimatedMetadata( mUseEstimatedMetadata );
uri.disableSelectAtId( !selectAtId );

return uri.uri();
}
Expand Down
3 changes: 1 addition & 2 deletions src/providers/postgres/qgspgsourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
void setSql( const QModelIndex& index );
//! Store the selected database
void on_cmbConnections_activated( int );
void setLayerType( QString schema, QString table, QString column,
QString type );
void setLayerType( QString schema, QString table, QString column, QString type );
void on_mTablesTreeView_clicked( const QModelIndex &index );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
//!Sets a new regular expression to the model
Expand Down
12 changes: 10 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
, geomType( QGis::WKBUnknown )
, mFeatureQueueSize( 200 )
, mUseEstimatedMetadata( false )
, mSelectAtIdDisabled( false )
, mPrimaryKeyDefault( QString::null )
{
// assume this is a valid layer until we determine otherwise
Expand Down Expand Up @@ -463,6 +464,7 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )

primaryKey = mUri.keyColumn();
mUseEstimatedMetadata = mUri.useEstimatedMetadata();
mSelectAtIdDisabled = mUri.selectAtIdDisabled();

QgsDebugMsg( "Connection info is " + mUri.connectionInfo() );
QgsDebugMsg( "Geometry column is: " + geometryColumn );
Expand Down Expand Up @@ -1834,7 +1836,10 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()

// postgres has fast access to features at id (thanks to primary key / unique index)
// the latter flag is here just for compatibility
enabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
if ( !mSelectAtIdDisabled )
{
enabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
}

if ( !inRecovery )
{
Expand Down Expand Up @@ -1963,7 +1968,10 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
return false;
}

enabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
if ( !mSelectAtIdDisabled )
{
enabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
}
}

return true;
Expand Down
3 changes: 3 additions & 0 deletions src/providers/postgres/qgspostgresprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ class QgsPostgresProvider : public QgsVectorDataProvider
/* Use estimated metadata. Uses fast table counts, geometry type and extent determination */
bool mUseEstimatedMetadata;

/* Disable support for SelectAtId */
bool mSelectAtIdDisabled;

// Produces a QMessageBox with the given title and text. Doesn't
// return until the user has dismissed the dialog box.
static void showMessageBox( const QString& title, const QString &text );
Expand Down