Skip to content
Permalink
Browse files
Fix sqlite skipped layer names logic
  • Loading branch information
nyalldawson committed Jun 28, 2021
1 parent 0ea4427 commit 6a0497f58f029b44f942b61c6c2b292aaeb0212d
@@ -1031,8 +1031,6 @@ bool QgsOgrProviderMetadata::uriIsBlocklisted( const QString &uri ) const

QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags, QgsFeedback *feedback ) const
{
QStringList skippedLayerNames;

QStringList options { QStringLiteral( "@LIST_ALL_TABLES=YES" ) };

QString errCause;
@@ -1041,10 +1039,6 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
return {};

const QString driverName = firstLayer->driverName();
if ( driverName == QLatin1String( "SQLite" ) )
{
skippedLayerNames = QgsSqliteUtils::systemTables();
}

const int layerCount = firstLayer->GetLayerCount();

@@ -2303,6 +2303,18 @@ QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int
// qgis_projects (coming from http://plugins.qgis.org/plugins/QgisGeopackage/)
return {};
}

QStringList skippedLayerNames;
if ( driverName == QLatin1String( "SQLite" ) )
{
skippedLayerNames = QgsSqliteUtils::systemTables();
}
if ( ( driverName == QLatin1String( "SQLite" ) && layerName.contains( QRegularExpression( QStringLiteral( "idx_.*_geom(etry)?($|_.*)" ), QRegularExpression::PatternOption::CaseInsensitiveOption ) ) )
|| skippedLayerNames.contains( layerName ) )
{
return {};
}

// Get first column name,
// TODO: add support for multiple
QString geometryColumnName;
@@ -1644,6 +1644,51 @@ def test_provider_sublayer_details(self):
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.Polygon)

# spatialite
res = metadata.querySublayers(os.path.join(TEST_DATA_DIR, "provider/spatialite.db"))
self.assertCountEqual([{'name': r.name(),
'description': r.description(),
'uri': r.uri(),
'providerKey': r.providerKey(),
'wkbType': r.wkbType(),
'geomColName': r.geometryColumnName()} for r in res],
[{'name': 'somedata',
'description': '',
'uri': '{}/provider/spatialite.db|layername=somedata'.format(TEST_DATA_DIR),
'providerKey': 'ogr',
'wkbType': 1,
'geomColName': 'geom'},
{'name': 'somepolydata',
'description': '',
'uri': '{}/provider/spatialite.db|layername=somepolydata'.format(TEST_DATA_DIR),
'providerKey': 'ogr',
'wkbType': 6,
'geomColName': 'geom'},
{'name': 'some data',
'description': '',
'uri': '{}/provider/spatialite.db|layername=some data'.format(TEST_DATA_DIR),
'providerKey': 'ogr',
'wkbType': 1,
'geomColName': 'geom'},
{'name': 'validator_project_test',
'description': '',
'uri': '{}/provider/spatialite.db|layername=validator_project_test'.format(TEST_DATA_DIR),
'providerKey': 'ogr',
'wkbType': 1,
'geomColName': 'geom'},
{'name': 'data_licenses',
'description': '',
'uri': '{}/provider/spatialite.db|layername=data_licenses'.format(TEST_DATA_DIR),
'providerKey': 'ogr',
'wkbType': 100,
'geomColName': ''},
{'name': 'some view',
'description': '',
'uri': '{}/provider/spatialite.db|layername=some view'.format(TEST_DATA_DIR),
'providerKey': 'ogr',
'wkbType': 100,
'geomColName': ''}])


if __name__ == '__main__':
unittest.main()

0 comments on commit 6a0497f

Please sign in to comment.