Skip to content

Commit 732b1cb

Browse files
committedJun 2, 2016
[OGR] Handle mFirstFieldIsFid in renameAttributes
1 parent 831f4c1 commit 732b1cb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,14 +1339,26 @@ bool QgsOgrProvider::renameAttributes( const QgsFieldNameMap& renamedAttributes
13391339
result = false;
13401340
continue;
13411341
}
1342+
int ogrFieldIndex = fieldIndex;
1343+
if ( mFirstFieldIsFid )
1344+
{
1345+
ogrFieldIndex -= 1;
1346+
if ( ogrFieldIndex < 0 )
1347+
{
1348+
pushError( tr( "Invalid attribute index" ) );
1349+
result = false;
1350+
continue;
1351+
}
1352+
}
13421353

13431354
//type does not matter, it will not be used
13441355
OGRFieldDefnH fld = OGR_Fld_Create( mEncoding->fromUnicode( renameIt.value() ), OFTReal );
1345-
if ( OGR_L_AlterFieldDefn( ogrLayer, fieldIndex, fld, ALTER_NAME_FLAG ) != OGRERR_NONE )
1356+
if ( OGR_L_AlterFieldDefn( ogrLayer, ogrFieldIndex, fld, ALTER_NAME_FLAG ) != OGRERR_NONE )
13461357
{
13471358
pushError( tr( "OGR error renaming field %1: %2" ).arg( fieldIndex ).arg( CPLGetLastErrorMsg() ) );
13481359
result = false;
13491360
}
1361+
OGR_Fld_Destroy( fld );
13501362
}
13511363
loadFields();
13521364
return result;

0 commit comments

Comments
 (0)
Please sign in to comment.