Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ogr] Insure that the connections pool always carry on open options
(fixes #45534)
  • Loading branch information
nirvn committed Oct 18, 2021
1 parent a81b872 commit ccba5d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/providers/ogr/qgsogrproviderutils.cpp
Expand Up @@ -957,7 +957,17 @@ QString QgsOgrProviderUtils::connectionPoolId( const QString &dataSourceURI, boo
QString filePath = dataSourceURI.left( dataSourceURI.indexOf( QLatin1Char( '|' ) ) );
QFileInfo fi( filePath );
if ( fi.isFile() )
return filePath;
{
// Preserve open options so pooled connections always carry those on
QString openOptions;
static thread_local QRegularExpression openOptionsRegex( QStringLiteral( "((?:\\|option:(?:[^|]*))+)" ) );
QRegularExpressionMatch match = openOptionsRegex.match( dataSourceURI );
if ( match.hasMatch() )
{
openOptions = match.captured( 1 );
}
return filePath + openOptions;
}
}
return dataSourceURI;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/src/python/test_provider_ogr.py
Expand Up @@ -2351,6 +2351,24 @@ def testGeoJsonFieldOrder(self):
self.assertEqual(features[1].attribute('B'), 'B')
self.assertEqual(features[1].attribute('C'), 'C')

def test_provider_feature_iterator_options(self):
"""Test issue GH #45534"""

datasource = os.path.join(self.basetestpath, 'testProviderFeatureIteratorOptions.csv')
with open(datasource, 'wt') as f:
f.write('id,Longitude,Latitude\n')
f.write('1,1.0,1.0\n')
f.write('2,2.0,2.0\n')

vl = QgsVectorLayer('{}|option:X_POSSIBLE_NAMES=Longitude|option:Y_POSSIBLE_NAMES=Latitude'.format(datasource), 'test', 'ogr')
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.Point)

f = vl.getFeature(1)
self.assertEqual(f.geometry().asWkt(), 'Point (1 1)')
f = vl.getFeature(2)
self.assertEqual(f.geometry().asWkt(), 'Point (2 2)')


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

0 comments on commit ccba5d9

Please sign in to comment.