Navigation Menu

Skip to content

Commit

Permalink
[BUGFIX][Spatialite] Setting default value in loadFields with the rig…
Browse files Browse the repository at this point in the history
…ht index

Because Geomtry field is not added to fields list, the index do not respect the index in the table. It's necessary to have a realFieldIndex.
  • Loading branch information
rldhont authored and m-kuhn committed Nov 24, 2017
1 parent cdca0dd commit 49b2312
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -949,9 +949,13 @@ void QgsSpatiaLiteProvider::loadFields()
;
else
{
int realFieldIndex = 0;
for ( i = 1; i <= rows; i++ )
{
QString name = QString::fromUtf8( results[( i * columns ) + 1] );
if ( name.toLower() == mGeometryColumn )
continue;

QString type = QString::fromUtf8( results[( i * columns ) + 2] ).toLower();
QString pk = results[( i * columns ) + 5];
if ( pk.toInt() != 0 )
Expand All @@ -962,17 +966,15 @@ void QgsSpatiaLiteProvider::loadFields()
pkName = name;
else
pkName.clear();
mPrimaryKeyAttrs << i - 1;
mPrimaryKeyAttrs << realFieldIndex;
QgsDebugMsg( "found primaryKey " + name );
}

if ( name.toLower() != mGeometryColumn )
{
const TypeSubType fieldType = getVariantType( type );
mAttributeFields.append( QgsField( name, fieldType.first, type, 0, 0, QString(), fieldType.second ) );
}
const TypeSubType fieldType = getVariantType( type );
mAttributeFields.append( QgsField( name, fieldType.first, type, 0, 0, QString(), fieldType.second ) );

insertDefaultValue( i - 1, QString::fromUtf8( results[( i * columns ) + 4] ) );
insertDefaultValue( realFieldIndex, QString::fromUtf8( results[( i * columns ) + 4] ) );
realFieldIndex += 1;
}
}
sqlite3_free_table( results );
Expand Down

0 comments on commit 49b2312

Please sign in to comment.