@@ -771,17 +771,36 @@ def testKey(lyr, key, kfnames):
771
771
772
772
# See https://issues.qgis.org/issues/17518
773
773
def testImportWithoutSchema (self ):
774
- self .execSQLCommand ('DROP TABLE IF EXISTS b17518 CASCADE' )
775
- uri = 'point?field=f1:int'
776
- uri += '&field=F2:double(6,4)'
777
- uri += '&field=f3:string(20)'
778
- lyr = QgsVectorLayer (uri , "x" , "memory" )
779
- self .assertTrue (lyr .isValid ())
780
774
781
- uri = "%s sslmode=disable table=\" b17518\" (geom) sql" % self .dbconn
782
- err = QgsVectorLayerExporter .exportLayer (lyr , uri , "postgres" , lyr .crs ())
783
- olyr = QgsVectorLayer (uri , "y" , "postgres" )
784
- self .assertTrue (olyr .isValid ())
775
+ def _test (table , schema = None ):
776
+ self .execSQLCommand ('DROP TABLE IF EXISTS %s CASCADE' % table )
777
+ uri = 'point?field=f1:int'
778
+ uri += '&field=F2:double(6,4)'
779
+ uri += '&field=f3:string(20)'
780
+ lyr = QgsVectorLayer (uri , "x" , "memory" )
781
+ self .assertTrue (lyr .isValid ())
782
+
783
+ table = ("%s" % table ) if schema is None else ("\" %s\" .\" %s\" " % (schema , table ))
784
+ dest_uri = "%s sslmode=disable table=%s (geom) sql" % (self .dbconn , table )
785
+ err = QgsVectorLayerExporter .exportLayer (lyr , dest_uri , "postgres" , lyr .crs ())
786
+ olyr = QgsVectorLayer (dest_uri , "y" , "postgres" )
787
+ self .assertTrue (olyr .isValid (), "Failed URI: %s" % dest_uri )
788
+
789
+ # Test bug 17518
790
+ _test ('b17518' )
791
+
792
+ # Test fully qualified table (with schema)
793
+ _test ("b17518" , "qgis_test" )
794
+
795
+ # Test empty schema
796
+ _test ("b17518" , "" )
797
+
798
+ # Test public schema
799
+ _test ("b17518" , "public" )
800
+
801
+ # Test fully qualified table (with wrong schema)
802
+ with self .assertRaises (AssertionError ):
803
+ _test ("b17518" , "qgis_test_wrong" )
785
804
786
805
def testStyle (self ):
787
806
self .execSQLCommand ('DROP TABLE IF EXISTS layer_styles CASCADE' )
0 commit comments