Skip to content

Commit

Permalink
Fix extraction of ogr LayerName from database dataset URIs
Browse files Browse the repository at this point in the history
See 6c53641#commitcomment-19439676
Includes testcase.

REF #15698
  • Loading branch information
strk committed Oct 17, 2016
1 parent cf83352 commit 003f10e
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
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
13 changes: 13 additions & 0 deletions python/plugins/processing/tools/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down

0 comments on commit 003f10e

Please sign in to comment.