Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimize SpatiaLite feature reading speed
  • Loading branch information
wonder-sk committed Nov 17, 2011
1 parent a9f82d1 commit 57ea79f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -795,8 +795,7 @@ bool QgsSpatiaLiteProvider::getFeature( sqlite3_stmt *stmt, bool fetchGeometry,
}
if ( fetchGeometry )
{
QString geoCol = QString( "AsBinary(%1)" ).arg( quotedIdentifier( mGeometryColumn ) );
if ( strcasecmp( geoCol.toUtf8().constData(), sqlite3_column_name( stmt, ic ) ) == 0 )
if ( ic == mGeomColIdx )
{
if ( sqlite3_column_type( stmt, ic ) == SQLITE_BLOB )
{
Expand Down Expand Up @@ -3247,6 +3246,7 @@ bool QgsSpatiaLiteProvider::prepareStatement(
QString primaryKey = !isQuery ? "ROWID" : quotedIdentifier( mPrimaryKey );

QString sql = QString( "SELECT %1" ).arg( primaryKey );
int colIdx = 1; // column 0 is primary key
for ( QgsAttributeList::const_iterator it = fetchAttributes.constBegin(); it != fetchAttributes.constEnd(); ++it )
{
const QgsField & fld = field( *it );
Expand All @@ -3258,10 +3258,12 @@ bool QgsSpatiaLiteProvider::prepareStatement(
fieldname = QString( "AsText(%1)" ).arg( fieldname );
}
sql += "," + fieldname;
colIdx++;
}
if ( fetchGeometry )
{
sql += QString( ", AsBinary(%1)" ).arg( quotedIdentifier( mGeometryColumn ) );
mGeomColIdx = colIdx;
}
sql += QString( " FROM %1" ).arg( mQuery );

Expand Down
3 changes: 3 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.h
Expand Up @@ -382,6 +382,9 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider

const QgsField & field( int index ) const;

/** geometry column index used when fetching geometry */
int mGeomColIdx;

/**
* internal utility functions used to handle common SQLite tasks
*/
Expand Down

0 comments on commit 57ea79f

Please sign in to comment.