diff --git a/python/plugins/processing/tests/ToolsTest.py b/python/plugins/processing/tests/ToolsTest.py index d25f3018e48..4baeb49c66f 100644 --- a/python/plugins/processing/tests/ToolsTest.py +++ b/python/plugins/processing/tests/ToolsTest.py @@ -92,6 +92,12 @@ class VectorTest(unittest.TestCase): 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() diff --git a/python/plugins/processing/tools/vector.py b/python/plugins/processing/tools/vector.py index c6e67ac4dcf..8a7e7e6ecff 100644 --- a/python/plugins/processing/tools/vector.py +++ b/python/plugins/processing/tools/vector.py @@ -533,6 +533,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:]