Skip to content

Commit

Permalink
[spatialite] Fix geometry column name case sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Mercier committed Feb 13, 2015
1 parent 12a4e7d commit 221ba9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -425,7 +425,7 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )

// parsing members from the uri structure
mTableName = anUri.table();
mGeometryColumn = anUri.geometryColumn();
mGeometryColumn = anUri.geometryColumn().toLower();
mSqlitePath = anUri.database();
mSubsetString = anUri.sql();
mPrimaryKey = anUri.keyColumn();
Expand Down Expand Up @@ -612,7 +612,7 @@ void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr
while ( fld )
{
QString name = QString::fromUtf8( fld->AttributeFieldName );
if ( name != mGeometryColumn )
if ( name.toLower() != mGeometryColumn )
{
const char *type = "TEXT";
QVariant::Type fieldType = QVariant::String; // default: SQLITE_TEXT
Expand Down Expand Up @@ -746,7 +746,7 @@ void QgsSpatiaLiteProvider::loadFields()
QgsDebugMsg( "found primaryKey " + name );
}

if ( name != mGeometryColumn )
if ( name.toLower() != mGeometryColumn )
{
// for sure any SQLite value can be represented as SQLITE_TEXT
QVariant::Type fieldType = QVariant::String;
Expand Down Expand Up @@ -813,7 +813,7 @@ void QgsSpatiaLiteProvider::loadFields()
QgsDebugMsg( "found primaryKey " + name );
}

if ( name != mGeometryColumn )
if ( name.toLower() != mGeometryColumn )
{
// for sure any SQLite value can be represented as SQLITE_TEXT
QVariant::Type fieldType = QVariant::String;
Expand Down
21 changes: 21 additions & 0 deletions tests/src/python/test_qgsspatialiteprovider.py
Expand Up @@ -82,6 +82,18 @@ def setUpClass(cls):
sql += "VALUES (2, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
cur.execute(sql)

# simple table with a geometry column named 'Geometry'
sql = "CREATE TABLE test_n (Id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL)"
cur.execute(sql)
sql = "SELECT AddGeometryColumn('test_n', 'Geometry', 4326, 'POLYGON', 'XY')"
cur.execute(sql)
sql = "INSERT INTO test_n (id, name, geometry) "
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
cur.execute(sql)
sql = "INSERT INTO test_n (id, name, geometry) "
sql += "VALUES (2, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
cur.execute(sql)

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

Expand Down Expand Up @@ -165,5 +177,14 @@ def test_queries(self):
assert(sum_id1 == 3)
assert(sum_id2 == 3)

def test_case(self):
"""Test case sensitivity issues"""
l = QgsVectorLayer("dbname=%s table='test_n' (geometry) key='id'" % self.dbname, "test_n1", "spatialite")
assert(l.isValid())
assert(l.dataProvider().fields().count() == 2)
fields = [f.name() for f in l.dataProvider().fields()]
assert('Geometry' not in fields)


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

0 comments on commit 221ba9c

Please sign in to comment.