Skip to content

Commit

Permalink
also determine primary key in spatialite 4
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jul 18, 2013
1 parent dcd19aa commit 95230b8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -631,6 +631,32 @@ void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr
}
fld = fld->Next;
}

mPrimaryKey.clear();
mPrimaryKeyAttrs.clear();

QString sql = QString( "PRAGMA table_info(%1)" ).arg( quotedIdentifier( mTableName ) );

char **results;
int rows;
int columns;
char *errMsg = NULL;
int ret = sqlite3_get_table( sqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
if ( ret == SQLITE_OK )
{
for ( int i = 1; i <= rows; i++ )
{
QString name = QString::fromUtf8( results[( i * columns ) + 1] );
QString pk = results[( i * columns ) + 5];
if ( pk.toInt() == 0 )
continue;

if( mPrimaryKey.isEmpty() )
mPrimaryKey = name;
mPrimaryKeyAttrs << i - 1;
}
}
sqlite3_free_table( results );
}
#endif

Expand Down

0 comments on commit 95230b8

Please sign in to comment.