Skip to content

Commit

Permalink
Merge pull request #41822 from kadas-albireo/gdal_isunique
Browse files Browse the repository at this point in the history
Use OGR_Fld_IsUnique if compiled against gdal-3.2.1 or newer
  • Loading branch information
manisandro committed Feb 25, 2021
2 parents 8e97626 + 1cba809 commit 984e0b1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -56,10 +56,12 @@ email : sherman at mrcc.com
#include <ogr_srs_api.h>
#include <cpl_string.h>

// Temporary solution until GDAL Unique support is available
#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3, 2, 1)
// Temporary solution for gdal < 3.2.1 without GDAL Unique support
#include "qgssqliteutils.h"
#include <sqlite3.h>
// end temporary
#endif

#include <limits>
#include <memory>
Expand Down Expand Up @@ -1110,6 +1112,7 @@ void QgsOgrProvider::loadFields()
mFirstFieldIsFid = !fidColumn.isEmpty() &&
fdef.GetFieldIndex( fidColumn ) < 0;

#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3, 2, 1)
// This is a temporary solution until GDAL Unique support is available
QSet<QString> uniqueFieldNames;

Expand All @@ -1127,6 +1130,7 @@ void QgsOgrProvider::loadFields()
}
}
}
#endif

int createdFields = 0;
if ( mFirstFieldIsFid )
Expand Down Expand Up @@ -1266,7 +1270,11 @@ void QgsOgrProvider::loadFields()
newField.setConstraints( constraints );
}

#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3, 2, 1)
if ( uniqueFieldNames.contains( OGR_Fld_GetNameRef( fldDef ) ) )
#else
if ( OGR_Fld_IsUnique( fldDef ) )
#endif
{
QgsFieldConstraints constraints = newField.constraints();
constraints.setConstraint( QgsFieldConstraints::ConstraintUnique, QgsFieldConstraints::ConstraintOriginProvider );
Expand Down

0 comments on commit 984e0b1

Please sign in to comment.