Skip to content

Commit

Permalink
[OGR] Handle mFirstFieldIsFid in renameAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 2, 2016
1 parent 831f4c1 commit 732b1cb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,14 +1339,26 @@ bool QgsOgrProvider::renameAttributes( const QgsFieldNameMap& renamedAttributes
result = false;
continue;
}
int ogrFieldIndex = fieldIndex;
if ( mFirstFieldIsFid )
{
ogrFieldIndex -= 1;
if ( ogrFieldIndex < 0 )
{
pushError( tr( "Invalid attribute index" ) );
result = false;
continue;
}
}

//type does not matter, it will not be used
OGRFieldDefnH fld = OGR_Fld_Create( mEncoding->fromUnicode( renameIt.value() ), OFTReal );
if ( OGR_L_AlterFieldDefn( ogrLayer, fieldIndex, fld, ALTER_NAME_FLAG ) != OGRERR_NONE )
if ( OGR_L_AlterFieldDefn( ogrLayer, ogrFieldIndex, fld, ALTER_NAME_FLAG ) != OGRERR_NONE )
{
pushError( tr( "OGR error renaming field %1: %2" ).arg( fieldIndex ).arg( CPLGetLastErrorMsg() ) );
result = false;
}
OGR_Fld_Destroy( fld );
}
loadFields();
return result;
Expand Down

0 comments on commit 732b1cb

Please sign in to comment.