Skip to content

Commit

Permalink
postgres provider: skip IN when feature id list is empty (followup fe…
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 8, 2015
1 parent 7e79398 commit a181845
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -558,20 +558,27 @@ QString QgsPostgresUtils::whereClause( const QgsFeatureIds& featureIds, const Qg
case pktOid:
case pktInt:
{
//simple primary key, so prefer to use an "IN (...)" query. These are much faster then multiple chained ...OR... clauses
QString delim;
QString expr = QString( "%1 IN (" ).arg(( pkType == pktOid ? "oid" : QgsPostgresConn::quotedIdentifier( fields[ pkAttrs[0] ].name() ) ) );
QString expr;

Q_FOREACH ( const QgsFeatureId featureId, featureIds )
//simple primary key, so prefer to use an "IN (...)" query. These are much faster then multiple chained ...OR... clauses
if ( !featureIds.isEmpty() )
{
expr += delim + QString::number( featureId );
delim = ',';
QString delim;
expr = QString( "%1 IN (" ).arg(( pkType == pktOid ? "oid" : QgsPostgresConn::quotedIdentifier( fields[ pkAttrs[0] ].name() ) ) );

Q_FOREACH ( const QgsFeatureId featureId, featureIds )
{
expr += delim + FID_TO_STRING( featureId );
delim = ',';
}
expr += ')';
}
expr += ')';

return expr;
}
default:
case pktFidMap:
case pktTid:
case pktUnknown:
{
//complex primary key, need to build up where string
QStringList whereClauses;
Expand Down

0 comments on commit a181845

Please sign in to comment.