Skip to content
Permalink
Browse files

[OGR provider] Support 64bit FID (partially implemented per 8f3d44d i…

…n master) (fixes #16404)
  • Loading branch information
rouault committed Nov 13, 2017
1 parent e1f5348 commit 2c49631bc98da90d1657005abfd1fe6ca7a88d2b
Showing with 33 additions and 1 deletion.
  1. +1 −1 src/providers/ogr/qgsogrprovider.cpp
  2. +32 −0 tests/src/python/test_provider_ogr_gpkg.py
@@ -1807,7 +1807,7 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )

for ( QgsGeometryMap::const_iterator it = geometry_map.constBegin(); it != geometry_map.constEnd(); ++it )
{
gdal::ogr_feature_unique_ptr theOGRFeature( mOgrLayer->GetFeature( static_cast<long>( FID_TO_NUMBER( it.key() ) ) ) );
gdal::ogr_feature_unique_ptr theOGRFeature( mOgrLayer->GetFeature( FID_TO_NUMBER( it.key() ) ) );
if ( !theOGRFeature )
{
pushError( tr( "OGR error changing geometry: feature %1 not found" ).arg( it.key() ) );
@@ -600,6 +600,38 @@ def testGeopackageRefreshIfTableListUpdated(self):
vl2.subLayers()
self.assertEqual(vl2.dataProvider().subLayers(), ['0:test:0:Point:geom', '1:test2:0:Point:geom'])

def testGeopackageLargeFID(self):

tmpfile = os.path.join(self.basetestpath, 'testGeopackageLargeFID.gpkg')
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
lyr = ds.CreateLayer('test', geom_type=ogr.wkbPoint)
lyr.CreateField(ogr.FieldDefn('str_field', ogr.OFTString))
ds = None

vl = QgsVectorLayer(u'{}'.format(tmpfile) + "|layername=" + "test", 'test', u'ogr')
f = QgsFeature()
f.setAttributes([1234567890123, None])
self.assertTrue(vl.startEditing())
self.assertTrue(vl.dataProvider().addFeatures([f]))
self.assertTrue(vl.commitChanges())

got = [feat for feat in vl.getFeatures()][0]
self.assertEqual(got['fid'], 1234567890123)

self.assertTrue(vl.startEditing())
self.assertTrue(vl.changeGeometry(1234567890123, QgsGeometry.fromWkt('Point (3 50)')))
self.assertTrue(vl.changeAttributeValue(1234567890123, 1, 'foo'))
self.assertTrue(vl.commitChanges())

got = [feat for feat in vl.getFeatures()][0]
self.assertEqual(got['str_field'], 'foo')
got_geom = got.geometry()
self.assertIsNotNone(got_geom)

self.assertTrue(vl.startEditing())
self.assertTrue(vl.deleteFeature(1234567890123))
self.assertTrue(vl.commitChanges())


if __name__ == '__main__':
unittest.main()

0 comments on commit 2c49631

Please sign in to comment.
You can’t perform that action at this time.