Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spatialite uniquevalues with bigint #33992

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteprovider.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()