Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 da0ee8b commit 52a0082
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/plugins/processing/tests/ToolsTest.py
Expand Up @@ -92,6 +92,12 @@ def linkTestfile(f, t):
name = vector.ogrLayerName(tmpdir + '|layername=f2|layerid=0') name = vector.ogrLayerName(tmpdir + '|layername=f2|layerid=0')
self.assertEqual(name, 'f2') # layername takes precedence 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): def testFeatures(self):
ProcessingConfig.initialize() ProcessingConfig.initialize()


Expand Down
13 changes: 13 additions & 0 deletions python/plugins/processing/tools/vector.py
Expand Up @@ -533,6 +533,19 @@ def ogrConnectionString(uri):




def ogrLayerName(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('|') fields = uri.split('|')
ogruri = fields[0] ogruri = fields[0]
fields = fields[1:] fields = fields[1:]
Expand Down

0 comments on commit 52a0082

Please sign in to comment.