Skip to content
Permalink
Browse files

Merge pull request #4195 from mhugo/fix_vlayers

[virtual layers] Fix encoding issues in dbmanager
  • Loading branch information
Hugo Mercier
Hugo Mercier committed Feb 27, 2017
2 parents 0eccc89 + f56e6b9 commit 887ca6f95ac750a894e9dd6a7886250a02aa842b
@@ -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():
@@ -116,7 +116,7 @@ namespace QgsVirtualLayerQueryParser
int pos = geometryTypeRx.indexIn( columnType, 0 );
if ( pos != -1 )
{
QgsWkbTypes::Type type = static_cast<QgsWkbTypes::Type>( geometryTypeRx.cap( 1 ).toInt() );
QgsWkbTypes::Type type = static_cast<QgsWkbTypes::Type>( geometryTypeRx.cap( 1 ).toLong() );
long srid = geometryTypeRx.cap( 2 ).toLong();
d.setGeometry( type );
d.setSrid( srid );

0 comments on commit 887ca6f

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