Skip to content
Permalink
Browse files

Fix extraction of ogr LayerName from database dataset URIs

See 6c53641#commitcomment-19439676
Includes testcase.

REF #15698
  • Loading branch information
strk committed Oct 17, 2016
1 parent cf83352 commit 003f10e9fc4cd263dd559b1881e521344bb53325
Showing with 19 additions and 0 deletions.
  1. +6 −0 python/plugins/processing/tests/ToolsTest.py
  2. +13 −0 python/plugins/processing/tools/vector.py
@@ -92,6 +92,12 @@ def linkTestfile(f, t):
name = vector.ogrLayerName(tmpdir + '|layername=f2|layerid=0')
self.assertEqual(name, 'f2') # layername takes precedence

name = vector.ogrLayerName('dbname=\'/tmp/x.sqlite\' table="t" (geometry) sql=')
self.assertEqual(name, 't')

name = vector.ogrLayerName('dbname=\'/tmp/x.sqlite\' table="s.t" (geometry) sql=')
self.assertEqual(name, 's.t')

def testFeatures(self):
ProcessingConfig.initialize()

@@ -513,6 +513,19 @@ def ogrConnectionString(uri):


def ogrLayerName(uri):
if 'host' in uri:
regex = re.compile('table="(.+?)\.(.+?)"')
r = regex.search(uri)
return '"' + r.groups()[0] + '.' + r.groups()[1] + '"'
elif 'dbname' in uri:
regex = re.compile('table="(.+?)"')
r = regex.search(uri)
return r.groups()[0]
elif 'layername' in uri:
regex = re.compile('(layername=)([^|]*)')
r = regex.search(uri)
return r.groups()[1]

fields = uri.split('|')
ogruri = fields[0]
fields = fields[1:]

0 comments on commit 003f10e

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