Skip to content
Permalink
Browse files

[db manager] Fix virtual layer uid handling

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Nov 22, 2016
1 parent 2894236 commit b7fa5400b67cb91bb9e661dc734433de010e895f
Showing with 7 additions and 6 deletions.
  1. +7 −6 python/plugins/db_manager/db_plugins/vlayers/plugin.py
@@ -24,7 +24,7 @@

from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsVirtualLayerDefinition

from ..plugin import DBPlugin, Database, Table, VectorTable, TableField

@@ -100,13 +100,14 @@ def sqlResultModel(self, sql, parent):
return LSqlResultModel(self, sql, parent)

def toSqlLayer(self, sql, geomCol, uniqueCol, layerName="QueryLayer", layerType=None, avoidSelectById=False, _filter=""):
q = QUrl.toPercentEncoding(sql)
s = "?query=%s" % q
df = QgsVirtualLayerDefinition()
df.setQuery(sql)
if uniqueCol is not None:
s += "&uid=" + uniqueCol
uniqueCol = uniqueCol.strip('"').replace('""', '"')
df.setUid(uniqueCol)
if geomCol is not None:
s += "&geometry=" + geomCol
vl = QgsVectorLayer(s, layerName, "virtual")
df.setGeometryField(geomCol)
vl = QgsVectorLayer(df.toString(), layerName, "virtual")
if _filter:
vl.setSubsetString(_filter)
return vl

0 comments on commit b7fa540

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