Skip to content

Commit 8bcac0f

Browse files
committedOct 17, 2016
Fix extraction of ogr LayerName from database dataset URIs
See 6c53641#commitcomment-19439676 Includes testcase. REF #15698
1 parent b940985 commit 8bcac0f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎python/plugins/processing/tests/ToolsTest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def linkTestfile(f, t):
9292
name = vector.ogrLayerName(tmpdir + '|layername=f2|layerid=0')
9393
self.assertEqual(name, 'f2') # layername takes precedence
9494

95+
name = vector.ogrLayerName('dbname=\'/tmp/x.sqlite\' table="t" (geometry) sql=')
96+
self.assertEqual(name, 't')
97+
98+
name = vector.ogrLayerName('dbname=\'/tmp/x.sqlite\' table="s.t" (geometry) sql=')
99+
self.assertEqual(name, 's.t')
100+
95101
def testFeatures(self):
96102
ProcessingConfig.initialize()
97103

‎python/plugins/processing/tools/vector.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,19 @@ def ogrConnectionString(uri):
511511

512512

513513
def ogrLayerName(uri):
514+
if 'host' in uri:
515+
regex = re.compile('table="(.+?)\.(.+?)"')
516+
r = regex.search(uri)
517+
return '"' + r.groups()[0] + '.' + r.groups()[1] + '"'
518+
elif 'dbname' in uri:
519+
regex = re.compile('table="(.+?)"')
520+
r = regex.search(uri)
521+
return r.groups()[0]
522+
elif 'layername' in uri:
523+
regex = re.compile('(layername=)([^|]*)')
524+
r = regex.search(uri)
525+
return r.groups()[1]
526+
514527
fields = uri.split('|')
515528
ogruri = fields[0]
516529
fields = fields[1:]

0 commit comments

Comments
 (0)
Please sign in to comment.