Skip to content
Permalink
Browse files
Move table name variable to local
  • Loading branch information
elpaso committed Sep 28, 2018
1 parent 9e9f0d6 commit f1b2893b489a939a672895f1ab401069c87b4acc
@@ -4592,27 +4592,29 @@ bool QgsSpatiaLiteProvider::checkLayerType()
{
// Check if we can get use the ROWID from the table that provides the geometry
sqlite3_stmt *stmt = nullptr;
//! String containing the name of the table that provides the geometry if the layer data source is based on a query
QString queryGeomTableName;
// 1. find the table that provides geometry
if ( sqlite3_prepare_v2( mSqliteHandle, sql.toUtf8().constData(), -1, &stmt, nullptr ) == SQLITE_OK )
{
mQueryGeomTableName = sqlite3_column_table_name( stmt, 1 );
queryGeomTableName = sqlite3_column_table_name( stmt, 1 );
}
// 2. check if the table has a useable ROWID
if ( ! mQueryGeomTableName.isEmpty() )
if ( ! queryGeomTableName.isEmpty() )
{
sql = QStringLiteral( "SELECT ROWID FROM %1 WHERE ROWID IS NOT NULL LIMIT 1" ).arg( quotedIdentifier( mQueryGeomTableName ) );
sql = QStringLiteral( "SELECT ROWID FROM %1 WHERE ROWID IS NOT NULL LIMIT 1" ).arg( quotedIdentifier( queryGeomTableName ) );
ret = sqlite3_get_table( mSqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK || rows != 1 )
{
mQueryGeomTableName = QString();
queryGeomTableName = QString();
}
}
// 3. check if ROWID injection works
if ( ! mQueryGeomTableName.isEmpty() )
if ( ! queryGeomTableName.isEmpty() )
{
QString newSql( mQuery.replace( QStringLiteral( "SELECT " ),
QStringLiteral( "SELECT %1.%2, " )
.arg( quotedIdentifier( mQueryGeomTableName ), QStringLiteral( "ROWID" ) ),
.arg( quotedIdentifier( queryGeomTableName ), QStringLiteral( "ROWID" ) ),
Qt::CaseInsensitive ) );
sql = QStringLiteral( "SELECT ROWID FROM %1 WHERE ROWID IS NOT NULL LIMIT 1" ).arg( newSql );
ret = sqlite3_get_table( mSqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
@@ -230,9 +230,6 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
//! Flag indicating if the layer data source is based on a query
bool mIsQuery = false;

//! String containing the name of the table that provides the geometry if the layer data source is based on a query
QString mQueryGeomTableName;

//! Flag indicating if ROWID has been injected in the query
bool mRowidInjectedInQuery = false;

0 comments on commit f1b2893

Please sign in to comment.