Skip to content
Permalink
Browse files

Fix virtual layer file name handling (in Windows)

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Feb 15, 2016
1 parent 30910df commit 942c5e5f73c84aaf5a88ef4d38f3e32977153d3b
@@ -126,7 +126,7 @@ def _get_cursor_columns(self, c):
tf.close()

q = QUrl.toPercentEncoding(c.sql)
p = QgsVectorLayer("%s?query=%s" % (tmp, q), "vv", "virtual")
p = QgsVectorLayer("%s?query=%s" % (QUrl.fromLocalFile(tmp).toString(), q), "vv", "virtual")
if not p.isValid():
return []
f = [f.name() for f in p.fields()]
@@ -73,7 +73,7 @@ def __init__(self, db, sql, parent=None):
tmp = tf.fileName()
tf.close()

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

if not p.isValid():
@@ -168,7 +168,8 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinition::fromUrl( const QUrl& url )
QUrl QgsVirtualLayerDefinition::toUrl() const
{
QUrl url;
url.setPath( filePath() );
if ( !filePath().isEmpty() )
url = QUrl::fromLocalFile( filePath() );

Q_FOREACH ( const QgsVirtualLayerDefinition::SourceLayer& l, sourceLayers() )
{
@@ -32,11 +32,11 @@ def test1(self):
d = QgsVirtualLayerDefinition()
self.assertEqual(d.toString(), "")
d.setFilePath("/file")
self.assertEqual(d.toString(), "/file")
self.assertEqual(d.toString(), "file:///file")
self.assertEqual(QgsVirtualLayerDefinition.fromUrl(d.toUrl()).filePath(), "/file")
self.assertEqual(QgsVirtualLayerDefinition.fromUrl(QUrl.fromEncoded(d.toString())).filePath(), "/file")
d.setFilePath("C:\\file")
self.assertEqual(d.toString(), "C:%5Cfile")
self.assertEqual(d.toString(), "file:///C:%5Cfile")
self.assertEqual(QgsVirtualLayerDefinition.fromUrl(d.toUrl()).filePath(), "C:\\file")
d.setQuery("SELECT * FROM mytable")
self.assertEqual(QgsVirtualLayerDefinition.fromUrl(d.toUrl()).query(), "SELECT * FROM mytable")

0 comments on commit 942c5e5

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