@@ -76,10 +76,10 @@ def setUpClass(cls):
76
76
sql = "SELECT AddGeometryColumn('test_q', 'geometry', 4326, 'POLYGON', 'XY')"
77
77
cur .execute (sql )
78
78
sql = "INSERT INTO test_q (id, name, geometry) "
79
- sql += "VALUES (1 , 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
79
+ sql += "VALUES (11 , 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
80
80
cur .execute (sql )
81
81
sql = "INSERT INTO test_q (id, name, geometry) "
82
- sql += "VALUES (2 , 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
82
+ sql += "VALUES (21 , 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
83
83
cur .execute (sql )
84
84
85
85
# simple table with a geometry column named 'Geometry'
@@ -150,32 +150,31 @@ def test_queries(self):
150
150
"""Test loading of query-based layers"""
151
151
152
152
# a query with a geometry, but no unique id
153
- # this allows to load a query without unique id
154
- # however, functions relying on such a unique id would fail
153
+ # the id will be autoincremented
155
154
l = QgsVectorLayer ("dbname=%s table='(select * from test_q)' (geometry)" % self .dbname , "test_pg_query1" , "spatialite" )
156
155
assert (l .isValid ())
157
- # the id() is not consistent
156
+ # the id() is autoincremented
158
157
sum_id1 = sum (f .id () for f in l .getFeatures ())
159
158
# the attribute 'id' works
160
159
sum_id2 = sum (f .attributes ()[0 ] for f in l .getFeatures ())
161
- assert (sum_id1 == 0 )
162
- assert (sum_id2 == 3 )
160
+ assert (sum_id1 == 3 ) # 1+2
161
+ assert (sum_id2 == 32 ) # 11 + 21
163
162
164
163
# and now with an id declared
165
164
l = QgsVectorLayer ("dbname=%s table='(select * from test_q)' (geometry) key='id'" % self .dbname , "test_pg_query1" , "spatialite" )
166
165
assert (l .isValid ())
167
166
sum_id1 = sum (f .id () for f in l .getFeatures ())
168
167
sum_id2 = sum (f .attributes ()[0 ] for f in l .getFeatures ())
169
- assert (sum_id1 == 3 )
170
- assert (sum_id2 == 3 )
168
+ assert (sum_id1 == 32 )
169
+ assert (sum_id2 == 32 )
171
170
172
171
# a query, but no geometry
173
172
l = QgsVectorLayer ("dbname=%s table='(select id,name from test_q)' key='id'" % self .dbname , "test_pg_query1" , "spatialite" )
174
173
assert (l .isValid ())
175
174
sum_id1 = sum (f .id () for f in l .getFeatures ())
176
175
sum_id2 = sum (f .attributes ()[0 ] for f in l .getFeatures ())
177
- assert (sum_id1 == 3 )
178
- assert (sum_id2 == 3 )
176
+ assert (sum_id1 == 32 )
177
+ assert (sum_id2 == 32 )
179
178
180
179
def test_case (self ):
181
180
"""Test case sensitivity issues"""
0 commit comments