GPKG: fix FID vs field of same name consistency check when field is not set
Related to #11527
This commit is contained in:
parent
e7b6c09d3b
commit
84ae5447d6
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue