Skip to content

Commit

Permalink
[bugfix] Browser panel D&D a layer onto a postgresql connection tree …
Browse files Browse the repository at this point in the history
…node icon fails without notice

Fixes #17518 by defaulting to "public" if no schema is given
  • Loading branch information
elpaso committed Nov 22, 2017
1 parent db3c93c commit 23dfb1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3696,7 +3696,7 @@ QgsVectorLayerExporter::ExportError QgsPostgresProvider::createEmptyLayer( const
{
// populate members from the uri structure
QgsDataSourceUri dsUri( uri );
QString schemaName = dsUri.schema();
QString schemaName = dsUri.schema().isEmpty() ? QStringLiteral( "public" ) : dsUri.schema();
QString tableName = dsUri.table();

QString geometryColumn = dsUri.geometryColumn();
Expand Down
18 changes: 18 additions & 0 deletions tests/src/python/test_provider_postgres.py
@@ -1,10 +1,14 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for the postgres provider.
Note: to prepare the DB, you need to run the sql files specified in
tests/testdata/provider/testdata_pg.sh
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from builtins import next
__author__ = 'Matthias Kuhn'
Expand Down Expand Up @@ -765,6 +769,20 @@ def testKey(lyr, key, kfnames):
testKey(lyr, '"f1","F2","f3"', ['f1', 'F2', 'f3'])
testKey(lyr, None, ['id'])

# See https://issues.qgis.org/issues/17518
def testImportWithoutSchema(self):
self.execSQLCommand('DROP TABLE IF EXISTS b17518 CASCADE')
uri = 'point?field=f1:int'
uri += '&field=F2:double(6,4)'
uri += '&field=f3:string(20)'
lyr = QgsVectorLayer(uri, "x", "memory")
self.assertTrue(lyr.isValid())

uri = "%s sslmode=disable table=\"b17518\" (geom) sql" % self.dbconn
err = QgsVectorLayerExporter.exportLayer(lyr, uri, "postgres", lyr.crs())
olyr = QgsVectorLayer(uri, "y", "postgres")
self.assertTrue(olyr.isValid())

def testStyle(self):
self.execSQLCommand('DROP TABLE IF EXISTS layer_styles CASCADE')

Expand Down

0 comments on commit 23dfb1d

Please sign in to comment.