Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adjustments following code review.
  • Loading branch information
espinafre committed Apr 17, 2020
1 parent d4672b0 commit 9607570
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -760,7 +760,7 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
{
QVariantList pkVal;

int idx = mSource->mPrimaryKeyAttrs[0];
int idx = mSource->mPrimaryKeyAttrs.at( 0 );
QgsField fld = mSource->mFields.at( idx );

QVariant v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), QString::number( mConn->getBinaryInt( queryResult, row, col ) ), fld.typeName() );
Expand Down
15 changes: 4 additions & 11 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -76,10 +76,6 @@ QgsPostgresProvider::pkType( const QgsField &f ) const
switch ( f.type() )
{
case QVariant::LongLong:
// unless we can guarantee all values are unsigned
// (in which case we could use pktUint64)
// we'll have to use a Map type.
// See https://github.com/qgis/QGIS/issues/22258
// PostgreSQL doesn't have native "unsigned" types.
// Unsigned primary keys are emulated by the serial/bigserial
// pseudo-types, in which autogenerated values are always > 0;
Expand Down Expand Up @@ -577,7 +573,7 @@ QString QgsPostgresUtils::whereClause( QgsFeatureId featureId, const QgsFields &
QgsField fld = fields.at( pkAttrs[0] );
whereClause = conn->fieldExpression( fld );
if ( !pkVals[0].isNull() )
whereClause += "=" + pkVals[0].toString();
whereClause += '=' + pkVals[0].toString();
else
whereClause += QLatin1String( " IS NULL" );
}
Expand Down Expand Up @@ -638,8 +634,7 @@ QString QgsPostgresUtils::whereClause( const QgsFeatureIds &featureIds, const Qg
QString delim;
expr = QStringLiteral( "%1 IN (" ).arg( ( pkType == PktOid ? QStringLiteral( "oid" ) : QgsPostgresConn::quotedIdentifier( fields.at( pkAttrs[0] ).name() ) ) );

const auto constFeatureIds = featureIds;
for ( const QgsFeatureId featureId : constFeatureIds )
for ( const QgsFeatureId featureId : qgis::as_const( featureIds ) )
{
expr += delim + FID_TO_STRING( ( pkType == PktOid ? featureId : FID2PKINT( featureId ) ) );
delim = ',';
Expand All @@ -660,8 +655,7 @@ QString QgsPostgresUtils::whereClause( const QgsFeatureIds &featureIds, const Qg
QString delim;
expr = QStringLiteral( "%1 IN (" ).arg( QgsPostgresConn::quotedIdentifier( fields.at( pkAttrs[0] ).name() ) );

const auto constFeatureIds = featureIds;
for ( const QgsFeatureId featureId : constFeatureIds )
for ( const QgsFeatureId featureId : qgis::as_const( featureIds ) )
{
QVariantList pkVals = sharedData->lookupKey( featureId );
if ( !pkVals.isEmpty() )
Expand All @@ -682,8 +676,7 @@ QString QgsPostgresUtils::whereClause( const QgsFeatureIds &featureIds, const Qg
{
//complex primary key, need to build up where string
QStringList whereClauses;
const auto constFeatureIds = featureIds;
for ( const QgsFeatureId featureId : constFeatureIds )
for ( const QgsFeatureId featureId : qgis::as_const( featureIds ) )
{
whereClauses << whereClause( featureId, fields, conn, pkType, pkAttrs, sharedData );
}
Expand Down

0 comments on commit 9607570

Please sign in to comment.