Skip to content

Commit

Permalink
Merge pull request #11528 from rouault/fix_11527
Browse files Browse the repository at this point in the history
GPKG: fix FID vs field of same name consistency check when field is not set
  • Loading branch information
rouault authored Dec 21, 2024
2 parents 4e36354 + 84ae544 commit b231fe7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions autotest/ogr/ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5159,6 +5159,11 @@ def test_ogr_gpkg_creation_fid(tmp_vsimem):
assert lyr.SetFeature(f) == ogr.OGRERR_NONE
f = None

f = ogr.Feature(lyr.GetLayerDefn())
f.SetFID(14)
assert lyr.CreateFeature(f) == ogr.OGRERR_NONE
assert f.GetFID() == 14

lyr = ds.CreateLayer("fid_integer64")
assert lyr.CreateField(ogr.FieldDefn("fid", ogr.OFTInteger64)) == ogr.OGRERR_NONE

Expand Down
23 changes: 14 additions & 9 deletions ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ void OGRGeoPackageTableLayer::CheckGeometryType(const OGRFeature *poFeature)
static bool CheckFIDAndFIDColumnConsistency(const OGRFeature *poFeature,
int iFIDAsRegularColumnIndex)
{
bool ok = false;
bool ok = true;
if (!poFeature->IsFieldSetAndNotNull(iFIDAsRegularColumnIndex))
{
// nothing to do
Expand All @@ -2233,21 +2233,26 @@ static bool CheckFIDAndFIDColumnConsistency(const OGRFeature *poFeature,
if (GDALIsValueInRange<int64_t>(dfFID))
{
const auto nFID = static_cast<GIntBig>(dfFID);
if (nFID == poFeature->GetFID())
if (nFID != poFeature->GetFID())
{
ok = true;
ok = false;
CPLError(CE_Failure, CPLE_AppDefined,
"Inconsistent values of FID (" CPL_FRMT_GIB
") and field of same name (%g)",
poFeature->GetFID(),
poFeature->GetFieldAsDouble(iFIDAsRegularColumnIndex));
}
}
}
else if (poFeature->GetFieldAsInteger64(iFIDAsRegularColumnIndex) ==
else if (poFeature->GetFieldAsInteger64(iFIDAsRegularColumnIndex) !=
poFeature->GetFID())
{
ok = true;
}
if (!ok)
{
ok = false;
CPLError(CE_Failure, CPLE_AppDefined,
"Inconsistent values of FID and field of same name");
"Inconsistent values of FID (" CPL_FRMT_GIB
") and field of same name (" CPL_FRMT_GIB ")",
poFeature->GetFID(),
poFeature->GetFieldAsInteger64(iFIDAsRegularColumnIndex));
}
return ok;
}
Expand Down

0 comments on commit b231fe7

Please sign in to comment.