Skip to content
Permalink
Browse files

Fix issue when inserting a feature with only null attributes

  • Loading branch information
troopa81 authored and nyalldawson committed Feb 19, 2021
1 parent 209fad5 commit b1067afc35ea37595ebcd368b8c705dd9dde6e8c
Showing with 43 additions and 3 deletions.
  1. +0 −3 src/providers/oracle/qgsoracleprovider.cpp
  2. +43 −0 tests/src/python/test_provider_oracle.py
@@ -1342,11 +1342,8 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flag
// e.g. for defaults
for ( int idx = 0; idx < std::min( attributevec.size(), mAttributeFields.size() ); ++idx )
{
QVariant v = attributevec[idx];
if ( mAlwaysGenerated.at( idx ) )
continue;
if ( !v.isValid() )
continue;

if ( fieldId.contains( idx ) )
continue;
@@ -908,6 +908,49 @@ def testCreateInvalidLayer(self):
exporter = QgsVectorLayerExporter(uri=uri, provider='oracle', fields=fields, geometryType=QgsWkbTypes.NoGeometry, crs=QgsCoordinateReferenceSystem(), overwrite=True)
self.assertEqual(exporter.errorCode(), QgsVectorLayerExporter.ErrCreateDataSource)

def testAddEmptyFeature(self):
"""
Test inserting a feature with only null attributes
"""

def countFeature(table_name):
self.assertTrue(self.conn)
query = QSqlQuery(self.conn)
res = query.exec_('SELECT count(*) FROM "QGIS"."{}"'.format(table_name))
self.assertTrue(query.next())
count = query.value(0)
query.finish()
return count

self.execSQLCommand('DROP TABLE "QGIS"."EMPTYFEATURE_LAYER"', ignore_errors=True)
self.execSQLCommand('CREATE TABLE "QGIS"."EMPTYFEATURE_LAYER" ( "num" INTEGER, GEOM SDO_GEOMETRY)')

vl = QgsVectorLayer(self.dbconn + ' sslmode=disable type=Point table="QGIS"."EMPTYFEATURE_LAYER" (GEOM) sql=', 'test', 'oracle')
self.assertTrue(vl.isValid())

# add feature with no attributes, no geometry
feature = QgsFeature(vl.fields())
self.assertTrue(vl.dataProvider().addFeatures([feature])[0])
self.assertEqual(countFeature('EMPTYFEATURE_LAYER'), 1)

# add feature with no attribute and one geometry
feature = QgsFeature(vl.fields())
feature.setGeometry(QgsGeometry.fromWkt('Point (43.5 1.42)'))
self.assertTrue(vl.dataProvider().addFeatures([feature])[0])
self.assertEqual(countFeature('EMPTYFEATURE_LAYER'), 2)

self.execSQLCommand('DROP TABLE "QGIS"."EMPTYFEATURE_NOGEOM_LAYER"', ignore_errors=True)
self.execSQLCommand('CREATE TABLE "QGIS"."EMPTYFEATURE_NOGEOM_LAYER" ( "num" INTEGER)')

# same tests but with no geometry in table definition
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable table="QGIS"."EMPTYFEATURE_NOGEOM_LAYER" sql=', 'test', 'oracle')
self.assertTrue(vl.isValid())

# add feature with no attributes
feature = QgsFeature(vl.fields())
self.assertTrue(vl.dataProvider().addFeatures([feature])[0])
self.assertEqual(countFeature('EMPTYFEATURE_NOGEOM_LAYER'), 1)


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

0 comments on commit b1067af

Please sign in to comment.