Skip to content

Commit 45ab8cc

Browse files
committed
- set primary key value to NULL in split when there is no default value.
- modified the test accordingly
1 parent 827ed31 commit 45ab8cc

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/core/qgsvectorlayereditutils.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ int QgsVectorLayerEditUtils::splitFeatures( const QList<QgsPoint>& splitLine, bo
254254
{
255255
newAttributes[ pkIdx ] = defaultValue;
256256
}
257+
else //try with NULL
258+
{
259+
newAttributes[ pkIdx ] = QVariant();
260+
}
257261
}
258262

259263
newFeature.setAttributes( newAttributes );

tests/src/python/test_qgsspatialiteprovider.py

+20
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ def setUpClass(cls):
5252
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
5353
cur.execute(sql)
5454

55+
# table with multiple column primary key
56+
sql = "CREATE TABLE test_pg_mk (id INTEGER NOT NULL, name TEXT NOT NULL, PRIMARY KEY(id,name))"
57+
cur.execute(sql)
58+
sql = "SELECT AddGeometryColumn('test_pg_mk', 'geometry', 4326, 'POLYGON', 'XY')"
59+
cur.execute(sql)
60+
sql = "INSERT INTO test_pg_mk (id, name, geometry) "
61+
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
62+
cur.execute(sql)
63+
5564
con.commit()
5665
con.close()
5766

@@ -79,6 +88,17 @@ def test_SplitFeature(self):
7988
layer.startEditing()
8089
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split")
8190
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0)==0 or die("error in split")
91+
layer.commitChanges() or die("this commit should work")
92+
layer.featureCount() == 4 or die("we should have 4 features after 2 split")
93+
94+
def test_SplitFeatureWithFailedCommit(self):
95+
"""Create spatialite database"""
96+
layer = QgsVectorLayer("dbname=test.sqlite table=test_pg_mk (geometry)", "test_pg_mk", "spatialite")
97+
assert(layer.isValid())
98+
assert(layer.hasGeometryType())
99+
layer.startEditing()
100+
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split")
101+
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0)==0 or die("error in split")
82102
if layer.commitChanges():
83103
die("this commit should fail")
84104
layer.rollBack()

0 commit comments

Comments
 (0)