Skip to content
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/
@@ -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()
if uniqueCol is not None:
s += "&uid=" + uniqueCol
uniqueCol = uniqueCol.strip('"').replace('""', '"')
if geomCol is not None:
s += "&geometry=" + geomCol
vl = QgsVectorLayer(s, layerName, "virtual")
vl = QgsVectorLayer(df.toString(), layerName, "virtual")
if _filter:
return vl

0 comments on commit b7fa540

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