Skip to content

Commit b7fa540

Browse files
author
Hugo Mercier
committedNov 22, 2016
[db manager] Fix virtual layer uid handling
1 parent 2894236 commit b7fa540

File tree

1 file changed

+7
-6
lines changed
  • python/plugins/db_manager/db_plugins/vlayers

1 file changed

+7
-6
lines changed
 

‎python/plugins/db_manager/db_plugins/vlayers/plugin.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from qgis.PyQt.QtCore import QUrl
2626
from qgis.PyQt.QtGui import QIcon
27-
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
27+
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsVirtualLayerDefinition
2828

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

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

102102
def toSqlLayer(self, sql, geomCol, uniqueCol, layerName="QueryLayer", layerType=None, avoidSelectById=False, _filter=""):
103-
q = QUrl.toPercentEncoding(sql)
104-
s = "?query=%s" % q
103+
df = QgsVirtualLayerDefinition()
104+
df.setQuery(sql)
105105
if uniqueCol is not None:
106-
s += "&uid=" + uniqueCol
106+
uniqueCol = uniqueCol.strip('"').replace('""', '"')
107+
df.setUid(uniqueCol)
107108
if geomCol is not None:
108-
s += "&geometry=" + geomCol
109-
vl = QgsVectorLayer(s, layerName, "virtual")
109+
df.setGeometryField(geomCol)
110+
vl = QgsVectorLayer(df.toString(), layerName, "virtual")
110111
if _filter:
111112
vl.setSubsetString(_filter)
112113
return vl

0 commit comments

Comments
 (0)
Please sign in to comment.