@@ -654,14 +654,14 @@ def testVectorLayerUtilsCreateFeatureWithProviderDefaultLiteral(self):
654
654
f = QgsVectorLayerUtils .createFeature (vl )
655
655
self .assertEqual (f .attributes (), [None , "qgis 'is good" , 5 , 5.7 , None ])
656
656
657
- # check that provider default literals take precedence over passed attribute values
657
+ # check that provider default literals do not take precedence over passed attribute values
658
658
f = QgsVectorLayerUtils .createFeature (vl , attributes = {1 : 'qgis is great' , 0 : 3 })
659
- self .assertEqual (f .attributes (), [3 , "qgis ' is good " , 5 , 5.7 , None ])
659
+ self .assertEqual (f .attributes (), [3 , "qgis is great " , 5 , 5.7 , None ])
660
660
661
661
# test that vector layer default value expression overrides provider default literal
662
662
vl .setDefaultValueDefinition (3 , QgsDefaultValue ("4*3" ))
663
663
f = QgsVectorLayerUtils .createFeature (vl , attributes = {1 : 'qgis is great' , 0 : 3 })
664
- self .assertEqual (f .attributes (), [3 , "qgis ' is good " , 5 , 12 , None ])
664
+ self .assertEqual (f .attributes (), [3 , "qgis is great " , 5 , 12 , None ])
665
665
666
666
def testCreateAttributeIndex (self ):
667
667
vl = QgsVectorLayer ("dbname=%s table='test_defaults' key='id'" % self .dbname , "test_defaults" , "spatialite" )
@@ -848,6 +848,18 @@ def _check_features(vl, offset):
848
848
self .assertTrue (vl_no_pk .isValid ())
849
849
_check_features (vl_no_pk , 10 )
850
850
851
+ def testAliasedQueries (self ):
852
+ """Test regression when sending queries with aliased tables from DB manager"""
853
+
854
+ def _test (sql ):
855
+ vl = QgsVectorLayer ('dbname=\' {}/provider/spatialite.db\' table="{}" (geom) sql=' .format (TEST_DATA_DIR , sql ), 'test' , 'spatialite' )
856
+ self .assertTrue (vl .isValid ())
857
+
858
+ _test ("(SELECT * FROM somedata as my_alias\n )" )
859
+ _test ("(SELECT * FROM somedata as my_alias)" )
860
+ _test ("(SELECT * FROM somedata AS my_alias)" )
861
+ _test ('(SELECT * FROM \\ "somedata\\ " as my_alias\n )' )
862
+
851
863
852
864
if __name__ == '__main__' :
853
865
unittest .main ()
0 commit comments