Skip to content
Permalink
Browse files

[dbmanager] Fix encoding issues with virtual layers

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Feb 27, 2017
1 parent 23c305b commit f56e6b9d3e5f3318740ad045252d79acb6873168
@@ -26,7 +26,7 @@
from ..connector import DBConnector
from ..plugin import Table

from qgis.core import Qgis, QgsDataSourceUri, QgsVirtualLayerDefinition, QgsProject, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsWkbTypes
from qgis.core import Qgis, QgsDataSourceUri, QgsVirtualLayerDefinition, QgsProject, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsWkbTypes, QgsVirtualLayerDefinition

import sqlite3

@@ -48,7 +48,7 @@ def getQueryGeometryName(sqlite_file):
with sqlite3_connection(sqlite_file) as conn:
c = conn.cursor()
for r in c.execute("SELECT url FROM _meta"):
d = QgsVirtualLayerDefinition.fromUrl(QUrl.fromEncoded(r[0]))
d = QgsVirtualLayerDefinition.fromUrl(QUrl(r[0]))
if d.hasDefinedGeometry():
return d.geometryField()
return None
@@ -127,8 +127,10 @@ def _get_cursor_columns(self, c):
tmp = tf.fileName()
tf.close()

q = QUrl.toPercentEncoding(c.sql)
p = QgsVectorLayer("%s?query=%s" % (QUrl.fromLocalFile(tmp).toString(), q), "vv", "virtual")
df = QgsVirtualLayerDefinition()
df.setFilePath(tmp)
df.setQuery(c.sql)
p = QgsVectorLayer(df.toString(), "vv", "virtual")
if not p.isValid():
return []
f = [f.name() for f in p.fields()]
@@ -26,7 +26,7 @@
from ..plugin import DbError

from qgis.PyQt.QtCore import QUrl, QTime, QTemporaryFile
from qgis.core import Qgis, QgsVectorLayer, QgsWkbTypes, QgsWkbTypes
from qgis.core import Qgis, QgsVectorLayer, QgsWkbTypes, QgsWkbTypes, QgsVirtualLayerDefinition


class LTableDataModel(TableDataModel):
@@ -68,7 +68,6 @@ class LSqlResultModel(BaseTableModel):

def __init__(self, db, sql, parent=None):
# create a virtual layer with non-geometry results
q = QUrl.toPercentEncoding(sql)
t = QTime()
t.start()

@@ -77,7 +76,10 @@ def __init__(self, db, sql, parent=None):
tmp = tf.fileName()
tf.close()

p = QgsVectorLayer("%s?query=%s" % (QUrl.fromLocalFile(tmp).toString(), q), "vv", "virtual")
df = QgsVirtualLayerDefinition()
df.setFilePath(tmp)
df.setQuery(sql)
p = QgsVectorLayer(df.toString(), "vv", "virtual")
self._secs = t.elapsed() / 1000.0

if not p.isValid():

0 comments on commit f56e6b9

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