Skip to content
Permalink
Browse files

[bugfix] Browser panel D&D a layer onto a postgresql connection tree …

…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 23dfb1de57bfa701f4ed2a9fe1b334497732c3ba
Showing with 19 additions and 1 deletion.
  1. +1 −1 src/providers/postgres/qgspostgresprovider.cpp
  2. +18 −0 tests/src/python/test_provider_postgres.py
@@ -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();
@@ -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'
@@ -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')

0 comments on commit 23dfb1d

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