Skip to content
Permalink
Browse files

[spatialite] Fix geometry column name case sensitivity

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Feb 13, 2015
1 parent 12a4e7d commit 221ba9c336294d4fa0cc3943aa3d3de1704341ee
@@ -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();
@@ -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
@@ -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;
@@ -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;
@@ -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()

@@ -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.
You can’t perform that action at this time.