Skip to content
Permalink
Browse files

Fixes #31626 don't crash on oracle getFeature(id) with an invalid id

  • Loading branch information
troopa81 authored and nyalldawson committed Feb 5, 2020
1 parent 167e0de commit b75acc78a2e33b7f5addab93fe98b315e3bb770a
Showing with 29 additions and 4 deletions.
  1. +2 −4 src/providers/oracle/qgsoracleprovider.cpp
  2. +27 −0 tests/src/python/test_provider_oracle.py
@@ -423,11 +423,9 @@ QString QgsOracleUtils::whereClause( QgsFeatureId featureId, const QgsFields &fi
case PktRowId:
case PktFidMap:
{
QVariant pkValsVariant = sharedData->lookupKey( featureId );
if ( !pkValsVariant.isNull() )
QVariantList pkVals = sharedData->lookupKey( featureId );
if ( !pkVals.isEmpty() )
{
QList<QVariant> pkVals = pkValsVariant.toList();

if ( primaryKeyType == PktFidMap )
{
Q_ASSERT( pkVals.size() == primaryKeyAttrs.size() );
@@ -699,6 +699,33 @@ def testIdentityCommit(self):
features = [f for f in vl.getFeatures()]
vl.dataProvider().deleteFeatures([features[-1].id()])

def testGetFeatureFidInvalid(self):
"""
Get feature with an invalid fid
https://github.com/qgis/QGIS/issues/31626
"""
self.execSQLCommand('DROP TABLE "QGIS"."TABLE_QGIS_ISSUE_FLOAT_KEY"', ignore_errors=True)
self.execSQLCommand("""CREATE TABLE "QGIS"."TABLE_QGIS_ISSUE_FLOAT_KEY" (CODE NUMBER PRIMARY KEY, DESCRIPTION VARCHAR2(25))""")
self.execSQLCommand("""INSERT INTO "QGIS"."TABLE_QGIS_ISSUE_FLOAT_KEY" VALUES(1000,'Desc for 1st record')""")
self.execSQLCommand("""INSERT INTO "QGIS"."TABLE_QGIS_ISSUE_FLOAT_KEY" VALUES(2000,'Desc for 2nd record')""")
self.execSQLCommand("""CREATE OR REPLACE VIEW "QGIS"."VIEW_QGIS_ISSUE_FLOAT_KEY" AS SELECT * FROM "QGIS"."TABLE_QGIS_ISSUE_FLOAT_KEY" """)

vl = QgsVectorLayer(
self.dbconn + ' sslmode=disable key=\'CODE\' table="QGIS"."VIEW_QGIS_ISSUE_FLOAT_KEY" sql=',
'test', 'oracle')

# feature are not loaded yet, mapping between CODE and fid is not built so feature
# is invalid
feature = vl.getFeature(2)
self.assertTrue(not feature.isValid())

# load all features
for f in vl.getFeatures():
pass

feature = vl.getFeature(2)
self.assertTrue(feature.isValid())


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

0 comments on commit b75acc7

Please sign in to comment.
You can’t perform that action at this time.