Skip to content
Permalink
Browse files

[BUGFIX][Spatialite] Setting default value in loadFields with the rig…

…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 16, 2017
1 parent cdca0dd commit 49b23127caaa8854f8fb05995d0119d4538dabed
Showing with 9 additions and 7 deletions.
  1. +9 −7 src/providers/spatialite/qgsspatialiteprovider.cpp
@@ -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 )
@@ -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 );

0 comments on commit 49b2312

Please sign in to comment.
You can’t perform that action at this time.