Skip to content

Commit

Permalink
[db manager] Fix virtual layer uid handling
Browse files Browse the repository at this point in the history
Hugo Mercier committed Nov 22, 2016
1 parent 2894236 commit b7fa540
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions python/plugins/db_manager/db_plugins/vlayers/plugin.py
Original file line number Diff line number Diff line change
@@ -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.