Skip to content

Commit 09061d1

Browse files
authoredJan 23, 2020
Merge pull request #33992 from elpaso/bugfix-gh33585-bigint-categorized
Fix spatialite uniquevalues with bigint
2 parents b7980f0 + 0850d99 commit 09061d1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3823,7 +3823,7 @@ QSet<QVariant> QgsSpatiaLiteProvider::uniqueValues( int index, int limit ) const
38233823
switch ( sqlite3_column_type( stmt, 0 ) )
38243824
{
38253825
case SQLITE_INTEGER:
3826-
uniqueValues.insert( QVariant( sqlite3_column_int( stmt, 0 ) ) );
3826+
uniqueValues.insert( QVariant( sqlite3_column_int64( stmt, 0 ) ) );
38273827
break;
38283828
case SQLITE_FLOAT:
38293829
uniqueValues.insert( QVariant( sqlite3_column_double( stmt, 0 ) ) );

‎tests/src/python/test_provider_spatialite.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ def setUpClass(cls):
227227
sql += "VALUES (8, 'int', GeomFromText('POINT(2 1)', 4326))"
228228
cur.execute(sql)
229229

230+
# bigint table
231+
sql = "CREATE TABLE test_bigint (id BIGINT, value INT)"
232+
cur.execute(sql)
233+
sql = "SELECT AddGeometryColumn('test_bigint', 'position', 4326, 'LINESTRING', 'XYM')"
234+
cur.execute(sql)
235+
sql = """
236+
INSERT INTO test_bigint (id, value, position) VALUES
237+
(987654321012345, 1, ST_GeomFromtext('LINESTRINGM(10.416255 55.3786316 1577093516, 10.516255 55.4786316 157709)', 4326) ),
238+
(987654321012346, 2, ST_GeomFromtext('LINESTRINGM(10.316255 55.3786316 1577093516, 11.216255 56.3786316 157709)', 4326) )"""
239+
240+
cur.execute(sql)
241+
230242
cur.execute("COMMIT")
231243
con.close()
232244

@@ -816,7 +828,7 @@ def testEncodeUri(self):
816828
filename = '/home/to/path/test.db'
817829
registry = QgsProviderRegistry.instance()
818830

819-
parts = {'path', filename, 'layerName': 'test'}
831+
parts = {'path': filename, 'layerName': 'test'}
820832
uri = registry.encodeUri('spatialite', parts)
821833
self.assertEqual(uri, 'dbname=\'{}\' table="test" (geometry) sql='.format(filename))
822834

@@ -1139,6 +1151,14 @@ def testGeometryTypes(self):
11391151
self.assertTrue(vl.isValid())
11401152
self.assertEqual(vl.wkbType(), qgisType)
11411153

1154+
def testBigint(self):
1155+
"""Test unique values bigint, see GH #33585"""
1156+
1157+
l = QgsVectorLayer("dbname=%s table='test_bigint' (position) key='id'" % self.dbname, "test_bigint", "spatialite")
1158+
self.assertTrue(l.isValid())
1159+
self.assertEqual(l.uniqueValues(1), {1, 2})
1160+
self.assertEqual(l.uniqueValues(0), {987654321012345, 987654321012346})
1161+
11421162

11431163
if __name__ == '__main__':
11441164
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.