Skip to content

Commit 3899f56

Browse files
authored
Merge pull request #11532 from OSGeo/backport-11528-to-release/3.10
[Backport release/3.10] GPKG: fix FID vs field of same name consistency check when field is not set
2 parents bcc643d + 02c9d70 commit 3899f56

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

autotest/ogr/ogr_gpkg.py

+5
Original file line numberDiff line numberDiff line change
@@ -4980,6 +4980,11 @@ def test_ogr_gpkg_creation_fid(tmp_vsimem):
49804980
assert lyr.SetFeature(f) == ogr.OGRERR_NONE
49814981
f = None
49824982

4983+
f = ogr.Feature(lyr.GetLayerDefn())
4984+
f.SetFID(14)
4985+
assert lyr.CreateFeature(f) == ogr.OGRERR_NONE
4986+
assert f.GetFID() == 14
4987+
49834988
lyr = ds.CreateLayer("fid_integer64")
49844989
assert lyr.CreateField(ogr.FieldDefn("fid", ogr.OFTInteger64)) == ogr.OGRERR_NONE
49854990

ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ void OGRGeoPackageTableLayer::CheckGeometryType(const OGRFeature *poFeature)
22172217
static bool CheckFIDAndFIDColumnConsistency(const OGRFeature *poFeature,
22182218
int iFIDAsRegularColumnIndex)
22192219
{
2220-
bool ok = false;
2220+
bool ok = true;
22212221
if (!poFeature->IsFieldSetAndNotNull(iFIDAsRegularColumnIndex))
22222222
{
22232223
// nothing to do
@@ -2231,21 +2231,26 @@ static bool CheckFIDAndFIDColumnConsistency(const OGRFeature *poFeature,
22312231
if (GDALIsValueInRange<int64_t>(dfFID))
22322232
{
22332233
const auto nFID = static_cast<GIntBig>(dfFID);
2234-
if (nFID == poFeature->GetFID())
2234+
if (nFID != poFeature->GetFID())
22352235
{
2236-
ok = true;
2236+
ok = false;
2237+
CPLError(CE_Failure, CPLE_AppDefined,
2238+
"Inconsistent values of FID (" CPL_FRMT_GIB
2239+
") and field of same name (%g)",
2240+
poFeature->GetFID(),
2241+
poFeature->GetFieldAsDouble(iFIDAsRegularColumnIndex));
22372242
}
22382243
}
22392244
}
2240-
else if (poFeature->GetFieldAsInteger64(iFIDAsRegularColumnIndex) ==
2245+
else if (poFeature->GetFieldAsInteger64(iFIDAsRegularColumnIndex) !=
22412246
poFeature->GetFID())
22422247
{
2243-
ok = true;
2244-
}
2245-
if (!ok)
2246-
{
2248+
ok = false;
22472249
CPLError(CE_Failure, CPLE_AppDefined,
2248-
"Inconsistent values of FID and field of same name");
2250+
"Inconsistent values of FID (" CPL_FRMT_GIB
2251+
") and field of same name (" CPL_FRMT_GIB ")",
2252+
poFeature->GetFID(),
2253+
poFeature->GetFieldAsInteger64(iFIDAsRegularColumnIndex));
22492254
}
22502255
return ok;
22512256
}

0 commit comments

Comments
 (0)