[ogr] Fix quoted identifier logic for sqlite-based drivers

This commit is contained in:
Mathieu Pellerin 2024-09-08 14:55:41 +07:00
parent ed15dacef9
commit d904c10cae
3 changed files with 26 additions and 0 deletions

View File

@ -1314,6 +1314,11 @@ QByteArray QgsOgrProviderUtils::quotedIdentifier( QByteArray field, const QStrin
field.replace( '`', "``" );
return field.prepend( '`' ).append( '`' );
}
else if ( driverName == QLatin1String( "GPKG" ) || driverName == QLatin1String( "SQLite" ) )
{
field.replace( '"', "\"\"" );
return field.prepend( '\"' ).append( '\"' );
}
else
{
field.replace( '\\', "\\\\" );

View File

@ -3124,6 +3124,27 @@ class TestPyQgsOGRProviderGpkg(QgisTestCase):
# for some reason that I cannto reproduce locally, featureCount returns 2
# self.assertEqual(vl.featureCount(), 1)
def testOrderByEscapedIdentifier(self):
"""Test issue GH #58508"""
tmpfile = os.path.join(self.basetestpath, 'points_escaped_identifier.gpkg')
testdata_path = unitTestDataPath('provider')
shutil.copy(os.path.join(testdata_path, 'points_escaped_identifier.gpkg'), tmpfile)
vl = QgsVectorLayer(f'{tmpfile}|layername=table\\"\\table', 'test', 'ogr')
self.assertTrue(vl.isValid())
self.assertEqual(vl.featureCount(), 3)
request = QgsFeatureRequest()
orderBy = QgsFeatureRequest.OrderBy([QgsFeatureRequest.OrderByClause('NAME', False)])
request.setOrderBy(orderBy)
features = vl.getFeatures(request)
featureCount = 0
for feature in features:
featureCount = featureCount + 1
self.assertEqual(featureCount, 3)
if __name__ == '__main__':
unittest.main()

Binary file not shown.