Skip to content

Commit 5414031

Browse files
committed
[ogr] Rename columns with non-unique name (Fix #8385)
1 parent 8828ae1 commit 5414031

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

‎src/providers/ogr/qgsogrprovider.cpp‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,28 @@ void QgsOgrProvider::loadFields()
670670
default: varType = QVariant::String; // other unsupported, leave it as a string
671671
}
672672

673-
mAttributeFields.append(
674-
QgsField(
675-
//TODO: fix this hack
673+
//TODO: fix this hack
676674
#ifdef ANDROID
677-
OGR_Fld_GetNameRef( fldDef ),
675+
QString name = OGR_Fld_GetNameRef( fldDef );
678676
#else
679-
mEncoding->toUnicode( OGR_Fld_GetNameRef( fldDef ) ),
677+
QString name = mEncoding->toUnicode( OGR_Fld_GetNameRef( fldDef ) );
680678
#endif
679+
680+
if ( mAttributeFields.indexFromName( name ) != -1 )
681+
{
682+
683+
QString tmpname = name + "_%1";
684+
int fix = 0;
685+
686+
while ( mAttributeFields.indexFromName( name ) != -1 )
687+
{
688+
name = tmpname.arg( ++fix );
689+
}
690+
}
691+
692+
mAttributeFields.append(
693+
QgsField(
694+
name,
681695
varType,
682696
#ifdef ANDROID
683697
OGR_GetFieldTypeName( ogrType ),

0 commit comments

Comments
 (0)