Skip to content

Commit 57ea79f

Browse files
committedNov 17, 2011
Optimize SpatiaLite feature reading speed
1 parent a9f82d1 commit 57ea79f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
 

‎src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,7 @@ bool QgsSpatiaLiteProvider::getFeature( sqlite3_stmt *stmt, bool fetchGeometry,
795795
}
796796
if ( fetchGeometry )
797797
{
798-
QString geoCol = QString( "AsBinary(%1)" ).arg( quotedIdentifier( mGeometryColumn ) );
799-
if ( strcasecmp( geoCol.toUtf8().constData(), sqlite3_column_name( stmt, ic ) ) == 0 )
798+
if ( ic == mGeomColIdx )
800799
{
801800
if ( sqlite3_column_type( stmt, ic ) == SQLITE_BLOB )
802801
{
@@ -3247,6 +3246,7 @@ bool QgsSpatiaLiteProvider::prepareStatement(
32473246
QString primaryKey = !isQuery ? "ROWID" : quotedIdentifier( mPrimaryKey );
32483247

32493248
QString sql = QString( "SELECT %1" ).arg( primaryKey );
3249+
int colIdx = 1; // column 0 is primary key
32503250
for ( QgsAttributeList::const_iterator it = fetchAttributes.constBegin(); it != fetchAttributes.constEnd(); ++it )
32513251
{
32523252
const QgsField & fld = field( *it );
@@ -3258,10 +3258,12 @@ bool QgsSpatiaLiteProvider::prepareStatement(
32583258
fieldname = QString( "AsText(%1)" ).arg( fieldname );
32593259
}
32603260
sql += "," + fieldname;
3261+
colIdx++;
32613262
}
32623263
if ( fetchGeometry )
32633264
{
32643265
sql += QString( ", AsBinary(%1)" ).arg( quotedIdentifier( mGeometryColumn ) );
3266+
mGeomColIdx = colIdx;
32653267
}
32663268
sql += QString( " FROM %1" ).arg( mQuery );
32673269

‎src/providers/spatialite/qgsspatialiteprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
382382

383383
const QgsField & field( int index ) const;
384384

385+
/** geometry column index used when fetching geometry */
386+
int mGeomColIdx;
387+
385388
/**
386389
* internal utility functions used to handle common SQLite tasks
387390
*/

0 commit comments

Comments
 (0)
Please sign in to comment.