Skip to content

Commit 0df39bd

Browse files
committed
[browser] List non-spatial layers for mixed spatial/non-spatial sqlite files
1 parent 5cb673a commit 0df39bd

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/providers/ogr/qgsogrdataitems.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsgeopackagedataitems.h"
2626
#include "qgsogrutils.h"
2727
#include "qgsproviderregistry.h"
28+
#include "qgssqliteutils.h"
2829
#include "symbology/qgsstyle.h"
2930

3031
#include <QFileInfo>
@@ -33,6 +34,7 @@
3334
#include <QMessageBox>
3435
#include <QInputDialog>
3536
#include <QFileDialog>
37+
#include <QRegularExpression>
3638

3739
#include <ogr_srs_api.h>
3840
#include <cpl_error.h>
@@ -388,14 +390,27 @@ QgsOgrDataCollectionItem::QgsOgrDataCollectionItem( QgsDataItem *parent, const Q
388390
QVector<QgsDataItem *> QgsOgrDataCollectionItem::createChildren()
389391
{
390392
QVector<QgsDataItem *> children;
393+
QStringList skippedLayerNames;
394+
395+
char **papszOptions = nullptr;
396+
papszOptions = CSLSetNameValue( papszOptions, "@LIST_ALL_TABLES", "YES" );
397+
gdal::dataset_unique_ptr hDataSource( GDALOpenEx( mPath.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, papszOptions, nullptr ) );
398+
CSLDestroy( papszOptions );
399+
400+
GDALDriverH hDriver = GDALGetDatasetDriver( hDataSource.get() );
401+
QString driverName = QString::fromUtf8( GDALGetDriverShortName( hDriver ) );
402+
if ( driverName == QStringLiteral( "SQLite" ) )
403+
{
404+
skippedLayerNames = QgsSqliteUtils::systemTables();
405+
}
391406

392-
gdal::dataset_unique_ptr hDataSource( GDALOpenEx( mPath.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
393407
if ( !hDataSource )
394408
return children;
395409
int numLayers = GDALDatasetGetLayerCount( hDataSource.get() );
396410

397411
// Check if layer names are unique, so we can use |layername= in URI
398412
QMap< QString, int > mapLayerNameToCount;
413+
QList< int > skippedLayers;
399414
bool uniqueNames = true;
400415
for ( int i = 0; i < numLayers; ++i )
401416
{
@@ -408,13 +423,21 @@ QVector<QgsDataItem *> QgsOgrDataCollectionItem::createChildren()
408423
uniqueNames = false;
409424
break;
410425
}
426+
if ( ( driverName == QStringLiteral( "SQLite" ) && layerName.contains( QRegularExpression( QStringLiteral( "idx_.*_geometry($|_.*)" ) ) ) )
427+
|| skippedLayerNames.contains( layerName ) )
428+
{
429+
skippedLayers << i;
430+
}
411431
}
412432

413433
children.reserve( numLayers );
414434
for ( int i = 0; i < numLayers; ++i )
415435
{
416-
QgsOgrLayerItem *item = dataItemForLayer( this, QString(), mPath, hDataSource.get(), i, true, uniqueNames );
417-
children.append( item );
436+
if ( !skippedLayers.contains( i ) )
437+
{
438+
QgsOgrLayerItem *item = dataItemForLayer( this, QString(), mPath, hDataSource.get(), i, true, uniqueNames );
439+
children.append( item );
440+
}
418441
}
419442

420443
return children;

0 commit comments

Comments
 (0)