Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #33992 from elpaso/bugfix-gh33585-bigint-categorized
Fix spatialite uniquevalues with bigint
  • Loading branch information
elpaso committed Jan 23, 2020
2 parents b7980f0 + 0850d99 commit 09061d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -3823,7 +3823,7 @@ QSet<QVariant> QgsSpatiaLiteProvider::uniqueValues( int index, int limit ) const
switch ( sqlite3_column_type( stmt, 0 ) )
{
case SQLITE_INTEGER:
uniqueValues.insert( QVariant( sqlite3_column_int( stmt, 0 ) ) );
uniqueValues.insert( QVariant( sqlite3_column_int64( stmt, 0 ) ) );
break;
case SQLITE_FLOAT:
uniqueValues.insert( QVariant( sqlite3_column_double( stmt, 0 ) ) );
Expand Down
22 changes: 21 additions & 1 deletion tests/src/python/test_provider_spatialite.py
Expand Up @@ -227,6 +227,18 @@ def setUpClass(cls):
sql += "VALUES (8, 'int', GeomFromText('POINT(2 1)', 4326))"
cur.execute(sql)

# bigint table
sql = "CREATE TABLE test_bigint (id BIGINT, value INT)"
cur.execute(sql)
sql = "SELECT AddGeometryColumn('test_bigint', 'position', 4326, 'LINESTRING', 'XYM')"
cur.execute(sql)
sql = """
INSERT INTO test_bigint (id, value, position) VALUES
(987654321012345, 1, ST_GeomFromtext('LINESTRINGM(10.416255 55.3786316 1577093516, 10.516255 55.4786316 157709)', 4326) ),
(987654321012346, 2, ST_GeomFromtext('LINESTRINGM(10.316255 55.3786316 1577093516, 11.216255 56.3786316 157709)', 4326) )"""

cur.execute(sql)

cur.execute("COMMIT")
con.close()

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

parts = {'path', filename, 'layerName': 'test'}
parts = {'path': filename, 'layerName': 'test'}
uri = registry.encodeUri('spatialite', parts)
self.assertEqual(uri, 'dbname=\'{}\' table="test" (geometry) sql='.format(filename))

Expand Down Expand Up @@ -1139,6 +1151,14 @@ def testGeometryTypes(self):
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), qgisType)

def testBigint(self):
"""Test unique values bigint, see GH #33585"""

l = QgsVectorLayer("dbname=%s table='test_bigint' (position) key='id'" % self.dbname, "test_bigint", "spatialite")
self.assertTrue(l.isValid())
self.assertEqual(l.uniqueValues(1), {1, 2})
self.assertEqual(l.uniqueValues(0), {987654321012345, 987654321012346})


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

0 comments on commit 09061d1

Please sign in to comment.