@@ -4592,27 +4592,29 @@ bool QgsSpatiaLiteProvider::checkLayerType()
4592
4592
{
4593
4593
// Check if we can get use the ROWID from the table that provides the geometry
4594
4594
sqlite3_stmt *stmt = nullptr ;
4595
+ // ! String containing the name of the table that provides the geometry if the layer data source is based on a query
4596
+ QString queryGeomTableName;
4595
4597
// 1. find the table that provides geometry
4596
4598
if ( sqlite3_prepare_v2 ( mSqliteHandle , sql.toUtf8 ().constData (), -1 , &stmt, nullptr ) == SQLITE_OK )
4597
4599
{
4598
- mQueryGeomTableName = sqlite3_column_table_name ( stmt, 1 );
4600
+ queryGeomTableName = sqlite3_column_table_name ( stmt, 1 );
4599
4601
}
4600
4602
// 2. check if the table has a useable ROWID
4601
- if ( ! mQueryGeomTableName .isEmpty () )
4603
+ if ( ! queryGeomTableName .isEmpty () )
4602
4604
{
4603
- sql = QStringLiteral ( " SELECT ROWID FROM %1 WHERE ROWID IS NOT NULL LIMIT 1" ).arg ( quotedIdentifier ( mQueryGeomTableName ) );
4605
+ sql = QStringLiteral ( " SELECT ROWID FROM %1 WHERE ROWID IS NOT NULL LIMIT 1" ).arg ( quotedIdentifier ( queryGeomTableName ) );
4604
4606
ret = sqlite3_get_table ( mSqliteHandle , sql.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
4605
4607
if ( ret != SQLITE_OK || rows != 1 )
4606
4608
{
4607
- mQueryGeomTableName = QString ();
4609
+ queryGeomTableName = QString ();
4608
4610
}
4609
4611
}
4610
4612
// 3. check if ROWID injection works
4611
- if ( ! mQueryGeomTableName .isEmpty () )
4613
+ if ( ! queryGeomTableName .isEmpty () )
4612
4614
{
4613
4615
QString newSql ( mQuery .replace ( QStringLiteral ( " SELECT " ),
4614
4616
QStringLiteral ( " SELECT %1.%2, " )
4615
- .arg ( quotedIdentifier ( mQueryGeomTableName ), QStringLiteral ( " ROWID" ) ),
4617
+ .arg ( quotedIdentifier ( queryGeomTableName ), QStringLiteral ( " ROWID" ) ),
4616
4618
Qt::CaseInsensitive ) );
4617
4619
sql = QStringLiteral ( " SELECT ROWID FROM %1 WHERE ROWID IS NOT NULL LIMIT 1" ).arg ( newSql );
4618
4620
ret = sqlite3_get_table ( mSqliteHandle , sql.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
0 commit comments