Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #46474 from qgis/backport-46465-to-release-3_16
[Backport release-3_16] [spatialite] Fix crash when loading certain spatialite layers
  • Loading branch information
lbartoletti committed Dec 14, 2021
2 parents bd96969 + 74a9fef commit 0837f20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -933,7 +933,7 @@ void QgsSpatiaLiteProvider::fetchConstraints()

QString sqlDef = QString::fromUtf8( results[ 1 ] );
// extract definition
QRegularExpression re( QStringLiteral( R"raw(\((.*)\))raw" ) );
QRegularExpression re( QStringLiteral( R"raw(\((.+)\))raw" ) );
QRegularExpressionMatch match = re.match( sqlDef );
if ( match.hasMatch() )
{
Expand Down
24 changes: 15 additions & 9 deletions tests/src/python/test_provider_spatialite.py
Expand Up @@ -10,16 +10,16 @@
__date__ = '09/07/2013'
__copyright__ = 'Copyright 2013, The QGIS Project'

import qgis # NOQA

import os
import re
import sys
import shutil
import sys
import tempfile
from osgeo import ogr
from datetime import datetime

import qgis # NOQA
from osgeo import ogr
from qgis.PyQt.QtCore import QVariant, QByteArray
from qgis.core import (QgsProviderRegistry,
QgsDataSourceUri,
QgsVectorLayer,
Expand All @@ -36,14 +36,12 @@
QgsRectangle,
QgsVectorLayerExporter,
QgsWkbTypes)

from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase
from qgis.PyQt.QtCore import QObject, QVariant, QByteArray

from qgis.utils import spatialite_connect

from providertestbase import ProviderTestCase
from utilities import unitTestDataPath

# Pass no_exit=True: for some reason this crashes sometimes on exit on Travis
start_app(True)
TEST_DATA_DIR = unitTestDataPath()
Expand Down Expand Up @@ -453,6 +451,14 @@ def test_SplitFeatureWithMultiKey(self):
[QgsPointXY(-0.5, 0.5), QgsPointXY(1.5, 0.5)], 0), 0)
self.assertTrue(layer.commitChanges())

def test_crash_on_constraint_detection(self):
"""
Test that constraint detection does not crash
"""
# should be no crash!
QgsVectorLayer("dbname={} table=KNN".format(TEST_DATA_DIR + '/views_test.sqlite'), "KNN",
"spatialite")

def test_queries(self):
"""Test loading of query-based layers"""

Expand Down

0 comments on commit 0837f20

Please sign in to comment.